Spaces:
Sleeping
Sleeping
from transformers.utils import logging | |
logging.set_verbosity_error() | |
from transformers import pipeline | |
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 | |
# Save the audio data to a temporary file | |
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmpfile: | |
sf.write(tmpfile.name, audio_data, samplerate) | |
# Return the path of the temporary audio file | |
return tmpfile.name | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
return None | |
# Create the Gradio interface | |
iface = gr.Interface(fn=launch, inputs="text", outputs=gr.Audio()) | |
# Launch the Gradio app | |
iface.launch() |