Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to use voice recognition with iTunes Apps
There is a scriptable application hidden in /System -> Library -> Frameworks -> Carbon.framework -> Frameworks -> SpeechRecognition.framework -> Versions -> Current -> Resources called "SpeechRecognitionServer." It allows you to write scripts that have voice recognition components to them. I have written an AppleScript that will allow me to speak the song I want to play. I saved this script as a compiled script called "play" and placed it in the Speakable Items folder (in ~/Library -> Speech once Speech is enabled in System Prefs). Then when Speakable Items is turned on, I can say "play" "artist" "song" and iTunes will play that track. Read the rest of the article for the script...

Enter the following in Script Editor and remember to save it as a compiled script:
tell application "iTunes"
  set myFinishedList to {"Cancel"} as list -- Add Cancel to the list
  set myList to (get artist of every track of playlist 1) as list 
    -- gets every artist in first iTunes library
  
  repeat with myItem in myList
    if myFinishedList does not contain myItem then
      set myFinishedList to myFinishedList & myItem 
        -- remove any duplicate band names
    end if
  end repeat
end tell
tell application "SpeechRecognitionServer"
  set myArtist to (listen for myFinishedList with prompt myFinishedList)
end tell

if myArtist is not "Cancel" then
  tell application "iTunes"
    set myTracks to get every track of playlist 1 where artist 
      is myArtist -- playlist 1 is my mp3 library
    if number of items of myTracks is 1 then
      play (get first item of myTracks) 
        -- if only one song by an artist play that one
    else
      set myTrackNames to {"Cancel"} & (get name of every track of playlist 1 
        where artist is myArtist) -- filter by artist
      tell application "SpeechRecognitionServer"
        set myTrack to (listen for myTrackNames with prompt 
          myTrackNames) -- get the song
      end tell
      if myTrack is not "Cancel" then
        set myTrackList to (get every track of playlist 1 where name is myTrack)
        play (get first item of myTrackList) 
          -- should be only one item in list but just in case play first one
      end if
    end if
  end tell
end if
[robg adds: I haven't tested this one, as I'm currently lacking a microphone...]
    •    
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[34,906 views]  

A script to use voice recognition with iTunes | 14 comments | Create New Account
Click here to return to the 'A script to use voice recognition with iTunes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to use voice recognition with iTunes
Authored by: Mikey-San on Feb 27, '03 10:27:55AM

Is anyone else thinking what I'm thinking?

"Computer, Star Trek, main theme!"

;-)


-/-
Mikey-San



