Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How do I set a variable to a spoken word from Speech Recognition?

I've been wanting to make an Applescript for the speech program, that will play an itunes song. I've got my script made, but my only problem, is i need it to set my variable "song" to whatever i say.


The script name is "Play" so that I can say "Computer, play [song name]"


I have no idea what to do here to give user input by speech instead of typing, anybody who can help?

AppleScript-OTHER, Mac OS X (10.6.8)

Posted on Jan 14, 2013 4:00 PM

Reply
4 replies

Jan 16, 2013 1:49 PM in response to mr.millian

I'll need to experiment, but I don't believe you can use variable words in quite the way you want. However, you can always fall back on the brute-force approach: use applescript to extract the names of all your songs to a list, prefix each song name in the list with "play ", and then use that list in the listen command of the speech recognition server.

Jan 16, 2013 2:28 PM in response to mr.millian

FYI, that would look something like this:


tell application "iTunes"

set songList to get name of every track of playlist 1

end tell


repeat with thisSong in songList

set contents of thisSong to "play " & thisSong

end repeat


tell application "SpeechRecognitionServer"

set songString to listen forsongList

end tell


set songName to text 6 thru -1 of songString


tell application "iTunes"

playtracksongName of playlist 1

end tell

though note that song titles often have odd names that the speech recognition server might have trouble with.

How do I set a variable to a spoken word from Speech Recognition?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.