feat: tts

This commit is contained in:
superobk
2024-03-19 17:33:09 +08:00
parent 2dccf5e78d
commit f2d6b9e526
90 changed files with 533580 additions and 5 deletions

62
tts/vits/text/sanskrit.py Normal file
View File

@ -0,0 +1,62 @@
import re
from indic_transliteration import sanscript
# List of (iast, ipa) pairs:
_iast_to_ipa = [(re.compile('%s' % x[0]), x[1]) for x in [
('a', 'ə'),
('ā', 'aː'),
('ī', 'iː'),
('ū', 'uː'),
('', 'ɹ`'),
('', 'ɹ`ː'),
('', 'l`'),
('', 'l`ː'),
('e', 'eː'),
('o', 'oː'),
('k', 'k⁼'),
('k⁼h', ''),
('g', 'g⁼'),
('g⁼h', ''),
('', 'ŋ'),
('c', 'ʧ⁼'),
('ʧ⁼h', 'ʧʰ'),
('j', 'ʥ⁼'),
('ʥ⁼h', 'ʥʰ'),
('ñ', 'n^'),
('', 't`⁼'),
('t`⁼h', 't`ʰ'),
('', 'd`⁼'),
('d`⁼h', 'd`ʰ'),
('', 'n`'),
('t', 't⁼'),
('t⁼h', ''),
('d', 'd⁼'),
('d⁼h', ''),
('p', 'p⁼'),
('p⁼h', ''),
('b', 'b⁼'),
('b⁼h', ''),
('y', 'j'),
('ś', 'ʃ'),
('', 's`'),
('r', 'ɾ'),
('', 'l`'),
('h', 'ɦ'),
("'", ''),
('~', '^'),
('', '^')
]]
def devanagari_to_ipa(text):
text = text.replace('', 'ओम्')
text = re.sub(r'\s*।\s*$', '.', text)
text = re.sub(r'\s*।\s*', ', ', text)
text = re.sub(r'\s*॥', '.', text)
text = sanscript.transliterate(text, sanscript.DEVANAGARI, sanscript.IAST)
for regex, replacement in _iast_to_ipa:
text = re.sub(regex, replacement, text)
text = re.sub('(.)[`ː]*ḥ', lambda x: x.group(0)
[:-1]+'h'+x.group(1)+'*', text)
return text