Correcting Pronunciation Errors in 'Say' Command in Terminal

Solution 1:

Here you go:

# read.sh <file-to-read> [name-of-voice]
#!/bin/bash

textToRead=$(cat $1)

IFS=$'\n'
while read rep; do
        IFS=" "
        repArray=( $rep )
        textToRead=${textToRead//${repArray[0]}//${repArray[1]}}
done < replacements.txt

if [ -z $2 ]; then
        echo "$textToRead" | say
else
        echo "$textToRead" | say -v $2
fi

This shell script read replacements from replacements.txt and uses the say command to read the files content after replacing what's defined in replacements.txt.

replacements.txt: One line per replacement, <search> <replace>.

Sorry for the ugly code... I hate bash scripting.

Solution 2:

According to this 2007 thread at discussions.apple.com the VoiceOver utility only fixes pronunciations in VoiceOver itself, not in text-to-speech.

So if you want to get say to correctly pronounce the words you should run a find and replace on the text file for each mis-pronounced word. There is probably a good way to do this in one step with a script, but if you just want to do it once you could:

  1. Open the file in Text Edit (or any text editor you prefer, I like Text Wrangler)
  2. Find (e.g.) "women" and replace all with "wimmen" (Located at Edit > Find > Find and Replace... in Text Edit)
  3. Move to the next word you want to correct finding and replacing all until you've corrected all the mispronunciations.
  4. Run say on the now incorrectly spelled text file.