Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.08 KB | None | 0 0
  1. require 'tweakSiri'
  2. require 'siriObjectGenerator'
  3. require 'net/http'
  4.  
  5.  
  6. #######
  7. # This is a "hello world" style plugin. It simply intercepts the phrase "text siri proxy" and responds
  8. # with a message about the proxy being up and running. This is good base code for other plugins.
  9. #
  10. # Remember to add other plugins to the "start.rb" file if you create them!
  11. ######
  12.  
  13.  
  14. class Eliza < SiriPlugin
  15.  
  16.     ####
  17.     # This gets called every time an object is received from the Guzzoni server
  18.     def object_from_guzzoni(object, connection)
  19.        
  20.         object
  21.     end
  22.        
  23.     ####
  24.     # This gets called every time an object is received from an iPhone
  25.     def object_from_client(object, connection)
  26.        
  27.         object
  28.     end
  29.    
  30.    
  31.     ####
  32.     # When the server reports an "unkown command", this gets called. It's useful for implementing commands that aren't otherwise covered
  33.     def unknown_command(object, connection, command)
  34.         if(command.match(/test siri proxy/i))
  35.             self.plugin_manager.block_rest_of_session_from_server
  36.            
  37.             return generate_siri_utterance(connection.lastRefId, "Siri Proxy is up and running!")
  38.         end
  39.        
  40.        
  41.         object
  42.     end
  43.    
  44.     ####
  45.     # This is called whenever the server recognizes speech. It's useful for overriding commands that Siri would otherwise recognize
  46.     def speech_recognized(object, connection, phrase)
  47.         self.plugin_manager.block_rest_of_session_from_server
  48.        
  49.         Thread.new {
  50.             ###Contact eliza
  51.             response =  Net::HTTP.post_form(URI.parse("http://www-ai.ijs.si/eliza-cgi-bin/eliza_script"),{'Entry1'=>phrase})
  52.            
  53.             addViews = SiriAddViews.new(false, false, "Reflection")
  54.             addViews.make_root(connection.lastRefId)
  55.             utterance = SiriAssistantUtteranceView.new(response.body.split("</strong>\n").last.split("\n").first)
  56.             utterance.listenAfterSpeaking = true
  57.             addViews.views << utterance
  58.            
  59.             connection.inject_object_to_output_stream(addViews.to_hash)
  60.         }      
  61.  
  62.         return object
  63.        
  64.         ##connection.inject_object_to_output_stream()
  65.        
  66.         ##requestComplete = SiriRequestCompleted.new
  67.         ##requestComplete.make_root(connection.lastRefId)
  68.        
  69.         ##return requestComplete.to_hash
  70.     end
  71.    
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement