How can you make OS X's say command speak IPA characters?

Here's a Ruby script that takes a string of Unicode IPA text and converts it to OS X's say command phonetic syntax.

Slap this Ruby code into a file—let's call it ipa2say.rb. Make the file executable (i.e. chmod u+x ipa2say.rb). Execute the executable, piping some IPA text to it. Out will come some ASCII phonetic text.

Then run say with the [[inpt PHON]] directive.

So, an example. Let's say you want to say the IPA text "ˌɪntərˈnæʃənəl fəˈnɛtɪk ˈælfəˌbɛt fəˈrɛvər". From the command line:

echo "ˌɪntərˈnæʃənəl fəˈnɛtɪk ˈælfəˌbɛt fəˈrɛvər" | ./ipa2say.rb

It will spit out:

IXntrnAESnl fAXnEHtIXk AElfbEHt frEHvr

You then run: say "[[inpt PHON]]IXntrnAESnl fAXnEHtIXk AElfbEHt frEHvr"

Here's the script.

#!/usr/bin/ruby -w

map =   {       'æ' => 'AE',
                'eɪ' => 'EY',
                'ɑ' => 'AO',
                'əˈ' => 'AX',
                'i' => 'IY',
                'ɛ' => 'EH',
                'ɪ' => 'IH',
                'aɪ' => 'AY',
                'ɪ' => 'IX',
                'ɑ' => 'AA',
                'u' => 'UW',
                'ʊ' => 'UH',
                'ʌ' => 'UX',
                'oʊ' => 'OW',
                'aʊ' => 'AW',
                'ɔɪ' => 'OY',
                'b' => 'b',
                'ʧ' => 'C',
                'd' => 'd',
                'ð' => 'D',
                'f' => 'f',
                'g' => 'g',
                'h' => 'h',
                'ʤ' => 'J',
                'k' => 'k',
                'l' => 'l',
                'm' => 'm',
                'n' => 'n',
                'ŋ' => 'N',
                'p' => 'p',
                'r' => 'r',
                's' => 's',
                'ʃ' => 'S',
                't' => 't',
                'θ' => 'T',
                'v' => 'v',
                'w' => 'w',
                'j' => 'y',
                'z' => 'z',
                'ʒ' => 'Z',
                'ɜ' => '',
                ' ' => ' ',
                'ˈ' => ''
        }

text = ARGF.read

substring = ''

text.split("").each do |c|

    substring << c

    if substring.length == 2
        if map.has_key? substring
            print map[ substring ]
        else
            front = substring[0]
            if map.has_key? front
                print map[ front ]
            end
            back = substring[1]
            if map.has_key? back
                print map[ back ]
            end
        end

        substring = ''
    end
end

Just wanted to add that IPA pronunciation has seemingly been moved to VoiceOver, which is now, I guess, a completely different TTS engine. Going to VoiceOver Utility, Speech, then Pronunciation allows customization with IPA. This has absolutely no effect on "say" and the "Edit, Speech, Start Speaking" command, tho—ugh!

VoiceOver Utility Application, Speech Options, Pronunciation Tab showing IPA listings for over-ridden pronunciations.