Text_to_Speech / app.py
hbui's picture
Update app.py
95e95ed verified
raw
history blame
957 Bytes
from transformers.utils import logging
logging.set_verbosity_error()
from transformers import pipeline
import gradio as gr
import os
import soundfile as sf
import numpy as np
import tempfile
def launch(input_text):
try:
# Assuming `narrator` function returns a numpy array with audio data and a sampling rate.
narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
out = narrator(input_text)
audio_data, samplerate = np.array(out["audio"][0]), 22050 # Example: 22050 Hz as common sampling rate
# Directly return the audio data and sampling rate.
return audio_data, samplerate
except Exception as e:
print(f"An error occurred: {e}")
return None, None
# Create the Gradio interface with the correct audio output handling.
iface = gr.Interface(fn=launch, inputs="text", outputs=gr.Audio(type="numpy", label="Your Audio"))
# Launch the Gradio app
iface.launch()