Skip to content

Instantly share code, notes, and snippets.

@unleashy
Last active July 9, 2022 02:38
Show Gist options
  • Save unleashy/9753ecd5e32c47d936559cca96e27d04 to your computer and use it in GitHub Desktop.
Save unleashy/9753ecd5e32c47d936559cca96e27d04 to your computer and use it in GitHub Desktop.
ruby xsampa -> ipa converter
module XSConverter
# noinspection RubyStringKeysInHashInspection
XSAMPA_MAP = {
'b_<' => 'ɓ',
'd`' => 'ɖ',
'd_<' => 'ɗ',
'g_<' => 'ɠ',
'h\\' => 'ɦ',
'j\\' => 'ʝ',
'l`' => 'ɭ',
'l\\' => 'ɺ',
'n`' => 'ɳ',
'p\\' => 'ɸ',
'r`' => 'ɽ',
'r\\' => 'ɹ',
'r\\`' => 'ɻ',
's`' => 'ʂ',
's\\' => 'ɕ',
't`' => 'ʈ',
'v\\' => 'ʋ',
'x\\' => 'ɧ',
'z`' => 'ʐ',
'z\\' => 'ʑ',
'A' => 'ɑ',
'B' => 'β',
'B\\' => 'ʙ',
'C' => 'ç',
'D' => 'ð',
'E' => 'ɛ',
'F' => 'ɱ',
'G' => 'ɣ',
'G\\' => 'ɢ',
'G\\_<' => 'ʛ',
'H' => 'ɥ',
'H\\' => 'ʜ',
'I' => 'ɪ',
'I\\' => 'ᵻ',
'J' => 'ɲ',
'J\\' => 'ɟ',
'J\\_<' => 'ʄ',
'K' => 'ɬ',
'K\\' => 'ɮ',
'L' => 'ʎ',
'L\\' => 'ʟ',
'M' => 'ɯ',
'M\\' => 'ɰ',
'N' => 'ŋ',
'N\\' => 'ɴ',
'O' => 'ɔ',
'O\\' => 'ʘ',
'P' => 'ʋ',
'Q' => 'ɒ',
'R' => 'ʁ',
'R\\' => 'ʀ',
'S' => 'ʃ',
'T' => 'θ',
'U' => 'ʊ',
'U\\' => 'ᵿ',
'V' => 'ʌ',
'W' => 'ʍ',
'X' => 'χ',
'X\\' => 'ħ',
'Y' => 'ʏ',
'Z' => 'ʒ',
'.' => '.',
'"' => 'ˈ',
'%' => 'ˌ',
"'" => 'ʲ',
'_j' => 'ʲ',
':' => 'ː',
':\\' => 'ˑ',
'-' => '',
'@' => 'ə',
'@\\' => 'ɘ',
'{' => 'æ',
'}' => 'ʉ',
'1' => 'ɨ',
'2' => 'ø',
'3' => 'ɜ',
'3\\' => 'ɞ',
'4' => 'ɾ',
'5' => 'ɫ',
'6' => 'ɐ',
'7' => 'ɤ',
'8' => 'ɵ',
'9' => 'œ',
'&' => 'ɶ',
'?' => 'ʔ',
'?\\' => 'ʕ',
'<\\' => 'ʢ',
'>\\' => 'ʡ',
'^' => 'ꜛ',
'!' => 'ꜜ',
'!\\' => 'ǃ',
'|' => '|',
'|\\' => 'ǀ',
'||' => '‖',
'|\\|\\' => 'ǁ',
'=\\' => 'ǂ',
'-\\' => '‿',
'_"' => ' ̈',
'_+' => '̟',
'_-' => '̠',
'_/' => '̌',
'_0' => '̥',
'_<' => '',
'=' => '̩',
'_=' => '̩',
'_>' => 'ʼ',
'_?\\' => 'ˤ',
'_\\' => '̂',
'_^' => '̯',
'_}' => '̚',
'`' => '˞',
'~' => '̃',
'_~' => '̃',
'_A' => '̘',
'_a' => '̺',
'_B' => '̏',
'_B_L' => '᷅',
'_c' => '̜',
'_d' => '̪',
'_e' => '̴',
'<F>' => '↘',
'_F' => '̂',
'_G' => 'ˠ',
'_H' => '́',
'_H_T' => '᷄',
'_h' => 'ʰ',
'_k' => '̰',
'_L' => '̀',
'_l' => 'ˡ',
'_M' => '̄',
'_m' => '̻',
'_N' => '̼',
'_n' => 'ⁿ',
'_O' => '̹',
'_o' => '̞',
'_q' => '̙',
'<R>' => '↗',
'_R' => '̌',
'_R_F' => '᷈',
'_r' => '̝',
'_T' => '̋',
'_t' => '̤',
'_v' => '̬',
'_w' => 'ʷ',
'_X' => '̆',
'_x' => '̽'
}.sort_by { |k, v| k.length }.reverse!.to_h.freeze
XSAMPA_MAP_RGX = Regexp.union(XSAMPA_MAP.keys)
def self.convert(ipa)
ipa.gsub(XSAMPA_MAP_RGX, XSAMPA_MAP)
end
end
@anna328p
Copy link

hi, what's the license on this?

@unleashy
Copy link
Author

@anna328p public domain, feel free to use it however you want, i'm sure there are bugs though

…how did you find this?

@anna328p
Copy link

@anna328p public domain, feel free to use it however you want, i'm sure there are bugs though

…how did you find this?

Searched "ruby x-sampa to ipa converter" on google, this was the first result

@unleashy
Copy link
Author

i see, thank you 😊

@acesuares
Copy link

Pretty cool! Did you make a gem for it ? Also, what does 'L\' mean??

@acesuares
Copy link

Oh I see, there is a gem already (it was the second hit on Google :-) https://github.com/hilarysk/string_to_ipa

@acesuares
Copy link

Oh... that gem uses a predefined sqlite database with english words to IPA... not easy to use for any other language.

@unleashy
Copy link
Author

unleashy commented Jul 9, 2022

@acesuares Sorry no gem. You can just copy and paste it though and do whatever you want with it :)

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