Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How can I do voice recognition on Mac OS X from the command line? Details:

% When I look in ~/Library/Speech/Speakable Items, I see many files, like "Tell me a joke", whose contents are:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> 
<plist version="0.9"> 
<dict> 
        <key>BuiltInCommandID</key> 
        <integer>105</integer> 
        <key>semanticCategory</key> 
        <string>globalTellMeAJoke</string> 
        <key>alternativeSpokenFeedback</key> 
        <string></string> 
        <key>suppressSpokenConfirmation</key> 
        <string>yes</string> 
        <key>alternativeFeedback</key> 
        <string></string> 
        <key>DefaultCommandName</key> 
        <string>Tell me a joke</string> 
</dict> 
</plist> 

% How does OS X know when to invoke this file? When I say something, does it look for a matching filename?

% How does OS X know what command to run? I see nothing in that file that says what command to run ("Tell me a joke" is not a command-line command).

% I know there's some osacompile magic going on, but can't figure out what it is.

% How can I get OS X to listen for the string "s" and run the program "cmd" in response? I'd prefer to do this purely from the command-line, but if I have to open up a graphical program, I will.

share|improve this question

1 Answer 1

You might be interested in reading Apple's documentation on Speakable Items, but the relevant part to your question, "How can I get OS X to listen for the string "s" and run the program "cmd" in response?" is:

You can add an item to the Speakable Items folder to make it speakable.

To open something using a spoken command, just add it to the Speakable Items folder. You can use a command to open anything you can open by double-clicking, including applications, files, and Web sites. You can also write scripts and add them to the folder.

In regards to "How does OS X know what command to run? I see nothing in that file that says what command to run?", the relevant portion of the file you posted is:

    <key>BuiltInCommandID</key> 
    <integer>105</integer> 
    <key>DefaultCommandName</key> 
    <string>Tell me a joke</string> 

This is saying, when the spoken command "Tell me a joke" is received, run the internal command ID#105, which is the "Tell me a joke" command.

In this case you're looking at an internal command to the speech system. But you can add AppleScripts or shell commands to the speakable items folder as well.

This article on Mac OS X Hints may be helpful as well.

EDIT: After some research I am not sure if you can run shell scripts directly from there, but a little AppleScript wrapper would be easy enough to write, and you could even write it so it can be duplicated and renamed, and it would just run the corresponding shell script from /scripts or something.

share|improve this answer
    
Wow, so OS X really does listen for the filename! Not fantastic design in my mind, but interesting. –  barrycarter Dec 16 '10 at 19:11
    
Yup, it sure does. Actually I believe what it does is rescans that folder every 20 seconds, converts all filenames to phonetic representations, and adds those to the list of commands it knows about. Personally, I think it's a great design -- nice and simple for the end user! –  Josh Dec 16 '10 at 19:14
    
My only gripe is that programs should depend on file content, not file name. However, what you said works and I was just making things too hard on myself (no compilation or anything necessary). Apparently, simple things confuse me! –  barrycarter Dec 22 '10 at 17:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.