Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[dict(style=TONE3, strict=False, heteronym=True), [['zhao1', 'chao2'],
['yang2']]],
[dict(style=INITIALS), [['zh'], ['']]],
[dict(style=INITIALS, heteronym=True), [['zh', 'ch'], ['']]],
[dict(style=INITIALS, strict=False), [['zh'], ['y']]],
[dict(style=INITIALS, strict=False, heteronym=True), [['zh', 'ch'],
['y']]],
[dict(style=FIRST_LETTER), [['z'], ['y']]],
[dict(style=FIRST_LETTER, heteronym=True), [['z', 'c'], ['y']]],
[dict(style=FIRST_LETTER, strict=False), [['z'], ['y']]],
[dict(style=FIRST_LETTER, strict=False, heteronym=True), [['z', 'c'],
['y']]],
[dict(style=FINALS), [['ao'], ['iang']]],
[dict(style=FINALS, heteronym=True), [['ao'], ['iang']]],
[dict(style=FINALS, strict=False), [['ao'], ['ang']]],
[dict(style=FINALS, strict=False, heteronym=True), [['ao'], ['ang']]],
[dict(style=FINALS_TONE), [['āo'], ['iáng']]],
['迂', dict(style=FINALS), ['v']],
['迂', dict(style=FINALS, strict=False), ['u']],
['约', dict(style=NORMAL), ['yue']],
['约', dict(style=FINALS), ['ve']],
['约', dict(style=FINALS, strict=False), ['ue']],
['冤', dict(style=NORMAL), ['yuan']],
['冤', dict(style=FINALS), ['van']],
['冤', dict(style=FINALS, strict=False), ['uan']],
['鱼', dict(style=NORMAL), ['yu']],
['鱼', dict(style=NORMAL, strict=False), ['yu']],
['鱼', dict(style=TONE), ['yú']],
['鱼', dict(style=TONE, strict=False), ['yú']],
['鱼', dict(style=TONE2), ['yu2']],
['鱼', dict(style=TONE2, strict=False), ['yu2']],
['鱼', dict(style=TONE3), ['yu2']],
['鱼', dict(style=TONE3, strict=False), ['yu2']],
['鱼', dict(style=INITIALS), ['']],
['鱼', dict(style=INITIALS, strict=False), ['y']],
['鱼', dict(style=FIRST_LETTER), ['y']],
['鱼', dict(style=FIRST_LETTER, strict=False), ['y']],
['鱼', dict(style=FINALS), ['v']],
['鱼', dict(style=FINALS, strict=False), ['u']],
['鱼', dict(style=FINALS_TONE), ['ǘ']],
['鱼', dict(style=FINALS_TONE, strict=False), ['ú']],
['鱼', dict(style=FINALS_TONE2), ['v2']],
['鱼', dict(style=FINALS_TONE2, strict=False), ['u2']],
['鱼', dict(style=FINALS_TONE3), ['v2']],
['鱼', dict(style=FINALS_TONE3, strict=False), ['u2']],
['约', dict(style=NORMAL), ['yue']],
['约', dict(style=NORMAL, strict=False), ['yue']],
"""包含声明和韵母的词语"""
hans = '中心'
# 默认风格,带声调
assert pinyin(hans) == [['zh\u014dng'], ['x\u012bn']]
assert pinyin(hans, strict=False) == [['zh\u014dng'], ['x\u012bn']]
# 普通风格,不带声调
assert pinyin(hans, NORMAL) == [['zhong'], ['xin']]
assert pinyin(hans, NORMAL, strict=False) == [['zhong'], ['xin']]
# 声调风格,拼音声调在韵母第一个字母上
assert pinyin(hans, TONE) == [['zh\u014dng'], ['x\u012bn']]
assert pinyin(hans, TONE, strict=False) == [['zh\u014dng'], ['x\u012bn']]
# 声调风格2,即拼音声调在各个声母之后,用数字 [1-4] 进行表示
assert pinyin(hans, TONE2) == [['zho1ng'], ['xi1n']]
assert pinyin(hans, TONE2, strict=False) == [['zho1ng'], ['xi1n']]
# 声调风格3,即拼音声调在各个拼音之后,用数字 [1-4] 进行表示
assert pinyin(hans, TONE3) == [['zhong1'], ['xin1']]
assert pinyin(hans, TONE3, strict=False) == [['zhong1'], ['xin1']]
# 声母风格,只返回各个拼音的声母部分
assert pinyin(hans, INITIALS) == [['zh'], ['x']]
assert pinyin(hans, INITIALS, strict=False) == [['zh'], ['x']]
# 首字母风格,只返回拼音的首字母部分
assert pinyin(hans, FIRST_LETTER) == [['z'], ['x']]
assert pinyin(hans, FIRST_LETTER, strict=False) == [['z'], ['x']]
# 注音风格,带声调
assert pinyin(hans, BOPOMOFO) == [['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
assert pinyin(hans, BOPOMOFO, strict=False) == [['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
# 注音风格,首字母
assert pinyin(hans, BOPOMOFO_FIRST) == [['ㄓ'], ['ㄒ']]
assert pinyin(hans, BOPOMOFO_FIRST, strict=False) == [['ㄓ'], ['ㄒ']]
# test CYRILLIC style
assert pinyin(hans, CYRILLIC) == [['чжун1'], ['синь1']]
assert pinyin(hans, CYRILLIC, strict=False) == [['чжун1'], ['синь1']]
['央', dict(style=FINALS), ['iang']],
['央', dict(style=FINALS, strict=False), ['ang']],
['英', dict(style=NORMAL), ['ying']],
['英', dict(style=FINALS), ['ing']],
['英', dict(style=FINALS, strict=False), ['ing']],
['雍', dict(style=NORMAL), ['yong']],
['雍', dict(style=FINALS), ['iong']],
['雍', dict(style=FINALS, strict=False), ['ong']],
['宜', dict(style=NORMAL), ['yi']],
['宜', dict(style=NORMAL, strict=False), ['yi']],
['宜', dict(style=TONE), ['yí']],
['宜', dict(style=TONE, strict=False), ['yí']],
['宜', dict(style=TONE2), ['yi2']],
['宜', dict(style=TONE2, strict=False), ['yi2']],
['宜', dict(style=TONE3), ['yi2']],
['宜', dict(style=TONE3, strict=False), ['yi2']],
['宜', dict(style=INITIALS), ['']],
['宜', dict(style=INITIALS, strict=False), ['y']],
['宜', dict(style=FIRST_LETTER), ['y']],
['宜', dict(style=FIRST_LETTER, strict=False), ['y']],
['宜', dict(style=FINALS), ['i']],
['宜', dict(style=FINALS, strict=False), ['i']],
['宜', dict(style=FINALS_TONE), ['í']],
['宜', dict(style=FINALS_TONE, strict=False), ['í']],
['宜', dict(style=FINALS_TONE2), ['i2']],
['宜', dict(style=FINALS_TONE2, strict=False), ['i2']],
['宜', dict(style=FINALS_TONE3), ['i2']],
['宜', dict(style=FINALS_TONE3, strict=False), ['i2']],
['盐', dict(style=NORMAL), ['yan']],
['盐', dict(style=NORMAL, strict=False), ['yan']],
def speak(self, text):
syllables = lazy_pinyin(text, style=pypinyin.TONE3)
print(syllables)
delay = 0
def preprocess(syllables):
temp = []
for syllable in syllables:
for p in TextToSpeech.punctuation:
syllable = syllable.replace(p, "")
if syllable.isdigit():
syllable = atc.num2chinese(syllable)
new_sounds = lazy_pinyin(syllable, style=pypinyin.TONE3)
for e in new_sounds:
temp.append(e)
else:
temp.append(syllable)
return temp
def speak(self, text):
syllables = lazy_pinyin(text, style=pypinyin.TONE3)
default_logger.debug(syllables)
delay = 0
def preprocess(syllables):
temp = []
for syllable in syllables:
for p in self.punctuation:
syllable = syllable.replace(p, '')
if syllable.isdigit():
syllable = num2chinese(syllable)
new_sounds = lazy_pinyin(syllable, style=pypinyin.TONE3)
for e in new_sounds:
temp.append(e)
else:
temp.append(syllable)
return temp
def preprocess(syllables):
temp = []
for syllable in syllables:
for p in self.punctuation:
syllable = syllable.replace(p, '')
if syllable.isdigit():
syllable = num2chinese(syllable)
new_sounds = lazy_pinyin(syllable, style=pypinyin.TONE3)
for e in new_sounds:
temp.append(e)
else:
temp.append(syllable)
return temp
def look_up(self, word):
result = pinyin(word, style=pypinyin.TONE3)
result = [self.word_2_safetext(item[0]) for item in result]
return result
def synthesize(self, text, src, dst):
"""
Synthesize .wav from text
src is the folder that contains all syllables .wav files
dst is the destination folder to save the synthesized file
"""
print("Synthesizing ...")
delay = 0
increment = 355 # milliseconds
pause = 500 # pause for punctuation
syllables = lazy_pinyin(text, style=pypinyin.TONE3)
# initialize to be complete silence, each character takes up ~500ms
result = AudioSegment.silent(duration=500*len(text))
for syllable in syllables:
path = src+syllable+".wav"
sound_file = Path(path)
# insert 500 ms silence for punctuation marks
if syllable in TextToSpeech.punctuation:
short_silence = AudioSegment.silent(duration=pause)
result = result.overlay(short_silence, position=delay)
delay += increment
continue
# skip sound file that doesn't exist
if not sound_file.is_file():
continue
segment = AudioSegment.from_wav(path)