-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathphone_batch.py
More file actions
59 lines (44 loc) · 1.48 KB
/
phone_batch.py
File metadata and controls
59 lines (44 loc) · 1.48 KB
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
#!/usr/bin/env python3
import os
import argparse
import torch
import torch.nn as nn
import matplotlib.pyplot as plt
import re
from packaging import version
import phonemizer
from phonemizer.phonemize import phonemize
_phoneme_punctuations = '.!;:,?'
PHONEME_PUNCTUATION_PATTERN = r'['+_phoneme_punctuations+']+'
'''
def text2phone(text, language):
seperator = phonemizer.separator.Separator(' |', '', '|')
#try:
punctuations = re.findall(PHONEME_PUNCTUATION_PATTERN, text)
if version.parse(phonemizer.__version__) >= version.parse('2.1'):
ph = phonemize(text, separator=seperator, strip=False, njobs=1, backend='espeak', language=language, preserve_punctuation=True, language_switch='remove-flags')
else:
raise RuntimeError(" [!] Use 'phonemizer' version 2.1 or older.")
return ph.replace("| ?","|?").replace("| .","|.")
'''
def get_list(path):
new_l = []
with open(path,'r') as list_file:
for row in list_file:
if row:
new_l.append(row.strip())
return new_l
def from_list_file(list_phone,file_name):
new_f = open(file_name,"w+")
for item in list_phone:
new_f.write(item+'\n')
new_f.close()
if __name__ == '__main__':
# get word
l = get_list('list.txt')
n_l = []
for item in l:
result = text2phone(item, "pt-br")
print(item+" "+" ".join(result[:-1]))
n_l.append(item+" "+" ".join(result[:-1]))
from_list_file(n_l,"new_ipa.txt")