Created
February 4, 2009 07:45
-
-
Save mattt/58006 to your computer and use it in GitHub Desktop.
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
module Keats | |
module Phones | |
IPA_CONSONANTS = { | |
"B" => "b", # b - Lower-case B <be> voiced bilabial plosive | |
"CH" => "t\312\203", # tʃ - T-Esh ligature <cheese> voiceless postalveolar affricate | |
"D" => "d", # d - Lower-case D <dee> voiced dental or alveolar plosive | |
"DH" => "\303\260", # ð - Eth <thee> voiced dental fricative | |
"F" => "f", # f - Lower-case F <fee> voiceless labiodental fricative | |
"G" => "g", # g - Lower-case G <green> voiced velar plosive | |
"HH" => "h", # h - Lower-case H <he> voiceless glottal fricative | |
"JH" => "d\312\222", # dʒ - D-Yogh ligature <gee> voiced postalveolar affricate | |
"K" => "k", # k - Lower-case k <key> voiceless velar plosive | |
"L" => "l", # l - Lower-case L <lee> voice alveolar lateral approx. | |
"M" => "m", # m - Lower-case M <me> voiced bilabial nasal | |
"N" => "n", # n - Lower-case N <knee> voiced alveolar nasal | |
"NG" => "\305\213", # ŋ - Engma <ping> voiced velar nasal | |
"P" => "p", # p - Lower-case P <pee> voiceless bilabial plosive | |
"R" => "\311\271", # ɹ - Turned R <read> voiced alveolar approximate | |
"S" => "s", # s - Lower-case S <sea> voiceless alveolar fricative | |
"SH" => "\312\203", # ʃ - Esh <she> voiceless postvelar fricative | |
"T" => "t", # t - Lower-case T <tea> voiceless alveolar plosive | |
"TH" => "\316\270", # θ - Theta <theta> voiceless dental fricative | |
"V" => "v", # v - Lower-case V <vee> voiced labiodental fricative | |
"W" => "w", # w - Lower-case W <we> voiced labio-velar approximant | |
"Y" => "j", # j - Lower-case J <yield> voiced palatal approximant | |
"Z" => "z", # z - Lower-case Z <zee> voiced alveolar fricative | |
"ZH" => "\312\222" # ʒ - Yogh <seizure> voiced postalveolar fricative | |
} | |
IPA_VOWELS = { | |
"AA" => "\311\221", # a - Script A <odd> open back unrounded vowel | |
"AE" => "\303\246", # æ - Ash <at> near-open front unrounded vowel | |
"AH" => "\312\214", # ᴧ - Turned V <hut> open-mid back unrounded vowel | |
"AO" => "\311\266", # ɶ - O-E ligature <ought> open front rounded vowel | |
"EH" => "\311\233", # ɛ - Epsilon <Ed> open-mid front unrounded vowel | |
"ER" => "\311\236", # ɞ - Closed-Epsilon* <hurt> open-mid front rounded vowel | |
"IH" => "\311\252", # ɪ - Small Capital I <it> near-close, front unrounded vowel | |
"IY" => "i", # i - Lower-case I <eat> close front unrounded vowel | |
"UH" => "\311\244", # ɤ - Ram's Horn <hood> close-mid back unrounded vowel | |
"UW" => "u", # u - Lower-case U <two> close back rounded vowel | |
"OY" => "\311\224i", # ɔi <toy> (diphthong) | |
"EY" => "\311\252", # eɪ <ate> (diphthong) | |
"AY" => "a\311\266", # aɪ <hide> (diphthong) | |
"AW" => "a\312\212", # aʊ <cow> (diphthong) | |
} | |
IPA_CHART = IPA_VOWELS.update(IPA_CONSONANTS) | |
STRESS_CHART = { | |
"1" => "\'", # ' - Primary Stress | |
"2" => "\"", # " - Secondary Stress | |
"0" => "" # - No Stress | |
} | |
end | |
end | |
class String | |
include Keats::Phones | |
def ipa_tokenize | |
self.split.collect do |token| | |
phoneme, stress = token.scan(/(\w{1,2})(\d)?/).first | |
"%s%s" % [IPA_CHART[phoneme], STRESS_CHART[stress]] | |
end | |
end | |
def to_ipa | |
"/%s/" % self.ipa_tokenize.join("") | |
end | |
end | |
# Example | |
puts "AH0 B Z AO1 R B AH0 N S IY0".to_ipa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment