Control Plex using Speech Recognition

What's up forum?

I recently started to play with the built in speech recognition in OS X and a couple of days ago I added commands to it to control Plex.
It is pretty awesome actually, which is why I wanted to share this with the forum.

If you haven't played with the speech recognition yet, here is how you get started:
Open System preferences > speech
- switch "speakable items" on.
- choose microphone (I have mine on internal (I'm on a mbp))
- I have chosen to let it "Listen continuously with keyword"
- keyword is "required before each command"
- keyword: Choose what you want here. For example "Computer". My keyword is "Mac".
- I have also added my own sound that plays "upon recognition". It's a voice saying "yes, master". If you want that, download the sound from http://www.mediafire.com/?za5bec15yshbf5a and save it to ~/Library/Sounds/. You should then be able to choose it in the speech preferences.

So... what commands can you say? take a look in the folder ~/Library/Speech/Speakable Items/
All files in there are commands. If you say one of the names of the files, the speech recognition will open that file.

To add your own commands, you just need to add a file with your desired command as filename. What I do is create an apple script to do a specific thing and save it as an application a Script using applescript editor.

Here are some of the scripts that I have made.

Pause/Unpause Plex (I have this under three diffrent filenames. "Play television", "Pause television" and "Unpause television"):

do shell script "curl http://localhost:3000/xbmcCmds/xbmcHttp?command=pause"


Stop Plex (saved as "stop television")
do shell script "curl http://localhost:3000/xbmcCmds/xbmcHttp?command=stop"


Play the latest unwatched (the oldest you haven't watched) episode of a specific tv show (saved as "Play the latest episode of *tv show name*" for each tv show)
Try out the app Pleech that i made to install this script for each tv-show in plex! https://github.com/nadangergeo/Pleech

*** I have made a new script that lets the computer ask you what tv show you want to watch.
And it's only ONE file. It only works in OS X Lion. You can get the new script and other scripts for Plex here: https://github.com/nadangergeo/Plex-AppleScripts


You need to download and install this little scripting addon for xml parsing (takes less than a minute): http://www.latenightsw.com/freeware/XMLTools2/

Old script:
This is how it would look for the tv show "The Big Bang Theory"
set tvShowName to "The Big Bang Theory" -- the name of the tv show (case sensitive, include "The"5
set pms to "localhost:32400" -- ip and port to pms
set section to "2" -- the number of the tv shows section
set computerName to computer name of (system info)

– Setup XML
set tvShowsXMLURL to “http://” & pms & “/library/sections/” & section & “/all”
set tvShowsXML to (do shell script "curl " & tvShowsXMLURL) as string
set tvShowsXML to parse XML tvShowsXML encoding “UTF-8”
set tvShows to XML contents of tvShowsXML

repeat with tvShow in tvShows
if title of XML attributes of tvShow = tvShowName then
set tvShowKey to |ratingKey| of XML attributes of tvShow
exit repeat
end if
end repeat

– Setup second XML
set episodesXMLURL to “http://” & pms & “/library/metadata/” & tvShowKey & “/allLeaves?unwatched=1”
set episodesXML to (do shell script "curl " & episodesXMLURL) as string
set episodesXML to parse XML episodesXML encoding “UTF-8”
set episodes to XML contents of episodesXML

if item 1 of episodes is “” then
say “There are no unwatched episodes.”
else
set episodeKey to |key| of XML attributes of item 1 of episodes
set episodePath to “http://” & pms & “/library/metadata/” & tvShowKey & “/allLeaves”

set triggerURL to “http://” & pms & “/system/players/” & computerName & “.local/Application/playMedia?path=” & episodePath & “\&key=” & episodeKey

do shell script "curl " & triggerURL
end if

tell application “Plex”
activate
end tell



One problem with this command is that Plex does not seem to register an episode as watched when opened from outside plex. Any thoughts on how to solve that? Fixed.



Script to toggle Speakable Items (which you can add to remotebuddy if you use that):
on appIsRunning(appName)
tell application “System Events” to (name of processes) contains appName
end appIsRunning

if not appIsRunning(“SpeakableItems”) then
do shell script “open System/Library/Speech/Recognizers/AppleSpeakableItems.SpeechRecognizer/Contents/Resources/SpeakableItems.app”
else
do shell script “killall “SpeakableItems””
end if

Any comment would be appreciated :stuck_out_tongue:

I’m with you that getting Plex working with Speech Recognition is a fun and worthwhile project. We had a brief thread in the Plex 0.8 days here and I keep hoping that someone will really put some time into making a nice spoken interface for Plex.



What are you planning on implementing next?



Keep up the good work!



Vicarious



Nice to know I'm not the only one who thinks this is fun :D

I can't get "Lazy hands" to work, I'm guessing it's because it was made for plex 8? That would anyway be a nice speech recognition feature to add.
I need to resolve the tv-show script so that plex knows that I've watched the episode. And maybe add a way to watch the latest unwatched.

I also need to develop a gui to install the different commands. Making a command for every tv-show manually for instance is not optimal.

I noticed that the speech recognition prevents the screen saver to start. So instead I mapped a key on the apple remote (using remote buddy) to make it listen. Now I just hold down the play button when I want to say a command.



Also: I made a new script for playing tv shows.



Precisely. One of these days I'd like to revisit it, but Preen and Plexflix are receiving my time right now.

Vicarious

Nice project. Too bad I dont have a mic to my Mac Mini. Would have loved to use this. Keep up the good work!

I’m hoping speech recognition will get a boost with OSX Lion. The voices will be updated, finally supporting more languages. Maybe recognition will be better, too. I would love to do this, but I want to speak my own language, otherwise I feel like a fool ;). It’s just silly that I do a lot of things with my iPhone through voice commands, but my Mac can’t do that properly.



Alright, let me know when and if that happens :)




Thanks man :) Yeah it's too bad that mac minis don't have microphones.



Oh, I didn't know that :D I hope they make the speech recognition server better. It would be nice to be able listen for commands in an applescript, the current speech recognition seems to have issues with that. I would have used it instead of making a different file for each tv show, cause that's kind of inconvenient when you want to update the code.


This is sweet. Thanks!

Vicarious



No problem ;)


Scratch that... that kinda sucked. Instead I added an action in remotebuddy menu that toogles Speakable Items. I'll put it in the first post.

Oh by the way, I'm working on an App to easily install all scripts automatically. But be patient, I'm new to objective-c :P

Try out the app Pleech that i made to install this script for each tv-show in plex! https://github.com/ge0/Pleech



Edit: Any feature-suggestions?

Has anyone tested out the app yet :P?


The app worked like a charm and installed scripts for all my shows. Unfortunately getting the mini to recognize long commands like that hasn't worked so well. It's interesting to play around with though.


Great! :D Yeah, I often need to repeat the command 2 or 3 times. The trick is to over pronounce words and try to sound American :P Maybe a shorter command could work better...

Bump!

I have made a new script that lets the computer ask you what tv show you want to watch.
And it's only ONE file. It only works in OS X Lion. You can get the new script and other scripts for Plex here:
https://github.com/nadangergeo/Plex-AppleScripts

No posts since Nov 2011?

Is this still being worked on... Its the missing element to the ultimate home media center...

I wouldn't mind seeing something setup to work with Ubuntu. :)

I've just come across this, it sounds awesome. Sadly im on a mac mini but would be tempted to buy a microphone if its worth it? I have an android phone with tasker and can now control my lights through voice, would be great to throw in plex control also!!