texttospeech / app.py
Ahsan658's picture
Create app.py
b05b5f6 verified
raw
history blame
881 Bytes
import streamlit as st
from transformers import pipeline
# Streamlit app title
st.title("Text to Speech Converter")
# User input for text to convert to speech
text_input = st.text_area("Enter text to convert to speech:")
# Load the Hugging Face TTS model
tts_pipeline = pipeline("text-to-speech", model="espnet/kan-bayashi-ljspeech-vits")
# Button to generate speech
if st.button("Convert to Speech"):
if text_input:
# Generate the speech
tts_output = tts_pipeline(text_input)
# Save the generated speech to a file
with open("output.wav", "wb") as f:
f.write(tts_output["wav"])
# Display the audio player in Streamlit
st.audio("output.wav")
else:
st.warning("Please enter some text to convert.")
# Footer
st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/).")