|
@@ -128,8 +128,13 @@ def import_jieba_userdict(ch_word_list, userDict_path='userDict.txt'):
|
|
|
jieba.load_userdict(userDict_path)
|
|
|
return jieba
|
|
|
|
|
|
-def gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path='test1.mp3',verbose=0):
|
|
|
+def gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path='test1.mp3',gender,verbose=0):
|
|
|
Y = []
|
|
|
+ pitch_step = 0
|
|
|
+ if gender == 0:
|
|
|
+ pitch_step=8
|
|
|
+ else:
|
|
|
+ pitch_step=0
|
|
|
print(jieba.lcut(ch_sentence))
|
|
|
for word in jieba.lcut(ch_sentence):
|
|
|
tmp_mapping_100 = hakka_100.loc[[word == i for i in hakka_100.chinese_clean],:].head(1)
|
|
@@ -143,14 +148,14 @@ def gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path='test1.mp
|
|
|
if tmp_mapping.index[0] in list(multi_sound.index):
|
|
|
y, sr = librosa.load('mp3_uni/{}.mp3'.format(tmp_mapping.index[0]))
|
|
|
if tmp_mapping.gender.values[0] == 'Male':
|
|
|
- y = librosa.effects.pitch_shift(y, sr, n_steps=8)
|
|
|
+ y = librosa.effects.pitch_shift(y, sr, n_steps=pitch_step)
|
|
|
else:
|
|
|
y, sr = librosa.load('mp3/{}.mp3'.format(tmp_mapping.index[0]))
|
|
|
if tmp_mapping.gender.values[0] == 'Male':
|
|
|
- y = librosa.effects.pitch_shift(y, sr, n_steps=8)
|
|
|
+ y = librosa.effects.pitch_shift(y, sr, n_steps=pitch_step)
|
|
|
Y += list(y[abs(y)>0.0005])
|
|
|
else:
|
|
|
y, sr = librosa.load('mp3_uni/hakka_100_{}.mp3'.format(tmp_mapping_100.index[0]))
|
|
|
- y = librosa.effects.pitch_shift(y, sr, n_steps=4)
|
|
|
+ y = librosa.effects.pitch_shift(y, sr, n_steps=pitch_step)
|
|
|
Y += list(y[abs(y)>0.0005])
|
|
|
librosa.output.write_wav(mp3_path, np.array(Y), sr)
|