File size: 938 Bytes
e695abb
303db20
553fba6
 
cbee267
e695abb
303db20
dd250a3
 
 
 
 
303db20
 
dd250a3
303db20
 
 
 
 
553fba6
 
cbee267
 
 
e695abb
cbee267
553fba6
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
import gradio as gr
import requests
import urllib.request
from pydub import AudioSegment
import numpy as np

def function1(prompt):
    response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
      "data": [
        prompt,
    ]}).json()
    data = response["data"][0]
    response = requests.post("https://matthijs-speecht5-tts-demo.hf.space/run/predict", json={
        "data": [
            data,
            "KSP (male)",
        ]
    }).json()
    data = response["data"][0]["name"]
    data = "https://matthijs-speecht5-tts-demo.hf.space/file="+data
    file_name, headers = urllib.request.urlretrieve(data, "speech.wav")
    sound = AudioSegment.from_wav(file_name)
    sound.export("speech.mp3", format="mp3")
    audio_array = np.array(sound.get_array_of_samples())
    return audio_array

iface = gr.Interface(fn=function1, inputs="text", outputs=gr.Audio(label="Audio", type="numpy"))
iface.launch()