[ Reply to This | # ]
A script to use voice recognition with iTunes
Authored by: ajoslin on Feb 27, '03 12:24:21PM

no, can you say: computer, play <genre>

this is something I've been trying to do for a while

thanks!

al;



[ Reply to This | # ]
A script to use voice recognition with iTunes
Authored by: scott_papenfuss on Feb 27, '03 02:21:01PM

Cool, but it takes about 45 seconds for it to load all the artists (probably over 100), and then several more seconds for the album titles. Any way to speed this up?



[ Reply to This | # ]
A script to use voice recognition with iTunes
Authored by: Newler on Feb 27, '03 02:37:48PM

this wasn't working for me. someone want to help me out?



[ Reply to This | # ]
Seems to work as advertised...
Authored by: simX on Feb 27, '03 02:57:20PM

... but you should note that you need to say each item separately. After you turn Speakable Items on, say "play", and then wait for it to confirm your command. Then say the artist, and WAIT FOR IT TO CONFIRM your artist. If you have confirmation turned on in System Preferences->Speech, it will actually display the name of the artist in a little tooltip. Then say the name of the track, and it will confirm that, too, in a little tooltip.

Pretty amazing what you can do with AppleScript!



[ Reply to This | # ]
Seems to work as advertised...
Authored by: dwchin on Feb 28, '03 03:13:44AM

Not for me, unfortunately. When I say the artist's name, SpeechRecognitionServer crashes with EXC_BAD_ACCESS.



[ Reply to This | # ]
A script to use voice recognition with iTunes
Authored by: DougAdams on Feb 27, '03 04:20:03PM
More AppleScript/Speech scripts are located here and here.

Doug Doug's AppleScripts for iTunes

---



[ Reply to This | # ]

A more natural version of the script...
Authored by: simX on Feb 27, '03 06:24:16PM
Here's a more natural version of this script: you just have to say "play", wait for confirmation, and then the name of the track, bypassing the artist step. This is much more natural, IMHO. Note that if there are 2 tracks with the same name, you can THEN say the artist and it will choose that one. Furthermore, if the artist and track of two songs are the same, it will select a random one, not just play the first it finds.

tell application "iTunes"
set myList to (get name of every track of playlist 1) as list
set myFinishedList to myList & "Cancel"
end tell
tell application "SpeechRecognitionServer"
set myTrack to (listen for myFinishedList with prompt myFinishedList)
end tell
if myTrack is not "Cancel" then
tell application "iTunes"
set myTrackList to (get every track of playlist 1 where name is myTrack)
if number of items of myTrackList is 1 then
play (get first item of myTrackList)
else
set myArtistNames to {"Cancel"} & (get artist of every track of playlist 1 where name is myTrack)
tell application "SpeechRecognitionServer"
set myArtist to (listen for myArtistNames with prompt myArtistNames)
end tell
if myArtist is not "Cancel" then
set myFocusedTrackList to (get every track of playlist 1 where name is myTrack and artist is myArtist)
set randnum to (random number ((number of items of myFocusedTrackList) - 1)) + 1
play (get item randnum of myTrackList)
end if
set randnum to ((random number (numitems - 1)) + 1)
play (get item randnum of myTrackList)
end if
end tell
end if


[ Reply to This | # ]
A more natural version of the script...
Authored by: kawcat on Jul 18, '03 08:23:37AM

Sounds like a wondrful script but...
exactly where should the script be put on the hard disk?

my speech recognition floater recognizes the word "play" but nothing happens when I continue with a artist's or song's name.


I have a rather large music library - is it just because I have to wait a long time for the script to work?



[ Reply to This | # ]
A more natural version of the script...
Authored by: ccsccs7 on Dec 21, '03 07:22:57AM

AppleScript can be slow (and Speech Recognition can also slow down if it has to sort through a large number of words). you'll be searching through a large number of possible matches with an iTunes library.

Another possiblity is that your song titles are hard to pronounce or aren't recognized in the way that you would say it (as opposed to how the computer would expect to "hear" it).

The script should be added to your Speakable Items folder: Library -> Speech -> Speakable Items. You can also get it there by selecting the script in the Finder and saying "make this speakable."



[ Reply to This | # ]
A more natural version of the script...
Authored by: boopeep on Mar 20, '05 11:43:41PM

Wait.. im a gimp. In order for the sript to work, do I need to use the SpeechRecognitionServer file? I'm having the same problem as the other guy. All it does is recognize "play" then nothing else. THX!



[ Reply to This | # ]
A more natural version of the script...
Authored by: apechette on Mar 15, '06 04:08:57PM

Thanks for the script. I copied it into ScriptEditor and then compiled and saved it in the Speakable Items folder. It recognizes the 'play' command but it does not recognize track names. A little help maybe? I have over 5,000 songs, will this make a difference?



[ Reply to This | # ]
A more natural version of the script...
Authored by: rob94 on Dec 31, '08 03:02:22PM

when you use this script you have to say what you named it when you saved it. i named it play originally and it just played a song from itunes. so i decided to try and rename it itunes play and it worked. you have to name it something else such as itunes play instead of play and when you use it you say "itunes play" instead of just "play" and then continue with the artist name or the track name depending on which script you used and it will work. it may take a while for songs with more than one word as the title.



[ Reply to This | # ]
A script to use voice recognition with iTunes
Authored by: anthony324 on Sep 18, '09 03:15:28PM

I cannont seem to get past the artist and/or song!



[ Reply to This | # ]