Skip to content

Instantly share code, notes, and snippets.

@devongovett
Created November 22, 2011 04:49
Show Gist options
  • Save devongovett/1384917 to your computer and use it in GitHub Desktop.
Save devongovett/1384917 to your computer and use it in GitHub Desktop.
require 'tweakSiri'
require 'siriObjectGenerator'
#######
# This is a "hello world" style plugin. It simply intercepts the phrase "text siri proxy" and responds
# with a message about the proxy being up and running. This is good base code for other plugins.
#
# Remember to add other plugins to the "start.rb" file if you create them!
######
class SiriTunes < SiriPlugin
def runiTunesCommand(cmd)
output = IO.popen("arch -i386 osascript -e 'tell application \"iTunes\" to #{cmd}'").readlines[0]
if output
output.strip!
end
output
end
####
# This is called whenever the server recognizes speech. It's useful for overriding commands that Siri would otherwise recognize
def speech_recognized(object, connection, phrase)
if(phrase.match(/tell iTunes to (.*)/i))
self.plugin_manager.block_rest_of_session_from_server
cmd = $1.downcase.strip
if cmd == 'mute'
cmd = 'set mute to true'
elsif cmd == 'unmute'
cmd = 'set mute to false'
end
if cmd.match(/turn the volume (up|down)/i)
vol = self.runiTunesCommand("sound volume as integer").to_i
if $1.downcase == 'up'
vol += 30
else
vol -= 30
end
cmd = "set sound volume to #{vol}"
end
if cmd.match(/next song|skip/i)
cmd = "next track"
elsif cmd.match(/previous song|back/i)
cmd = "previous track"
end
if cmd.match(/play track (.*)/)
cmd = "play track \"#{$1}\" in playlist 1"
end
self.runiTunesCommand(cmd)
return generate_siri_utterance(connection.lastRefId, "OK.")
elsif(phrase.match(/what is iTunes playing/i))
self.plugin_manager.block_rest_of_session_from_server
state = self.runiTunesCommand("player state as string")
if state == 'playing'
artist = self.runiTunesCommand("artist of current track as string")
track = self.runiTunesCommand("name of current track as string")
return generate_siri_utterance(connection.lastRefId, "iTunes is currently playing \"#{track}\" by \"#{artist}\".")
else
return generate_siri_utterance(connection.lastRefId, "iTunes isn't playing anything right now.")
end
end
object
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment