mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-10-07 23:48:48 +08:00
优化了切分音频的性能和逻辑
This commit is contained in:
parent
1979211eda
commit
8a8ddad7e8
@ -74,11 +74,16 @@ import pydub, os
|
|||||||
|
|
||||||
def slice_audio_with_lib(audio_path, save_folder, format, subtitles, pre_preserve_time, post_preserve_time, pre_silence_time, post_silence_time, language='ZH', character='character'):
|
def slice_audio_with_lib(audio_path, save_folder, format, subtitles, pre_preserve_time, post_preserve_time, pre_silence_time, post_silence_time, language='ZH', character='character'):
|
||||||
list_file = os.path.join(save_folder, 'datamapping.list')
|
list_file = os.path.join(save_folder, 'datamapping.list')
|
||||||
|
try:
|
||||||
|
audio = pydub.AudioSegment.from_file(audio_path)
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
with open(list_file, 'w', encoding="utf-8") as f:
|
with open(list_file, 'w', encoding="utf-8") as f:
|
||||||
for i in range(len(subtitles)):
|
for i in range(len(subtitles)):
|
||||||
subtitle = subtitles[i]
|
subtitle = subtitles[i]
|
||||||
start = subtitle.start.total_seconds() - pre_preserve_time
|
start = subtitle.start.total_seconds() - pre_preserve_time
|
||||||
end = subtitle.end.total_seconds() + post_preserve_time
|
end = subtitle.end.total_seconds() + post_preserve_time
|
||||||
|
|
||||||
if i < len(subtitles) - 1:
|
if i < len(subtitles) - 1:
|
||||||
next_subtitle = subtitles[i + 1]
|
next_subtitle = subtitles[i + 1]
|
||||||
end = min(end, 1.0/2*(subtitle.end.total_seconds()+next_subtitle.start.total_seconds()))
|
end = min(end, 1.0/2*(subtitle.end.total_seconds()+next_subtitle.start.total_seconds()))
|
||||||
@ -86,12 +91,12 @@ def slice_audio_with_lib(audio_path, save_folder, format, subtitles, pre_preserv
|
|||||||
prev_subtitle = subtitles[i - 1]
|
prev_subtitle = subtitles[i - 1]
|
||||||
start = max(start, 1.0/2*(prev_subtitle.end.total_seconds()+subtitle.start.total_seconds()))
|
start = max(start, 1.0/2*(prev_subtitle.end.total_seconds()+subtitle.start.total_seconds()))
|
||||||
try:
|
try:
|
||||||
audio = pydub.AudioSegment.from_file(audio_path)
|
|
||||||
sliced_audio = audio[int(start * 1000):int(end * 1000)]
|
sliced_audio = audio[int(start * 1000):int(end * 1000)]
|
||||||
file_name = f'{character}_{i + 1:03d}.{format}'
|
file_name = f'{character}_{i + 1:03d}.{format}'
|
||||||
save_path = os.path.join(save_folder, file_name)
|
save_path = os.path.join(save_folder, file_name)
|
||||||
sliced_audio.export(save_path, format=format)
|
sliced_audio.export(save_path, format=format)
|
||||||
f.write(f"{file_name}|{character}|{language}|{subtitle.content}\n")
|
f.write(f"{file_name}|{character}|{language}|{subtitle.content}\n")
|
||||||
|
print(f"Slice {file_name} from {start} to {end}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from srt_utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
port = 8991
|
port = 8991
|
||||||
is_share = False
|
is_share = True
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
port = int(sys.argv[1])
|
port = int(sys.argv[1])
|
||||||
is_share = eval(sys.argv[2])
|
is_share = eval(sys.argv[2])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user