File size: 1,072 Bytes
e9e16ef c045613 e9e16ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import streamlit as st
from transformers import pipeline
import soundfile as sf
import io
# Initialize TTS pipeline
@st.cache_resource
def get_tts_pipeline():
# Use a valid TTS model from Hugging Face
return pipeline("text-to-speech", model="microsoft/speecht5_tts")
tts = get_tts_pipeline()
# Streamlit app
st.title("Text-to-Speech (TTS) Application")
st.write("Convert text to speech using Hugging Face models!")
# Input text
input_text = st.text_area("Enter text below:", "Hello! Welcome to our TTS application.")
if st.button("Generate Speech"):
if input_text.strip():
# Generate speech
with st.spinner("Generating speech..."):
speech = tts(input_text)
# Convert numpy array to audio file
audio_data = io.BytesIO()
sf.write(audio_data, speech["audio"], samplerate=speech["sampling_rate"], format="wav")
audio_data.seek(0)
# Play audio
st.audio(audio_data, format="audio/wav")
else:
st.error("Please enter some text!")
st.markdown("**Created by [Your Name]**")
|