Skip to content

Instantly share code, notes, and snippets.

@gshutler
Created April 13, 2013 18:02
Show Gist options
  • Save gshutler/5379413 to your computer and use it in GitHub Desktop.
Save gshutler/5379413 to your computer and use it in GitHub Desktop.
Script hacked from https://github.com/ajfaraday/Text-to-music for listening to log files. A day of logs can be listened to in under a minute.
#
# Andrew James Faraday - May 2012
#
# This script is to allow direct manual control of the text-to-music algorithm.
# After a simple check of speed (1 divided by numbers 1 to 10 = number of seconds between characters) the user is prompted to provide textual input which is then sonified.
# This is recommended as a first experience of the text-to-music system, so new users can see the correlation between their use of text and the resulting sound.
# press ctrl+c to exit the script
#
#
# Update, 11 Jun 2012
#
# The script, with a surprisingly simple set of changes, can now be fed a file, which it reads. This opens the rather mind-blowing possibility of running this line:
#
# ruby scripts/manual-input.rb scripts/manual-input.rb
#
# The above command will use this file to read and sonify this file including this comment about reading and sonifying this file.
#
require_relative '../lib/pd-connect'
# If the first argument is a valid file, place a flag to skip prompts
begin
file = File.new(ARGV[0])
puts "Reading file: #{file.path}"
rescue
# a convenience rescue to keep the process silent when a file is not present.
end
# Set up a port into pd
pd = PureData.new
if file and file.is_a? File
# Automatically set the playback speed
speed = 0.01
show_prompt = false
else
raise "No file"
end
# Repeatedly prompt the user to provide some text to sonify.
info = 0
warn = 0
line = ''
while true do
line = gets
break unless line
case line
when /INFO/
if info == 0
pd.send_string('a', speed)
else
sleep speed/100
end
info += 1
info = 0 if info > 500
when /WARN/
if warn == 0
pd.send_string('f', speed)
else
sleep speed/100
end
warn += 1
warn = 0 if warn > 10
when /ERROR/
puts "\n#{line}"
pd.send_string('!', speed*10)
when /FATAL/
puts "\n#{line}"
pd.send_string('!', speed*10)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment