Control itunes by voice

I would like to able to create a script that when iTunes is playing or open, I can say "play, (put name of song or artist here). Is this possible?

googleman76

Hi googleman76,

I think it’s possible. Here’s a simple quick algorithm:

get list of song names from the iTunes library
tell app “SpeakableItems” to activate
pause until the process appears
tell app “SpeechRecognition server”
listen continuously for {“play track”,“pause track”,“stop track”,“rewind track”} with identifier “the identifier” and use other parameters
stop listening for identifier “the identifier”
if the spoken phrase was “play track” then
listen continuously for song_names with identifier “Some identifier”
stop listening for identifier “Some identifier”
end if
end tell
You can reset the system preferences by quitting “SpeakableItems”
tell iTunes to play the track by that name

So you would say something like “play track”, slight pause before the song name, “Ain’t No Mountain High Enough”.

I have to get ready to go. Been working on scripting SpeechRecognitionServer all day. You have to watch the timings. Finder or whatever takes a long time with these apps. Probably will get a working script by tomorrow or as soon as possible if nobody gets it first.

I wrestled with this long time ago and still am.

gl,

Hi googleman76,

Good news. This is what I have so far:


set itunes_commands to {"play track", "stop track", "pause track", "rewind track"}
set inf_time to 1 * days

tell application "SpeakableItems" to launch

tell application "iTunes"
	--activate
	tell playlist "Library"
		set track_names to name of every track
	end tell
end tell

tell application "SpeechRecognitionServer"
	listen continuously for itunes_commands with prompt "Say an iTunes command." giving up after inf_time with identifier "command" displaying itunes_commands
	set user_command to result
	stop listening for identifier "command"
	set user_track to missing value
	if user_command is "play track" then
		listen continuously for track_names with prompt "What track?" giving up after inf_time with identifier "track name" displaying track_names
		set user_track to result
		stop listening for identifier "track name"
	end if
end tell

if user_track is not missing value then
	tell application "iTunes"
		--activate
		tell playlist "Library"
			play track user_track
		end tell
	end tell
end if

tell application "SpeakableItems" to quit

So far it’s working with “play track”, but track is hard to say, so I’m changing that later. Also, need to stop iTunes if it is playing so it doesn’t interfere with the speaking.

Editted: also thinking about making it a stay open app on idle.

Later,

Hello.

I can’t find the application Speakable Items, do I have to download it from somewhere, or is it in some package on the installation disks? I am on Snow Leopard.

Thanks.

Hi McUsrII,

path to app “SpeakableItems”

gives me:

alias “Macintosh HD:System:Library:Speech:Recognizers:AppleSpeakableItems.SpeechRecognizer:Contents:PlugIns:SpeakableItems.app:”

SpeechRecognitionServer is in Carbon Frameworks, but it’s working pretty well. :slight_smile: I’m happy because it never used to work this well in Jaguar. Apple must have improved it since then. Or maybe the computing speed.

Edited: I don’t think I downloaded anything about speech recognition, but it might have come with a game? I don’t think they install in the System folder though. Not sure.

gl,

Thanks kel. :slight_smile:

I guess the problem is that I have never used it before, so it has never been registered or something.

I find it (on Snow Leopard, and as a foreigner), a little bit hard to use, I have to say Tzafari for instance.

It is fun to play with. :slight_smile:

Yeah it is fun to play with. Ever since I got a mac, I’ve always wanted to buy an external mic. It’s essential for speech recognition. I remember one time in class, I was showing the other students how the computer could listen to what I say. The air conditioner ruined it all. It was too loud! Was I embarrassed when the computer wouldn’t talk back to us.

Model: MBP
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Hi

When you run the script several times in the Script Editor, things start to go wrong. Just force quit the Script Editor and reopen. I’m thinking that it has something to do with the other apps, besides SpeakableItems, taking a long time to quit. Not sure. Need to look into this later.

gl,

Waiting for the window app to close seems to have cured it when rerunning the script before the window app actually quits. Tested with this at the end of the script:


set itunes_commands to {"play track", "stop track", "pause track", "rewind track"}
set inf_time to 1 * days

tell application "SpeakableItems" to activate -- changed launch to activate

tell application "iTunes"
	--activate
	stop
	tell playlist "Library"
		set track_names to name of every track
	end tell
end tell

tell application "SpeechRecognitionServer"
	listen continuously for itunes_commands with prompt "Say an iTunes command." giving up after inf_time with identifier "command" displaying itunes_commands
	set user_command to result
	stop listening for identifier "command"
	set user_track to missing value
	if user_command is "play track" then
		listen continuously for track_names with prompt "What track?" giving up after inf_time with identifier "track name" displaying track_names
		set user_track to result
		stop listening for identifier "track name"
	end if
end tell

if user_track is not missing value then
	tell application "iTunes"
		--activate
		tell playlist "Library"
			play track user_track
		end tell
	end tell
end if

tell application "SpeakableItems" to quit

(*
tell application "SpeechFeedbackWindow" to quit
tell application "SpeechRecognitionServer" to quit
*)

-- check
tell application "System Events"
	repeat until not (exists process "SpeechFeedbackWindow")
		delay 2
		beep
	end repeat
end tell
say "Finished."

I wonder how we can make it so we don’t have to wait for the window app, if that’s it.:confused:

Thanks everyone for your help, I think I have something to work with now.

googleman76

Hi googleman76,

It’s so frustrating because every once in a while you need to add another command:


tell application "SpeechFeedbackWindow" to quit

The speech window stays open. Running this in the Script Editor fixes it and closes the window. that’s the last of the three apps that stays open.

I just thought of something to try.

Editted: oh and I just woke up because the computer kept beeping. :slight_smile: Computers are demanding!

gl,