File size: 699 Bytes
31b3285
6094769
59f752a
e31a483
 
59f752a
6094769
 
 
 
 
 
59f752a
6094769
59f752a
6094769
 
 
 
 
 
 
59f752a
 
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
import streamlit as st
from transformers import pipeline

# Set up the text-to-speech pipeline with a compatible model
pipe = pipeline('text-to-speech', 'Xenova/speecht5_tts');

def text_to_speech(text):
    result = pipe(text)
    audio_path = 'output.wav'
    with open(audio_path, 'wb') as f:
        f.write(result['audio'])
    return audio_path

st.title("Text to Speech with Hugging Face Model")

text = st.text_area("Enter text to convert to speech:")

if st.button("Convert"):
    if text:
        audio_file = text_to_speech(text)
        audio_bytes = open(audio_file, 'rb').read()
        st.audio(audio_bytes, format='audio/wav')
    else:
        st.warning("Please enter some text.")