Spaces:
Sleeping
Sleeping
kevinwang676
commited on
Commit
•
9d0a20f
1
Parent(s):
76581c2
Update app.py
Browse files
app.py
CHANGED
@@ -223,29 +223,27 @@ def merge_audios(folder_path):
|
|
223 |
return "AI配音版.wav"
|
224 |
|
225 |
import shutil
|
226 |
-
from pathlib import Path
|
227 |
|
228 |
def convert_from_srt(apikey, filename, audio_full, voice, multilingual):
|
229 |
subtitle_list = read_srt(filename)
|
230 |
|
231 |
-
#audio_data, sr =
|
232 |
-
audio_data, sr = librosa.load((str(Path(audio_full))), sr=44100)
|
233 |
|
234 |
-
write("audio_full.wav", sr, audio_data.astype(np.int16))
|
235 |
|
236 |
if os.path.isdir("output"):
|
237 |
shutil.rmtree("output")
|
238 |
if multilingual==False:
|
239 |
for i in subtitle_list:
|
240 |
os.makedirs("output", exist_ok=True)
|
241 |
-
trim_audio([[i.start_time, i.end_time]],
|
242 |
print(f"正在合成第{i.index}条语音")
|
243 |
print(f"语音内容:{i.text}")
|
244 |
convert(apikey, i.text, f"sliced_audio_{i.index}_0.wav", voice, i.text + " " + str(i.index))
|
245 |
else:
|
246 |
for i in subtitle_list:
|
247 |
os.makedirs("output", exist_ok=True)
|
248 |
-
trim_audio([[i.start_time, i.end_time]],
|
249 |
print(f"正在合成第{i.index}条语音")
|
250 |
print(f"语音内容:{i.text.splitlines()[1]}")
|
251 |
convert(apikey, i.text.splitlines()[1], f"sliced_audio_{i.index}_0.wav", voice, i.text.splitlines()[1] + " " + str(i.index))
|
@@ -260,7 +258,7 @@ with gr.Blocks() as app:
|
|
260 |
with gr.Column():
|
261 |
inp0 = gr.Textbox(type='password', label='请输入您的OpenAI API Key')
|
262 |
inp1 = gr.File(file_count="single", label="请上传一集视频对应的SRT文件")
|
263 |
-
inp2 = gr.Audio(label="请上传一集视频的配音文件", info="需要是.wav音频文件")
|
264 |
inp3 = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='请选择一个说话人提供基础音色', info="试听音色链接:https://platform.openai.com/docs/guides/text-to-speech/voice-options", value='alloy')
|
265 |
#inp4 = gr.Dropdown(label="请选择用于分离伴奏的模型", info="UVR-HP5去除背景音乐效果更好,但会对人声造成一定的损伤", choices=["UVR-HP2", "UVR-HP5"], value="UVR-HP5")
|
266 |
inp4 = gr.Checkbox(label="SRT文件是否为双语字幕", info="若为双语字幕,请打勾选择(SRT文件中需要先出现中文字幕,后英文字幕;中英字幕各占一行)")
|
|
|
223 |
return "AI配音版.wav"
|
224 |
|
225 |
import shutil
|
|
|
226 |
|
227 |
def convert_from_srt(apikey, filename, audio_full, voice, multilingual):
|
228 |
subtitle_list = read_srt(filename)
|
229 |
|
230 |
+
#audio_data, sr = librosa.load(audio_full, sr=44100)
|
|
|
231 |
|
232 |
+
#write("audio_full.wav", sr, audio_data.astype(np.int16))
|
233 |
|
234 |
if os.path.isdir("output"):
|
235 |
shutil.rmtree("output")
|
236 |
if multilingual==False:
|
237 |
for i in subtitle_list:
|
238 |
os.makedirs("output", exist_ok=True)
|
239 |
+
trim_audio([[i.start_time, i.end_time]], audio_full, f"sliced_audio_{i.index}")
|
240 |
print(f"正在合成第{i.index}条语音")
|
241 |
print(f"语音内容:{i.text}")
|
242 |
convert(apikey, i.text, f"sliced_audio_{i.index}_0.wav", voice, i.text + " " + str(i.index))
|
243 |
else:
|
244 |
for i in subtitle_list:
|
245 |
os.makedirs("output", exist_ok=True)
|
246 |
+
trim_audio([[i.start_time, i.end_time]], audio_full, f"sliced_audio_{i.index}")
|
247 |
print(f"正在合成第{i.index}条语音")
|
248 |
print(f"语音内容:{i.text.splitlines()[1]}")
|
249 |
convert(apikey, i.text.splitlines()[1], f"sliced_audio_{i.index}_0.wav", voice, i.text.splitlines()[1] + " " + str(i.index))
|
|
|
258 |
with gr.Column():
|
259 |
inp0 = gr.Textbox(type='password', label='请输入您的OpenAI API Key')
|
260 |
inp1 = gr.File(file_count="single", label="请上传一集视频对应的SRT文件")
|
261 |
+
inp2 = gr.Audio(label="请上传一集视频的配音文件", info="需要是.wav音频文件", type="filepath")
|
262 |
inp3 = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='请选择一个说话人提供基础音色', info="试听音色链接:https://platform.openai.com/docs/guides/text-to-speech/voice-options", value='alloy')
|
263 |
#inp4 = gr.Dropdown(label="请选择用于分离伴奏的模型", info="UVR-HP5去除背景音乐效果更好,但会对人声造成一定的损伤", choices=["UVR-HP2", "UVR-HP5"], value="UVR-HP5")
|
264 |
inp4 = gr.Checkbox(label="SRT文件是否为双语字幕", info="若为双语字幕,请打勾选择(SRT文件中需要先出现中文字幕,后英文字幕;中英字幕各占一行)")
|