Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Created October 26, 2016 21:32
Show Gist options
  • Save loretoparisi/a22c03094cb899e8f9ca4fbcea8dda79 to your computer and use it in GitHub Desktop.
Save loretoparisi/a22c03094cb899e8f9ca4fbcea8dda79 to your computer and use it in GitHub Desktop.
IPA (Internationl Phonetic Alphabet) to macOS say Text To Speech (TTS) conversion
#!/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
@loretoparisi
Copy link
Author

To speech out IPA to tts

$ ipa=`echo "ˌɪntərˈnæʃənəl fəˈnɛtɪk ˈælfəˌbɛt fəˈrɛvər" | ./ipa2say.rb` ; say -v Victoria "[[inpt PHON]]$ipa"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment