mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-10-08 16:00:01 +08:00
Update TTS.py
This commit is contained in:
parent
347dcd7d76
commit
a61f007060
@ -901,10 +901,53 @@ class TTS:
|
|||||||
# 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:
|
||||||
audio = speed_change(audio, speed=speed_factor, sr=int(sr))
|
audio = speed_change(audio, speed=speed_factor, sr=int(sr))
|
||||||
@ -916,6 +959,8 @@ class TTS:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def speed_change(input_audio:np.ndarray, speed:float, sr:int):
|
def speed_change(input_audio:np.ndarray, speed:float, sr:int):
|
||||||
# 将 NumPy 数组转换为原始 PCM 流
|
# 将 NumPy 数组转换为原始 PCM 流
|
||||||
raw_audio = input_audio.astype(np.int16).tobytes()
|
raw_audio = input_audio.astype(np.int16).tobytes()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user