File size: 957 Bytes
e66fc24
 
 
 
 
 
4d6559b
 
 
e66fc24
 
 
 
 
 
 
 
 
 
 
95e95ed
 
e66fc24
 
95e95ed
e66fc24
95e95ed
 
e66fc24
 
95e95ed
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
26
27
28
29
30
31
32
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()