Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 03-15-2006, 03:23 PM   #1
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
Question Fun with Speakable Items

I just discovered the magic that is speakable items, and I can't help but love the idea of adressing my computer by name and commanding it to do something.

Now, My question is this: Is there a way to make the computer reply to keywords with predetermined answers? It's kinda dorky, but since i use the command line, when I say "computer" I'd like it to respond with "Yes?" or something.
If this is too far out, let me know, but I have a feeling someone figured this out.
Thanks in advance.
BehindthePlan is offline   Reply With Quote
Old 03-15-2006, 04:37 PM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Here's a sample AppleScript (try running it in Script Editor) from an Apple document that seems temporarily unavailable but can be accessed from Google's cache:
http://72.14.203.104/search?q=cache:...&client=safari

Code:
tell application "SpeechRecognitionServer"
	local theResultstring, helpLanguageModel, choicesLanguageModel
	set helpLanguageModel to {"help", "help me", "what can i say"}
	set choicesLanguageModel to {"iMac", "iBook", "PowerMac"}
	set thePrompt to "What is your [[emph +]] favorite Macintosh?"
	try
		set theResultstring to listen for choicesLanguageModel & helpLanguageModel with prompt thePrompt giving up after 30
		if theResultstring is "iMac" then
			say "I like that [[emph +]] too!"
		else if theResultstring is "iBook" then
			say "The iBook is [[emph +]] cool"
		else if theResultstring is "PowerMac" then
			say "[[emph +]]Wow. You must be a professional."
		else if theResultstring is in helpLanguageModel then
			tell me to doHelp()
		end if
	end try
end tell

on doHelp()
	say "I would really like to help you but I cannot."
end doHelp
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 03-15-2006, 05:25 PM   #3
styrafome
Hall of Famer
 
Join Date: Nov 2004
Posts: 3,818
Hmmm...how long can it be before someone writes Marvin the Paranoid Android, "Dark Star" bomb, or HAL 9000 scripts?

"Open the keychain, Hal......Hal......open the keychain..."
styrafome is offline   Reply With Quote
Old 03-15-2006, 07:38 PM   #4
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
Hayne, thanks for your response, though I'm not quite savvy enough to know whether or not this really answers my question. I basically want verbal commands to incite a spoken response from the speach feedback, such as it does during an error, only, obivously, editable to my liking
BehindthePlan is offline   Reply With Quote
Old 03-15-2006, 08:39 PM   #5
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
I'm not familiar enough with the standard speakable items to know how easy it would be to hook this sort of thing up. But I vaguely recall that they make use of AppleScript, so it should be possible with some investigation.

In any case, the script I showed above does work (on my 10.4.5 machine) and so it could provide a base for writing your own script that would do whatever you want. The script above only speaks back to you in response to your speech input but it could do anything that is possible in AppleScript - e.g. opening an application, opening a document, etc.

Of course you would need to learn AppleScript to do this.
There are lots of introductory tutorials available and lots of people on these forums who know a lot about AppleScript and are usually happy to help if you describe what you want to do.

To get started, just open Script Editor (it's under /Applications/AppleScript) and copy & paste the above script into it, then press "Run".
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 03-15-2006, 08:42 PM   #6
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
Question

I would like write a script (or scripts) that would do two things, though I know nothing about writing scripts.

I recently discovered speakable commands, and I would like to script responses by the speach feedback beyond the standard "whiit" or "speak command acknowledgement".

What I was hoping to acheive would be a a command that would simply result in a spoken phrase such as "thank you" and it's response, "you're welcome", spoken by the computer. the second response i was hoping to script would be a single response at command recognition, but only when the keyword is spoken, such as "computer" and it's response "yes dave?" with no further response.

These scripts are clearly useless beyond simple amusement, but having little knowledge of writing code and scripts I figure this would be a good way to start. I was also wondering how these scripts could be saved/exported to a speakable command so that they would operate soleley in that environment.

Thanks for any advice/scripts that you guys could share with me!
BehindthePlan is offline   Reply With Quote
Old 03-15-2006, 09:23 PM   #7
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
BehindthePlan:
I merged your new thread into this existing one. Let's keep it to the one thread. I'll move this thread into the Developers forum since that's what you seem to want.

But to get people to help you, you are going to need to make a start on it yourself. Start by searching for docs on AppleScript, on Speakable Items, etc, and read it all, then try some experiments with Script Editor in making your own scripts etc. Show us your scripts, tell us what works and what doesn't and then people will help.
__________________
hayne.net/macosx.html

Last edited by hayne; 03-15-2006 at 09:25 PM.
hayne is offline   Reply With Quote
Old 03-15-2006, 11:47 PM   #8
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
Thanks, as you can tell I'm new at this, and I appreciate you're help
BehindthePlan is offline   Reply With Quote
Old 03-16-2006, 04:40 AM   #9
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
From what I can see, Haynes script idea will work for the responses with the spoken keyword before command.

But the "Thank You" - "Your welcome" part has no keyword

So the computer would ignore the "Thank You"


I not sure if its possible to have two Keywords. If you could then You could use "Thank You" as one

Or you could just say "Computer, Thank You"
but it does not have the same feel.
mark hunte is offline   Reply With Quote
Old 03-16-2006, 01:35 PM   #10
Newbish
Triple-A Player
 
Join Date: Nov 2002
Location: Massachusetts
Posts: 202
Actually, I had a similar set-up back when I was using OS 9.

You can set the speech recognition to keep listening for commands for 15/30 seconds after the last spoken keyword. So I could say something like, "Get the email," and then say, "Thank you," when it finished without having to say "Computer" a second time to get its attention.

The "Thank you" was attached to a text file that was set to be spoken, which resulted in the computer saying, "You're welcome," each time I said that phrase.

With an applescript as the target for a given spoken command, you can have it randomly select responses from a list of appropriate phrases for the given command.
__________________
There is no such thing as a stupid question. If you don't ask, you will never know.
Newbish is offline   Reply With Quote
Old 03-17-2006, 01:36 PM   #11
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
I've been able to script a simple question/response dialog, however I am now stuck on 2 points, one is to apply the script continuously, and a second is while the script is running, the computer will not respond to other standard and custom commands. Can anyone help me out on getting this script to run as a constant command within the speakable items that does not interfere with existing commands? Here is the (simple) working script I've come up with so far:
PHP Code:
tell application "SpeechRecognitionServer"
    
listen for {"Thankyou compuder"}
    
say "Your [[emph+]]welcome."
end tell 
Note: I use "compuder" as speech recognition doesn't recognize me caying computer with a T as well as D
BehindthePlan is offline   Reply With Quote
Old 03-17-2006, 01:46 PM   #12
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
However, I have had no success trying to figure out a way to script a response in recognition of the keyword such as the "whiit" would normally imply
BehindthePlan is offline   Reply With Quote
Old 03-17-2006, 02:40 PM   #13
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
interesting.

On a hunch I just open the Speak-able items folder.

Thinking Maybe you could put your script in there.

The was a AS script already there. Named "Open Sherlock"

I opened it and changed it to a different app. (Delicious Library)

saved it and the ask the computer to "open Sherlock"

it opened "Delicious Library"

So I am assuming all you need to do is have a script
like

Code:
on run
	try
		
		say "Your [[emph+]]welcome."
		
	end try
end run
call it 'Thank You'

and place it in the Speak-able items folder.


I've done this and it shows up in my commands window.
But on my PB speak-able is a bit flakey, and will not respond to any bloody thing right now.
mark hunte is offline   Reply With Quote
Old 03-17-2006, 02:47 PM   #14
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
Yep it works......
mark hunte is offline   Reply With Quote
Old 03-21-2006, 01:04 PM   #15
Gaffer74
Triple-A Player
 
Join Date: Mar 2006
Location: South Blighty
Posts: 75
Does this (?useless) Mac OSX Speakable function work with any of you? (i'm not talking about your scripts...more the whole app itself).

I tried for half a day and could only get "What time is it?" to work

...surely it's quicker to look at my wrist?
__________________
PowerBook G4, 1.67Ghz, 1Gb RAM, 80Gb HD, 128Mb VRAM, Mac OS X.4.8 ... Extreme BaseStation
4thGen 20Gb iPod, Hdphn Remote, Senny PX100, Senny CX300, iSkin evo2, iPoDonut, iTrip
2nd Powerbook = G4, 550Mhz, 512Mb RAM, 20Gb HD, 16Mb VRAM, Mac OS X.4.8
Gaffer74 is offline   Reply With Quote
Old 03-22-2006, 10:57 PM   #16
BehindthePlan
Prospect
 
Join Date: Mar 2006
Posts: 10
mark hunte, thank you so much! This is just what I've been looking for!
As for speakable items in general, I have a PB and it's touchy, and it definitely doesn't work with ANY other sounds in the room, so showing it off to friends makes me look like an ass, but then again, who talks to their computer AND has friends?
BehindthePlan is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 03:53 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.