Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
import outetts
|
| 4 |
+
from scipy.io.wavfile import write
|
| 5 |
+
|
| 6 |
+
def generate_speech(text, model_config):
|
| 7 |
+
model = outetts.TTSModel(model_config)
|
| 8 |
+
model.eval()
|
| 9 |
+
|
| 10 |
+
with torch.no_grad():
|
| 11 |
+
audio, sample_rate = model.infer(text)
|
| 12 |
+
|
| 13 |
+
return audio, sample_rate
|
| 14 |
+
|
| 15 |
+
# Streamlit UI
|
| 16 |
+
st.title("OuteTTS Speech Synthesis")
|
| 17 |
+
st.write("Enter text below to generate speech.")
|
| 18 |
+
|
| 19 |
+
text_input = st.text_area("Text to convert to speech:", "Hello, this is an AI-generated voice.")
|
| 20 |
+
|
| 21 |
+
if st.button("Generate Speech"):
|
| 22 |
+
with st.spinner("Generating audio..."):
|
| 23 |
+
model_config = outetts.HFModelConfig_v1(
|
| 24 |
+
model_path="OuteAI/OuteTTS-0.2-500M",
|
| 25 |
+
language="en"
|
| 26 |
+
)
|
| 27 |
+
audio, sample_rate = generate_speech(text_input, model_config)
|
| 28 |
+
output_path = "output.wav"
|
| 29 |
+
write(output_path, sample_rate, audio)
|
| 30 |
+
|
| 31 |
+
st.audio(output_path, format="audio/wav")
|
| 32 |
+
st.success("Speech generated successfully!")
|