Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import urllib.request
|
4 |
-
from pydub import AudioSegment
|
5 |
-
import numpy as np
|
6 |
import os
|
7 |
|
8 |
def function1(prompt):
|
@@ -10,27 +7,31 @@ def function1(prompt):
|
|
10 |
"data": [
|
11 |
prompt,
|
12 |
]}).json()
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
|
35 |
iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
|
36 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
def function1(prompt):
|
|
|
7 |
"data": [
|
8 |
prompt,
|
9 |
]}).json()
|
10 |
+
message = response["data"][0]
|
11 |
+
url = 'https://api.elevenlabs.io/v1/text-to-speech/pNInz6obpgDQGcFmaJgB'
|
12 |
+
|
13 |
+
headers = {
|
14 |
+
'accept': 'audio/mpeg',
|
15 |
+
'xi-api-key': os.enivron.get("test2"),
|
16 |
+
'Content-Type': 'application/json'
|
17 |
+
}
|
18 |
+
|
19 |
+
data = {
|
20 |
+
"text": message,
|
21 |
+
"voice_settings": {
|
22 |
+
"stability": 0,
|
23 |
+
"similarity_boost": 0
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
response = requests.post(url, headers=headers, json=data)
|
28 |
+
if response.status_code == 200:
|
29 |
+
file_path = 'test.mp3'
|
30 |
+
if os.path.isfile(file_path):
|
31 |
+
os.remove(file_path)
|
32 |
+
with open(file_path, 'wb') as f:
|
33 |
+
f.write(response.content)
|
34 |
+
return "test.mp3"
|
35 |
|
36 |
iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
|
37 |
iface.launch()
|