Spaces:
Running
Running
Create app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,19 @@ import streamlit as st
|
|
2 |
from speechbrain.pretrained import Tacotron2, HIFIGAN
|
3 |
from scipy.io.wavfile import write
|
4 |
|
5 |
-
# Load the TTS and
|
6 |
@st.cache_resource
|
7 |
def load_models():
|
8 |
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
|
9 |
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
|
10 |
return tacotron2, hifi_gan
|
11 |
|
|
|
|
|
12 |
tacotron2, hifi_gan = load_models()
|
|
|
13 |
|
14 |
-
#
|
15 |
def text_to_speech(text):
|
16 |
mel_output, mel_length, alignment = tacotron2.encode_text(text)
|
17 |
waveforms, _, _ = hifi_gan.decode_batch(mel_output)
|
@@ -19,11 +22,9 @@ def text_to_speech(text):
|
|
19 |
write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy())
|
20 |
return audio_path
|
21 |
|
22 |
-
# Streamlit
|
23 |
-
st.title("Text-to-Speech
|
24 |
-
|
25 |
-
# Input text box
|
26 |
-
text = st.text_input("Enter text to convert to speech:", "")
|
27 |
|
28 |
if st.button("Generate Speech"):
|
29 |
if text.strip():
|
@@ -32,5 +33,3 @@ if st.button("Generate Speech"):
|
|
32 |
st.audio(audio_file, format="audio/wav")
|
33 |
else:
|
34 |
st.warning("Please enter some text.")
|
35 |
-
|
36 |
-
st.write("Powered by SpeechBrain and Streamlit.")
|
|
|
2 |
from speechbrain.pretrained import Tacotron2, HIFIGAN
|
3 |
from scipy.io.wavfile import write
|
4 |
|
5 |
+
# Load the TTS and vocoder models
|
6 |
@st.cache_resource
|
7 |
def load_models():
|
8 |
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
|
9 |
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
|
10 |
return tacotron2, hifi_gan
|
11 |
|
12 |
+
# Load models
|
13 |
+
st.write("Loading models... Please wait ⏳")
|
14 |
tacotron2, hifi_gan = load_models()
|
15 |
+
st.success("Models loaded successfully!")
|
16 |
|
17 |
+
# TTS function
|
18 |
def text_to_speech(text):
|
19 |
mel_output, mel_length, alignment = tacotron2.encode_text(text)
|
20 |
waveforms, _, _ = hifi_gan.decode_batch(mel_output)
|
|
|
22 |
write(audio_path, 22050, waveforms.squeeze(1).cpu().numpy())
|
23 |
return audio_path
|
24 |
|
25 |
+
# Streamlit UI
|
26 |
+
st.title("🗣️ Text-to-Speech App")
|
27 |
+
text = st.text_input("Enter text to convert to speech:")
|
|
|
|
|
28 |
|
29 |
if st.button("Generate Speech"):
|
30 |
if text.strip():
|
|
|
33 |
st.audio(audio_file, format="audio/wav")
|
34 |
else:
|
35 |
st.warning("Please enter some text.")
|
|
|
|