Skip to content

Instantly share code, notes, and snippets.

@44100hertz
Created March 11, 2022 06:09
Show Gist options
  • Save 44100hertz/87f079b7fd524e02c51f810ead0dbda3 to your computer and use it in GitHub Desktop.
Save 44100hertz/87f079b7fd524e02c51f810ead0dbda3 to your computer and use it in GitHub Desktop.
Takes espeak output, makes it into sort-of-readable phonetic language inspired by Sayspel
local input =
[==[
Put Your input text here.
]==]
local phonemes = {}
do
local h = io.popen('espeak -w /dev/null -x "' .. input .. '"')
phonemes = h:read('*a')
h:close()
end
-- http://espeak.sourceforge.net/phonemes.html
local subst = {
-- -- short words -- --
{'DI2;', 'dh'},
{'D@', 'dh'},
-- -- consonants -- --
{'j', 'y'},
{'tS', 'ch'},
{'kw', 'q'},
{'dZ', 'j'},
{'ks', 'x'},
{'gz', 'x'},
{'D', 'dh'},
{'T', 'th'},
{'S', 'sh'},
{'N', 'ng'},
{'L', 'l'},
{'k', 'c'},
-- -- vowel + rhotics -- --
{'A@', 'ar'},
{'e@', 'er'},
{'i@', 'i'},
{'o@', 'or'},
{'O@', 'or'},
{'3:?', 'ur'},
-- Vowels
{'eI', 'aa'},
{'aU', 'au'},
{'aa', 'a'},
{'A:', 'á'},
-- {'a', 'a'},
{'i:', 'é'},
{'aI', 'í'},
--{'i', 'i'},
{'OI', 'oi'},
{'oU', 'ó'},
{'O:', 'ou'},
{'O', 'o'},
{'u:', 'ú'},
{'E', 'e'},
{'I2?', 'i'},
{'0', 'o'},
{'V', 'u'},
{'U', 'oo'},
-- old schwa rules were to sometimes replace with 'u'
-- {'@([bptdkg])', 'u%1'},
-- {';@', 'u'},
-- now I use a schwa and I like it
{'@', ''},
-- -- ignored -- --
{'[-!_:;#\',]', ''},
}
print(phonemes)
print(input)
for i,s in ipairs(subst) do
local pat, sub = table.unpack(s)
phonemes = phonemes:gsub(pat, sub)
--print(pat, sub, phonemes)
end
print(phonemes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment