本文整理汇总了Python中pypinyin.Style.TONE3属性的典型用法代码示例。如果您正苦于以下问题:Python Style.TONE3属性的具体用法?Python Style.TONE3怎么用?Python Style.TONE3使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pypinyin.Style
的用法示例。
在下文中一共展示了Style.TONE3属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_lab
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def _add_lab(txtlines, wav_dir_path):
logger = logging.getLogger('mtts')
for line in txtlines:
numstr, txt = line.split(' ')
txt = re.sub('#\d', '', txt)
pinyin_list = pinyin(txt, style=Style.TONE3)
new_pinyin_list = []
for item in pinyin_list:
if not item:
logger.warning(
'{file_num} do not generate right pinyin'.format(numstr))
if not item[0][-1].isdigit():
phone = item[0] + '5'
else:
phone = item[0]
new_pinyin_list.append(phone)
lab_file = os.path.join(wav_dir_path, numstr + '.lab')
with open(lab_file, 'w') as oid:
oid.write(' '.join(new_pinyin_list))
示例2: _add_pinyin
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def _add_pinyin(txtlines, output_path):
''' txt2pinyin in one file '''
logger = logging.getLogger('mtts')
all_pinyin = []
for line in txtlines:
numstr, txt = line.split(' ')
txt = re.sub('#\d', '', txt)
pinyin_list = pinyin(txt, style=Style.TONE3)
new_pinyin_list = []
for item in pinyin_list:
if not item:
logger.warning(
'{file_num} do not generate right pinyin'.format(numstr))
if not item[0][-1].isdigit():
phone = item[0] + '5'
else:
#phone = item[0]
phone = item[0].replace('v', 'u')
new_pinyin_list.append(phone)
all_pinyin.append(numstr + ' ' + ' '.join(new_pinyin_list))
all_pinyin_file = os.path.join(output_path, 'all_pinyin.lab')
with open(all_pinyin_file, 'w') as oid:
for item in all_pinyin:
oid.write(item + '\n')
示例3: pypinyin_g2p_phone
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def pypinyin_g2p_phone(text) -> List[str]:
from pypinyin import pinyin
from pypinyin import Style
from pypinyin.style._utils import get_finals
from pypinyin.style._utils import get_initials
phones = [
p
for phone in pinyin(text, style=Style.TONE3)
for p in [
get_initials(phone[0], strict=True),
get_finals(phone[0], strict=True),
]
if len(p) != 0
]
return phones
示例4: __convert_transcript
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def __convert_transcript(raw_transcript):
"""
Converts a Chinese transcript to a Chinese pinyin sequence.
"""
waveid, raw_trans = raw_transcript.split("\t")[:2]
wavename = waveid + ".wav"
symbols = ",.!?"
# For simplicity, we only retain the Chinese chars and symbols
trans = ''.join([_char for _char in __replace_symbols(raw_trans) if __is_chinese(_char) or _char in symbols])
pinyin_trans = []
for pinyin in lazy_pinyin(trans, style=Style.TONE3):
if pinyin not in symbols and not pinyin[-1].isdigit():
pinyin_trans.append(pinyin + "0")
else:
pinyin_trans.append(pinyin)
return wavename, " ".join(pinyin_trans)
示例5: txt2pinyin
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def txt2pinyin(txt):
phone_list = []
'''
if isinstance(txt, str):
pinyin_list = pinyin(unicode(txt,'utf-8'), style = Style.TONE3)
elif isinstance(txt, unicode):
pinyin_list = pinyin(txt, style = Style.TONE3)
else:
print('error: unsupport coding form')
'''
pinyin_list = pinyin(txt, style = Style.TONE3)
for item in pinyin_list:
phone_list.append(seprate_syllable(pinyinformat(item[0])))
return phone_list
示例6: chs_pinyin
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def chs_pinyin(text):
pys = pinyin(text, style=Style.TONE3)
results = []
sentence = []
for i in range(len(pys)):
if pys[i][0][0] == "," or pys[i][0][0] == "、" or pys[i][0][0] == '·':
pys[i][0] = ','
elif pys[i][0][0] == '。' or pys[i][0][0] == "…":
pys[i][0] = '.'
elif pys[i][0][0] == '―' or pys[i][0][0] == "――" or pys[i][0][0] == '—' or pys[i][0][0] == '——':
pys[i][0] = ','
elif pys[i][0][0] == ";":
pys[i][0] = ';'
elif pys[i][0][0] == ":":
pys[i][0] = ':'
elif pys[i][0][0] == "?":
pys[i][0] = '?'
elif pys[i][0][0] == "!":
pys[i][0] = '!'
elif pys[i][0][0] == "《" or pys[i][0][0] == '》' or pys[i][0][0] == '(' or pys[i][0][0] == ')':
continue
elif pys[i][0][0] == '“' or pys[i][0][0] == '”' or pys[i][0][0] == '‘' or pys[i][0][0] == '’' or pys[i][0][0] == '"':
continue
elif pys[i][0][0] == '(' or pys[i][0][0] == ')' or pys[i][0][0] == '"' or pys[i][0][0] == '\'':
continue
elif pys[i][0][0] == ' ' or pys[i][0][0] == '/' or pys[i][0][0] == '<' or pys[i][0][0] == '>' or pys[i][0][0] == '「' or pys[i][0][0] == '」':
continue
sentence.append(pys[i][0])
if pys[i][0] in ",.;?!:":
results.append(' '.join(sentence))
sentence = []
if len(sentence) > 0:
results.append(' '.join(sentence))
for i, res in enumerate(results):
print(res)
return results
示例7: pypinyin_g2p
# 需要导入模块: from pypinyin import Style [as 别名]
# 或者: from pypinyin.Style import TONE3 [as 别名]
def pypinyin_g2p(text) -> List[str]:
from pypinyin import pinyin
from pypinyin import Style
phones = [phone[0] for phone in pinyin(text, style=Style.TONE3)]
return phones