Spaces:
Sleeping
Sleeping
import streamlit as st | |
import gradio as gr | |
from speechbrain.pretrained import Tacotron2, HIFIGAN | |
from scipy.io.wavfile import write | |
# Load TTS and vocoder models | |
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts") | |
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder") | |
# Function to generate speech from text | |
def text_to_speech(text): | |
mel_output, mel_length, alignment = tacotron2.encode_text(text) | |
waveforms, _, _ = hifi_gan.decode_batch(mel_output) | |
audio_path = "tts_output.wav" | |
write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy()) | |
return audio_path | |
# Gradio interface for TTS | |
def chatbot_response(text): | |
audio_path = text_to_speech(text) | |
return audio_path | |
gr_interface = gr.Interface(fn=chatbot_response, inputs="text", outputs="audio") | |
# Streamlit app setup | |
st.title("Text-to-Speech Chatbot") | |
st.write("This application converts text into speech using SpeechBrain.") | |
# Embed Gradio interface in Streamlit | |
with st.spinner("Loading Gradio interface..."): | |
gr_interface.launch(share=False, inbrowser=True) | |