Spaces:
Build error
Build error
File size: 1,590 Bytes
b20b7b4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import sys
sys.path.append("../")
from viphoneme import syms, vi2IPA_split
symbols = syms
_symbol_to_id = {s: i for i, s in enumerate(symbols)}
_id_to_symbol = {i: s for i, s in enumerate(symbols)}
def sequence_to_text(sequence):
result = ''
for symbol_id in sequence:
if symbol_id in _id_to_symbol:
result += _id_to_symbol[symbol_id]
return result
def text_to_sequence(text, cleaner_names):
sequence = []
text = text.replace('\s+',' ').lower()
phon = vi2IPA_split(text,"/")
phon = phon.split("/")[1:]
eol = -1
for i,p in reversed(list(enumerate(phon))):
if p not in ["..",""," ","."," "]:
eol = i
break
phones = phon[:i+1]+[" ","."]
phones_id =[]
for i in phones:
if i in _symbol_to_id:
phones_id.append(_symbol_to_id[i])
#phones_id = [_symbol_to_id[i] for i in phones]
sequence.extend(phones_id)
return sequence
def cleaned_text_to_sequence(cleaned_text):
sequence = []
phon = cleaned_text.split("/")[1:]
eol = -1
for i,p in reversed(list(enumerate(phon))):
if p not in ["..",""," ","."," "]:
eol = i
break
phones = phon[:i+1]+[" ","."]
phones_id =[]
for i in phones:
if i in _symbol_to_id:
phones_id.append(_symbol_to_id[i])
#phones_id = [_symbol_to_id[i] for i in phones]
sequence.extend(phones_id)
return sequence
if __name__ == "__main__":
text = "Nơi lưu trữ và cập nhật các bài viết, hình ảnh từ Tuấn Khanh"
seq = text_to_sequence(text, "")
print(seq) |