Aki004 commited on
Commit
55f7374
1 Parent(s): cddf4ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import streamlit as st
2
  import edge_tts
3
  import asyncio
4
  import librosa
@@ -24,24 +24,25 @@ def tts_get_voices_list():
24
 
25
  return voices
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  loop = asyncio.new_event_loop()
28
  asyncio.set_event_loop(loop)
29
 
30
- with st.form(key = 'tts', clear_on_submit=False):
31
- txt = st.text_input('your text message (your text message should be < 100 characters)', max_chars = 100)
32
- voice = str(st.selectbox('voices', tts_get_voices_list()))
33
- summitted = st.form_submit_button('Summit')
34
-
35
- if summitted:
36
- tts = asyncio.run(edge_tts.Communicate(txt, voice).save('temp\\test.mp3'))
37
- audio, sr = librosa.load('temp\\test.mp3', sr=16000, mono=True)
38
- raw_path = io.BytesIO()
39
- soundfile.write(raw_path, audio, 16000, format="wav")
40
- raw_path.seek(0)
41
- model = Svc(fr"Herta-Svc/G_10000.pth", f"Herta-Svc/config.json", device = 'cpu')
42
- out_audio, out_sr = model.infer('speaker0', 0, raw_path, auto_predict_f0 = True,)
43
- soundfile.write('temp\\xxx.wav', out_audio.cpu().numpy(), 44100)
44
- audio_file = open('temp\\xxx.wav', 'rb')
45
- audio_bytes = audio_file.read()
46
- st.audio(audio_bytes, format = 'audio/wav')
47
 
 
 
 
1
+ import gradio as gr
2
  import edge_tts
3
  import asyncio
4
  import librosa
 
24
 
25
  return voices
26
 
27
+ def tts_mode(txt, voice):
28
+ tts = asyncio.run(edge_tts.Communicate(txt, voice).save('temp\\test.mp3'))
29
+ audio, sr = librosa.load('temp\\test.mp3', sr=16000, mono=True)
30
+ raw_path = io.BytesIO()
31
+ soundfile.write(raw_path, audio, 16000, format="wav")
32
+ raw_path.seek(0)
33
+ model = Svc(fr"Herta-Svc/G_10000.pth", f"Herta-Svc/config.json", device = 'cpu')
34
+ out_audio, out_sr = model.infer('speaker0', 0, raw_path, auto_predict_f0 = True,)
35
+ soundfile.write('temp\\xxx.wav', out_audio.cpu().numpy(), 44100)
36
+ audio_file = open('temp\\xxx.wav', 'rb')
37
+ audio_bytes = audio_file.read()
38
+
39
+ return audio_bytes
40
+
41
  loop = asyncio.new_event_loop()
42
  asyncio.set_event_loop(loop)
43
 
44
+ txt = gr.Textbox(label = 'TTS text')
45
+ voice = gr.Dropdown(tts_get_voices_list(), value = str)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ if gr.Button():
48
+ tts_mode(txt, voice)