Musawir19 commited on
Commit
e09371c
·
verified ·
1 Parent(s): 010d4bf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -1,13 +1,12 @@
1
- import streamlit as st
2
- import gradio as gr
3
  from speechbrain.pretrained import Tacotron2, HIFIGAN
4
  from scipy.io.wavfile import write
 
5
 
6
  # Load TTS and vocoder models
7
  tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
8
  hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
9
 
10
- # Function to generate speech from text
11
  def text_to_speech(text):
12
  mel_output, mel_length, alignment = tacotron2.encode_text(text)
13
  waveforms, _, _ = hifi_gan.decode_batch(mel_output)
@@ -15,17 +14,8 @@ def text_to_speech(text):
15
  write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy())
16
  return audio_path
17
 
18
- # Gradio interface for TTS
19
  def chatbot_response(text):
20
- audio_path = text_to_speech(text)
21
- return audio_path
22
-
23
- gr_interface = gr.Interface(fn=chatbot_response, inputs="text", outputs="audio")
24
-
25
- # Streamlit app setup
26
- st.title("Text-to-Speech Chatbot")
27
- st.write("This application converts text into speech using SpeechBrain.")
28
 
29
- # Embed Gradio interface in Streamlit
30
- with st.spinner("Loading Gradio interface..."):
31
- gr_interface.launch(share=False, inbrowser=True)
 
 
 
1
  from speechbrain.pretrained import Tacotron2, HIFIGAN
2
  from scipy.io.wavfile import write
3
+ import gradio as gr
4
 
5
  # Load TTS and vocoder models
6
  tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
7
  hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
8
 
9
+ # TTS function
10
  def text_to_speech(text):
11
  mel_output, mel_length, alignment = tacotron2.encode_text(text)
12
  waveforms, _, _ = hifi_gan.decode_batch(mel_output)
 
14
  write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy())
15
  return audio_path
16
 
17
+ # Gradio interface
18
  def chatbot_response(text):
19
+ return text_to_speech(text)
 
 
 
 
 
 
 
20
 
21
+ gr.Interface(fn=chatbot_response, inputs="text", outputs="audio").launch()