mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-10-07 23:48:48 +08:00
Update TTS.py
This commit is contained in:
parent
347dcd7d76
commit
a61f007060
@ -900,10 +900,53 @@ class TTS:
|
|||||||
else:
|
else:
|
||||||
# audio = [item for batch in audio for item in batch]
|
# audio = [item for batch in audio for item in batch]
|
||||||
audio = sum(audio, [])
|
audio = sum(audio, [])
|
||||||
|
|
||||||
|
def ms_to_srt_time(ms):
|
||||||
|
N = int(ms)
|
||||||
|
hours, remainder = divmod(N, 3600000)
|
||||||
|
minutes, remainder = divmod(remainder, 60000)
|
||||||
|
seconds, milliseconds = divmod(remainder, 1000)
|
||||||
|
timesrt = f"{hours:02d}:{minutes:02d}:{seconds:02d},{milliseconds:03d}"
|
||||||
|
# print(timesrt)
|
||||||
|
return timesrt
|
||||||
|
|
||||||
|
import soundfile as sf
|
||||||
|
print("打印")
|
||||||
|
text = ""
|
||||||
|
with open(r'./srt/tts-out.txt', 'r',encoding='utf-8') as f:
|
||||||
|
text = f.read()
|
||||||
|
text_list = eval(text)
|
||||||
|
|
||||||
|
audio_samples = 0
|
||||||
|
srtlines = []
|
||||||
|
audio_opt = []
|
||||||
|
try:
|
||||||
|
num = 0
|
||||||
|
for x in audio:
|
||||||
|
ad = (np.concatenate([x], 0) * 32768).astype(np.int16)
|
||||||
|
|
||||||
|
srtline_begin=ms_to_srt_time(audio_samples*1000.0 / int(sr))
|
||||||
|
audio_samples += ad.size
|
||||||
|
srtline_end=ms_to_srt_time(audio_samples*1000.0 / int(sr))
|
||||||
|
|
||||||
|
audio_opt.append(ad)
|
||||||
|
|
||||||
|
srtlines.append(f"{len(audio_opt):02d}\n")
|
||||||
|
srtlines.append(srtline_begin+' --> '+srtline_end+"\n")
|
||||||
|
|
||||||
|
|
||||||
|
srtlines.append(text_list[num]+"\n\n")
|
||||||
|
|
||||||
|
num += 1
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
audio = np.concatenate(audio, 0)
|
audio = np.concatenate(audio, 0)
|
||||||
audio = (audio * 32768).astype(np.int16)
|
audio = (audio * 32768).astype(np.int16)
|
||||||
|
|
||||||
|
with open('./srt/tts-out.srt', 'w', encoding='utf-8') as f:
|
||||||
|
f.writelines(srtlines)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if speed_factor != 1.0:
|
if speed_factor != 1.0:
|
||||||
@ -912,6 +955,8 @@ class TTS:
|
|||||||
print(f"Failed to change speed of audio: \n{e}")
|
print(f"Failed to change speed of audio: \n{e}")
|
||||||
|
|
||||||
return sr, audio
|
return sr, audio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -935,4 +980,4 @@ def speed_change(input_audio:np.ndarray, speed:float, sr:int):
|
|||||||
# 将管道输出解码为 NumPy 数组
|
# 将管道输出解码为 NumPy 数组
|
||||||
processed_audio = np.frombuffer(out, np.int16)
|
processed_audio = np.frombuffer(out, np.int16)
|
||||||
|
|
||||||
return processed_audio
|
return processed_audio
|
||||||
|
Loading…
x
Reference in New Issue
Block a user