Spaces:
Running
Running
first version of the demo
Browse files
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title: Voice Filters API
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
+
title: Voicemod's Voice Filters API
|
3 |
+
emoji: 🧌
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
import requests
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
+
|
7 |
+
token = os.environ['apikey']
|
8 |
+
API_HOST = "https://api.voicemod.net"
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
def getPayload(index, audio_file):
|
14 |
+
new_name = audio_file.replace("-0-100.wav", ".m4a")
|
15 |
+
|
16 |
+
command = f"ffmpeg -y -f wav -i {audio_file} -f ipod {new_name}"
|
17 |
+
print("Executing command: " + command)
|
18 |
+
os.system(command)
|
19 |
+
|
20 |
+
voiceIds = [
|
21 |
+
"banana",
|
22 |
+
"bob",
|
23 |
+
"pilot",
|
24 |
+
"drone",
|
25 |
+
"evil",
|
26 |
+
"ogre",
|
27 |
+
"cave"
|
28 |
+
]
|
29 |
+
|
30 |
+
|
31 |
+
payload={'voiceId': voiceIds[index]}
|
32 |
+
files=[
|
33 |
+
('audioFile',('audio.m4a',open(new_name,'rb'),'application/octet-stream'))
|
34 |
+
]
|
35 |
+
|
36 |
+
|
37 |
+
return payload, files
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
def cleanUpLines(lines):
|
42 |
+
return list(filter(None, lines))
|
43 |
+
|
44 |
+
|
45 |
+
def greet(index, audio_file):
|
46 |
+
url = API_HOST + "/v1/cloud/audio?convertMp3=true"
|
47 |
+
|
48 |
+
|
49 |
+
print("URL: " + url)
|
50 |
+
print("Audio file path: ", audio_file)
|
51 |
+
|
52 |
+
payload, files = getPayload(index, audio_file)
|
53 |
+
|
54 |
+
headers = {
|
55 |
+
'x-api-key': token,
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
print(payload)
|
60 |
+
print("Before the call")
|
61 |
+
response = requests.request("POST", url, headers=headers, data=payload, files=files)
|
62 |
+
print("After the call...")
|
63 |
+
print(response.status_code)
|
64 |
+
print(response.text)
|
65 |
+
|
66 |
+
jsonResp = response.json()
|
67 |
+
print(jsonResp)
|
68 |
+
|
69 |
+
return gr.make_waveform(download_file(jsonResp['convertedFileUrl']))
|
70 |
+
|
71 |
+
|
72 |
+
def download_file(url):
|
73 |
+
response = requests.get(url)
|
74 |
+
if response.status_code == 200:
|
75 |
+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
76 |
+
tmp_file.write(response.content)
|
77 |
+
tmp_file.flush()
|
78 |
+
return tmp_file.name
|
79 |
+
else:
|
80 |
+
print("Error: Unable to download file")
|
81 |
+
|
82 |
+
|
83 |
+
with gr.Blocks() as demo:
|
84 |
+
|
85 |
+
gr.Markdown("""
|
86 |
+
## Voicemod's Speech-to-Speech API
|
87 |
+
|
88 |
+
**Try some of our voice filters on your own voice with this demo!**
|
89 |
+
|
90 |
+
To use the demo, follow the instructions:
|
91 |
+
|
92 |
+
1. First, select the voice you want from the dropdown
|
93 |
+
2. Then record yourself saying someting funny (or not)
|
94 |
+
3. ???
|
95 |
+
4. PROFIT! (or rather, play the resulting audio)
|
96 |
+
|
97 |
+
### Recommendation
|
98 |
+
For better results, make sure you leave a small amount of silence at the end of the recording (1 second or less is fine).
|
99 |
+
Also, a little bit of acting never hurts. Especially for the ones like **Evil**, results are a lot more fun when you do some acting while speaking :)
|
100 |
+
""")
|
101 |
+
|
102 |
+
voices = [
|
103 |
+
"Banana",
|
104 |
+
"Bob",
|
105 |
+
"Pilot",
|
106 |
+
"Drone",
|
107 |
+
"Evil",
|
108 |
+
"Ogre",
|
109 |
+
"Cave"
|
110 |
+
]
|
111 |
+
|
112 |
+
with gr.Row():
|
113 |
+
with gr.Column():
|
114 |
+
with gr.Row():
|
115 |
+
dd = gr.Dropdown(choices=voices, type="index", label="1. Select the voice...")
|
116 |
+
audioInput = gr.Audio(type="filepath",
|
117 |
+
label="2. Record yourself saying something...",
|
118 |
+
source="microphone",
|
119 |
+
)
|
120 |
+
|
121 |
+
with gr.Row():
|
122 |
+
btn = gr.Button("Run")
|
123 |
+
with gr.Column():
|
124 |
+
video = gr.Video(label="3. Play the generated audio")
|
125 |
+
video.style(height=300)
|
126 |
+
|
127 |
+
gr.Markdown("""
|
128 |
+
## Want to use this API for your project?
|
129 |
+
|
130 |
+
If you'd like to use this API for your own project, request access through our [form here](https://voicemod.typeform.com/to/KqeNN6bO)
|
131 |
+
""")
|
132 |
+
|
133 |
+
btn.click(fn=greet,
|
134 |
+
inputs=[
|
135 |
+
dd,
|
136 |
+
audioInput
|
137 |
+
],
|
138 |
+
outputs=video)
|
139 |
+
|
140 |
+
demo.launch()
|