tommy24 commited on
Commit
5e9a4dd
·
1 Parent(s): 30c6e45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
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
- data = response["data"][0]
14
- response = requests.post("https://matthijs-speecht5-tts-demo.hf.space/run/predict", json={
15
- "data": [
16
- data,
17
- "KSP (male)",
18
- ]
19
- }).json()
20
- data = response["data"][0]["name"]
21
- data = "https://matthijs-speecht5-tts-demo.hf.space/file="+data
22
- file_name, headers = urllib.request.urlretrieve(data, "speech.mp3")
23
- # code = random.randint(1,1000)
24
- # generated_file = f"output{code}"
25
- filename = "output.mp3"
26
-
27
- if os.path.exists(filename):
28
- os.remove(filename)
29
- else:
30
- pass
31
- command = f"ffmpeg -i {file_name} -vn -ar 44100 -ac 2 -b:a 192k output.mp3"
32
- os.system(command)
33
- return "output.mp3"
 
 
 
 
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()