How can I change how OS X's 'say' command pronounces a word?

Posted by jwhitlock on Super User See other posts from Super User or by jwhitlock
Published on 2010-07-30T17:38:36Z Indexed on 2012/09/09 3:40 UTC
Read the original article Hit count: 245

Filed under:
|

OS X's say command is useful for some tasks (such as Skype's 'notify me when a contact comes online), but it is pronouncing some names incorrectly. Is there a way to teach say to pronounce a word differently?

For example, try:

say "Hi, Joel Spolsky"

The 'ol' sounds like 'ball' rather than 'old'. I'd like to add an exception that say "Pronounce Spolsky like this", rather than try to teach new linguistic rules. I bet there is a way since it can pronounce "iphone" as Apple wants.


Update - After some research, here's what I've learned:

  1. Text-to-speech is split between turning the text to phonemes, and then the phonemes are turned into audio using a voice. Changing the voice doesn't effect the phonemes.
  2. The Speech Synthesis Manager has some functions for turning text to phonemes, and a method for registering a speech dictionary that will add new text-phoneme maps. However, Apple's speech dictionary must be in a binary form - I didn't find any plist XML.
  3. Using dtrace while running say, I found some interesting files opened in /System/Library/PrivateFrameworks/SpeechDictionary.framework/Resources. This is probably the speech dictionary, but they are all binary, except for Homophones, which is XML. Adding entries to Homophones does nothing - it is probably used in speech-to-text. They are also code signed by Apple - changing them may prevent some programs from working.
    • PrefixDictionary
    • CartNames
    • CartLite
    • SymbolDictionary
    • Homophones
  4. There are ways to add text versions of application interface elements so VoiceOver works, a lot of which a developer gets for free, but there are tricky bits. The standard here appears to be to use a phonetic spelling as needed.

My guesses are:

  1. say is a light layer of code on top of the Speech Synthesis Manager. It would be easy for the Apple devs to add a command line option to take the path to a speech dictionary plist for alternate phoneme mapping, but they didn't. It may be a useful open-source project to write a better say.
  2. Skype probably uses Speech Synthesis Manager directly, leaving no hooks to change the way my friend's names are pronounced, other than spelling them phonetically, which is silly.
  3. The easiest way to make a command line version of say is how JRobert suggested.

Here's my quick implementation, using Doug Harris's spelling suggestion:

#!/bin/sh
echo $@ | tr '[A-Z]' '[a-z]' |
sed "s/spolsky/spowlsky/g" |
/usr/bin/say

Finally, some fun command line stuff:

# Apple is weird
sqlite3 /System/Library/PrivateFrameworks/SpeechDictionary.framework/Resources/Tuples .dump
# Get too much information about what files are being opened
sudo dtrace -n 'syscall::open*:entry { printf("%s %s",execname,copyinstr(arg0)); }'
# Just fun
say -v bad "Joel Spolsky Spolsky Spolsky Spolsky Spolsky, Joel Spolsky Spolsky Spolsky Spolsky Spolsky"
echo "scale=1000; 4*a(1)" | bc -l | say

© Super User or respective owner

Related posts about osx

Related posts about say