File size: 881 Bytes
b05b5f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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/).")