tommy24 commited on
Commit
ce74a88
·
1 Parent(s): 3710b38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -25
app.py CHANGED
@@ -1,5 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import requests
 
 
 
3
  import os
4
 
5
  def function1(prompt):
@@ -7,31 +49,27 @@ 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.environ.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()
 
1
+ # import gradio as gr
2
+ # import requests
3
+ # import os
4
+
5
+ # def function1(prompt):
6
+ # response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
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.environ.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()
38
+
39
+
40
  import gradio as gr
41
  import requests
42
+ import urllib.request
43
+ from pydub import AudioSegment
44
+ import numpy as np
45
  import os
46
 
47
  def function1(prompt):
 
49
  "data": [
50
  prompt,
51
  ]}).json()
52
+ data = response["data"][0]
53
+ response = requests.post("https://matthijs-speecht5-tts-demo.hf.space/run/predict", json={
54
+ "data": [
55
+ data,
56
+ "KSP (male)",
57
+ ]
58
+ }).json()
59
+ data = response["data"][0]["name"]
60
+ data = "https://matthijs-speecht5-tts-demo.hf.space/file="+data
61
+ file_name, headers = urllib.request.urlretrieve(data, "speech.mp3")
62
+ # code = random.randint(1,1000)
63
+ # generated_file = f"output{code}"
64
+ filename = "output.mp3"
65
+
66
+ if os.path.exists(filename):
67
+ os.remove(filename)
68
+ else:
69
+ pass
70
+ command = f"ffmpeg -i {file_name} -vn -ar 44100 -ac 2 -b:a 192k output.mp3"
71
+ os.system(command)
72
+ return "output.mp3"
 
 
 
 
73
 
74
  iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
75
  iface.launch()