本文整理匯總了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