|
|
import streamlit as st |
|
|
from transformers import pipeline |
|
|
import soundfile as sf |
|
|
import io |
|
|
|
|
|
|
|
|
@st.cache_resource |
|
|
def get_tts_pipeline(): |
|
|
|
|
|
return pipeline("text-to-speech", model="microsoft/speecht5_tts") |
|
|
|
|
|
tts = get_tts_pipeline() |
|
|
|
|
|
|
|
|
st.title("Text-to-Speech (TTS) Application") |
|
|
st.write("Convert text to speech using Hugging Face models!") |
|
|
|
|
|
|
|
|
input_text = st.text_area("Enter text below:", "Hello! Welcome to our TTS application.") |
|
|
|
|
|
if st.button("Generate Speech"): |
|
|
if input_text.strip(): |
|
|
|
|
|
with st.spinner("Generating speech..."): |
|
|
speech = tts(input_text) |
|
|
|
|
|
|
|
|
audio_data = io.BytesIO() |
|
|
sf.write(audio_data, speech["audio"], samplerate=speech["sampling_rate"], format="wav") |
|
|
audio_data.seek(0) |
|
|
|
|
|
|
|
|
st.audio(audio_data, format="audio/wav") |
|
|
else: |
|
|
st.error("Please enter some text!") |
|
|
|
|
|
st.markdown("**Created by [Your Name]**") |
|
|
|