bgtts / app.py
englissi's picture
Update app.py
aa294bf verified
raw
history blame
961 Bytes
# Install transformers if not installed
# !pip install transformers gradio
from transformers import pipeline
import gradio as gr
# Install transformers and gradio if not installed
import os
os.system('pip install transformers gradio')
# Load a pre-trained TTS pipeline
tts_pipeline = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
# Function to convert text to audio using the Hugging Face TTS model
def text_to_audio(mytext):
audio = tts_pipeline(mytext) # Generate audio
return audio["filename"] # Return the filename of the generated audio
# Create a Gradio interface
iface = gr.Interface(
fn=text_to_audio,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs=gr.Audio(type="file"), # Gradio expects a file for audio output
title="Text to Speech Application",
description="Type your text and generate the corresponding audio."
)
# Launch the interface
iface.launch(share=True)