audio / app.py
pm6six's picture
Update app.py
569b020 verified
raw
history blame
923 Bytes
import streamlit as st
from transformers import pipeline
# Initialize text-to-speech model (small lightweight model)
tts_model = pipeline("text-to-speech", model="espnet/kan-bayashi_ljspeech_vits")
# Streamlit app UI
st.title("Text-to-Audio App")
st.text("This app generates audio from text input using Hugging Face models.")
# User input
text_input = st.text_area("Enter some text for the model:")
if st.button("Generate Audio"):
if not text_input.strip():
st.error("Please enter some text!")
else:
# Generate response
st.text("Generating audio response...")
tts_audio = tts_model(text_input)
# Save the audio output
audio_file = "response.wav"
with open(audio_file, "wb") as f:
f.write(tts_audio["wav"])
# Display audio response
st.audio(audio_file, format="audio/wav")
st.success("Audio generated successfully!")