Created
          October 26, 2016 21:32 
        
      - 
      
 - 
        
Save loretoparisi/a22c03094cb899e8f9ca4fbcea8dda79 to your computer and use it in GitHub Desktop.  
    IPA (Internationl Phonetic Alphabet) to macOS say Text To Speech (TTS) conversion
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
To speech out IPA to tts