代码拉取完成,页面将自动刷新
同步操作将从 峯挚/HanTTS 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from pydub import AudioSegment
from pydub.silence import split_on_silence
import json
from pprint import pprint
from pathlib import Path
import sys
with open('mapping.json') as data_file:
data = json.load(data_file)
# keys = sorted(data.keys())
if len(sys.argv) != 2:
print("usage:")
print(" python process.py {key}")
print("to process ./recording/{key}.wav")
sys.exit(1)
key = sys.argv[1:][0]
syllables = data[key]
path = "./recording/"+key+".wav"
file = Path(path)
if not file.is_file():
raise Exception(path+" doesn't exist")
sound_file = AudioSegment.from_wav(path)
audio_chunks = split_on_silence(sound_file,
# must be silent for at least 300ms
min_silence_len=300,
# consider it silent if quieter than -48 dBFS
silence_thresh=-48
)
flag = False
if len(syllables)*5 != len(audio_chunks):
flag = True
for i, chunk in enumerate(audio_chunks):
syllable = syllables[i//5]
print(syllable)
j = i % 5
if j != 4: # 1st, 2nd, 3rd, 4th tone
out_file = "./pre/"+ syllable + str(j+1)+".wav"
else: # neutrual tone
out_file = "./pre/"+ syllable +".wav"
# out_file = "./pre/"+ str(i)+".wav"
print("exporting", out_file)
chunk.export(out_file, format="wav")
print(key, len(audio_chunks))
if flag:
print(key, "doesn't match expected audio chunks length")
print("expected:", len(syllables)*5, "actual:", len(audio_chunks))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。