kevinwang676 commited on
Commit
bab39d8
1 Parent(s): f15996c

Update app_share.py

Browse files
Files changed (1) hide show
  1. app_share.py +41 -3
app_share.py CHANGED
@@ -304,6 +304,37 @@ def merge_audios(folder_path):
304
 
305
  import shutil
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  def convert_from_srt(api_key, filename, audio_full, voice, multilingual):
308
 
309
  subtitle_list = read_srt(filename)
@@ -335,8 +366,10 @@ def convert_from_srt(api_key, filename, audio_full, voice, multilingual):
335
  except Exception:
336
  pass
337
  merge_audios("output")
 
 
338
 
339
- return "AI配音版.wav"
340
 
341
  restart_markdown = ("""
342
  ### 若此页面无法正常显示,请点击[此链接](https://openxlab.org.cn/apps/detail/Kevin676/OpenAI-TTS)唤醒该程序!谢谢🍻
@@ -374,11 +407,16 @@ with gr.Blocks() as app:
374
  inp3 = gr.Dropdown(choices=["Rachel", "Alice", "Chris", "Adam"], label='请选择一个说话人提供基础音色', info="试听音色链接:https://elevenlabs.io/app/speech-synthesis", value='Chris')
375
  #inp4 = gr.Dropdown(label="请选择用于分离伴奏的模型", info="UVR-HP5去除背景音乐效果更好,但会对人声造成一定的损伤", choices=["UVR-HP2", "UVR-HP5"], value="UVR-HP5")
376
  inp4 = gr.Checkbox(label="SRT文件是否为双语字幕", info="若为双语字幕,请打勾选择(SRT文件中需要先出现中文字幕,后英文字幕;中英字幕各占一行)")
377
- btn = gr.Button("一键开启AI配音吧💕", variant="primary")
378
  with gr.Column():
379
  out1 = gr.Audio(label="为您生成的AI完整配音", type="filepath")
 
 
 
 
380
 
381
- btn.click(convert_from_srt, [inp0, inp1, inp2, inp3, inp4], [out1])
 
382
 
383
  gr.Markdown("### <center>注意❗:请勿生成会对任何个人或组织造成侵害的内容,请尊重他人的著作权和知识产权。用户对此程序的任何使用行为与程序开发者无关。</center>")
384
  gr.HTML('''
 
304
 
305
  import shutil
306
 
307
+ # get a zip file
308
+
309
+ import zipfile
310
+
311
+ def zip_sliced_files(directory, zip_filename):
312
+ # Create a ZipFile object
313
+ with zipfile.ZipFile(zip_filename, 'w') as zipf:
314
+ # Iterate over all files in the directory
315
+ for foldername, subfolders, filenames in os.walk(directory):
316
+ for filename in filenames:
317
+ # Check if the file starts with "sliced" and has a .wav extension
318
+ if filename.startswith("sliced") and filename.endswith(".wav"):
319
+ # Create the complete file path
320
+ file_path = os.path.join(foldername, filename)
321
+ # Add the file to the zip file
322
+ zipf.write(file_path, arcname=filename)
323
+ print(f"Added {filename} to {zip_filename}")
324
+
325
+ # set speed
326
+
327
+ def change_speed(audio_inp, speed=1.0):
328
+ audio = AudioSegment.from_file(audio_inp)
329
+
330
+ sound_with_altered_frame_rate = audio._spawn(audio.raw_data, overrides={
331
+ "frame_rate": int(audio.frame_rate * speed)
332
+ })
333
+ slower_audio = sound_with_altered_frame_rate.set_frame_rate(audio.frame_rate)
334
+ slower_audio.export("slower_speech.wav", format="wav")
335
+ return "slower_speech.wav"
336
+
337
+
338
  def convert_from_srt(api_key, filename, audio_full, voice, multilingual):
339
 
340
  subtitle_list = read_srt(filename)
 
366
  except Exception:
367
  pass
368
  merge_audios("output")
369
+
370
+ zip_sliced_files("./", "参考音频.zip")
371
 
372
+ return "AI配音版.wav", "参考音频.zip"
373
 
374
  restart_markdown = ("""
375
  ### 若此页面无法正常显示,请点击[此链接](https://openxlab.org.cn/apps/detail/Kevin676/OpenAI-TTS)唤醒该程序!谢谢🍻
 
407
  inp3 = gr.Dropdown(choices=["Rachel", "Alice", "Chris", "Adam"], label='请选择一个说话人提供基础音色', info="试听音色链接:https://elevenlabs.io/app/speech-synthesis", value='Chris')
408
  #inp4 = gr.Dropdown(label="请选择用于分离伴奏的模型", info="UVR-HP5去除背景音乐效果更好,但会对人声造成一定的损伤", choices=["UVR-HP2", "UVR-HP5"], value="UVR-HP5")
409
  inp4 = gr.Checkbox(label="SRT文件是否为双语字幕", info="若为双语字幕,请打勾选择(SRT文件中需要先出现中文字幕,后英文字幕;中英字幕各占一行)")
410
+ btn1 = gr.Button("一键开启AI配音吧💕", variant="primary")
411
  with gr.Column():
412
  out1 = gr.Audio(label="为您生成的AI完整配音", type="filepath")
413
+ out2 = gr.File(label="包含所有参考音频的zip文件")
414
+ inp_speed = gr.Slider(label="设置AI配音的速度", minimum=0.8, maximum=1.2, value=1.0, step=0.01)
415
+ btn2 = gr.Button("一键改变AI配音速度")
416
+ out3 = gr.Audio(label="变速后的AI配音", type="filepath")
417
 
418
+ btn1.click(convert_from_srt, [inp0, inp1, inp2, inp3, inp4], [out1, out2])
419
+ btn2.click(change_speed, [out1, inp_speed], [out3])
420
 
421
  gr.Markdown("### <center>注意❗:请勿生成会对任何个人或组织造成侵害的内容,请尊重他人的著作权和知识产权。用户对此程序的任何使用行为与程序开发者无关。</center>")
422
  gr.HTML('''