File size: 1,030 Bytes
e66fc24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()