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 # Using a more reliable and commonly used model for TTS tts_pipeline = pipeline("text-to-speech", model="microsoft/speecht5_tts") from datasets import load_dataset ds = load_dataset("Matthijs/cmu-arctic-xvectors") # Button to generate speech if st.button("Convert to Speech"): if text_input: # Generate the speech tts_output = tts_pipeline(text_input) # The output from the pipeline should be an array of speech chunks # Save the generated speech to a file audio_file_path = "output.wav" with open(audio_file_path, "wb") as f: f.write(tts_output[0]["array"]) # Display the audio player in Streamlit st.audio(audio_file_path) else: st.warning("Please enter some text to convert.") # Footer st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/).")