Spaces:
Sleeping
Sleeping
kevinwang676
commited on
Commit
•
7fde70a
1
Parent(s):
f486ddb
Update app.py
Browse files
app.py
CHANGED
@@ -223,23 +223,26 @@ def merge_audios(folder_path):
|
|
223 |
return "AI配音版.wav"
|
224 |
|
225 |
import shutil
|
|
|
226 |
|
227 |
-
def convert_from_srt(apikey, filename, audio_full, voice,
|
228 |
subtitle_list = read_srt(filename)
|
|
|
|
|
229 |
|
230 |
if os.path.isdir("output"):
|
231 |
shutil.rmtree("output")
|
232 |
if multilingual==False:
|
233 |
for i in subtitle_list:
|
234 |
os.makedirs("output", exist_ok=True)
|
235 |
-
trim_audio([[i.start_time, i.end_time]], audio_full, f"sliced_audio_{i.index}")
|
236 |
print(f"正在合成第{i.index}条语音")
|
237 |
print(f"语音内容:{i.text}")
|
238 |
convert(apikey, i.text, f"sliced_audio_{i.index}_0.wav", voice, i.text + " " + str(i.index))
|
239 |
else:
|
240 |
for i in subtitle_list:
|
241 |
os.makedirs("output", exist_ok=True)
|
242 |
-
trim_audio([[i.start_time, i.end_time]], audio_full, f"sliced_audio_{i.index}")
|
243 |
print(f"正在合成第{i.index}条语音")
|
244 |
print(f"语音内容:{i.text.splitlines()[1]}")
|
245 |
convert(apikey, i.text.splitlines()[1], f"sliced_audio_{i.index}_0.wav", voice, i.text.splitlines()[1] + " " + str(i.index))
|
@@ -254,15 +257,15 @@ with gr.Blocks() as app:
|
|
254 |
with gr.Column():
|
255 |
inp0 = gr.Textbox(type='password', label='请输入您的OpenAI API Key')
|
256 |
inp1 = gr.File(file_count="single", label="请上传一集视频对应的SRT文件")
|
257 |
-
inp2 = gr.Audio(label="请上传一集视频的配音文件", info="需要是.wav
|
258 |
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')
|
259 |
-
inp4 = gr.Dropdown(label="请选择用于分离伴奏的模型", info="UVR-HP5去除背景音乐效果更好,但会对人声造成一定的损伤", choices=["UVR-HP2", "UVR-HP5"], value="UVR-HP5")
|
260 |
-
|
261 |
btn = gr.Button("一键开启AI配音吧💕", variant="primary")
|
262 |
with gr.Column():
|
263 |
out1 = gr.Audio(label="为您生成的AI完整配音", type="filepath")
|
264 |
|
265 |
-
btn.click(convert_from_srt, [inp0, inp1, inp2, inp3, inp4
|
266 |
|
267 |
gr.Markdown("### <center>注意❗:请勿生成会对任何个人或组织造成侵害的内容,请尊重他人的著作权和知识产权。用户对此程序的任何使用行为与程序开发者无关。</center>")
|
268 |
gr.HTML('''
|
|
|
223 |
return "AI配音版.wav"
|
224 |
|
225 |
import shutil
|
226 |
+
from scipy.io import wavfile
|
227 |
|
228 |
+
def convert_from_srt(apikey, filename, audio_full, voice, multilingual):
|
229 |
subtitle_list = read_srt(filename)
|
230 |
+
samplerate, data = wavfile.read(audio_full)
|
231 |
+
wavfile.write("audio_full.wav", samplerate, data.astype(np.int16))
|
232 |
|
233 |
if os.path.isdir("output"):
|
234 |
shutil.rmtree("output")
|
235 |
if multilingual==False:
|
236 |
for i in subtitle_list:
|
237 |
os.makedirs("output", exist_ok=True)
|
238 |
+
trim_audio([[i.start_time, i.end_time]], "audio_full.wav", f"sliced_audio_{i.index}")
|
239 |
print(f"正在合成第{i.index}条语音")
|
240 |
print(f"语音内容:{i.text}")
|
241 |
convert(apikey, i.text, f"sliced_audio_{i.index}_0.wav", voice, i.text + " " + str(i.index))
|
242 |
else:
|
243 |
for i in subtitle_list:
|
244 |
os.makedirs("output", exist_ok=True)
|
245 |
+
trim_audio([[i.start_time, i.end_time]], "audio_full.wav", f"sliced_audio_{i.index}")
|
246 |
print(f"正在合成第{i.index}条语音")
|
247 |
print(f"语音内容:{i.text.splitlines()[1]}")
|
248 |
convert(apikey, i.text.splitlines()[1], f"sliced_audio_{i.index}_0.wav", voice, i.text.splitlines()[1] + " " + str(i.index))
|
|
|
257 |
with gr.Column():
|
258 |
inp0 = gr.Textbox(type='password', label='请输入您的OpenAI API Key')
|
259 |
inp1 = gr.File(file_count="single", label="请上传一集视频对应的SRT文件")
|
260 |
+
inp2 = gr.Audio(label="请上传一集视频的配音文件", info="需要是.wav音频文件")
|
261 |
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')
|
262 |
+
#inp4 = gr.Dropdown(label="请选择用于分离伴奏的模型", info="UVR-HP5去除背景音乐效果更好,但会对人声造成一定的损伤", choices=["UVR-HP2", "UVR-HP5"], value="UVR-HP5")
|
263 |
+
inp4 = gr.Checkbox(label="SRT文件是否为双语字幕", info="若为双语字幕,请打勾选择(SRT文件中需要先出现中文字幕,后英文字幕;中英字幕各占一行)")
|
264 |
btn = gr.Button("一键开启AI配音吧💕", variant="primary")
|
265 |
with gr.Column():
|
266 |
out1 = gr.Audio(label="为您生成的AI完整配音", type="filepath")
|
267 |
|
268 |
+
btn.click(convert_from_srt, [inp0, inp1, inp2, inp3, inp4], [out1])
|
269 |
|
270 |
gr.Markdown("### <center>注意❗:请勿生成会对任何个人或组织造成侵害的内容,请尊重他人的著作权和知识产权。用户对此程序的任何使用行为与程序开发者无关。</center>")
|
271 |
gr.HTML('''
|