Spaces:
Sleeping
Sleeping
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() | |