Spaces:
Runtime error
Runtime error
adding code
Browse files
README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title: Text To Sing
|
| 3 |
emoji: 🏃
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.34.0
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Voicemod's Text To Sing
|
| 3 |
emoji: 🏃
|
| 4 |
+
colorFrom: black
|
| 5 |
+
colorTo: cyan
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.34.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
import requests
|
| 4 |
+
import time
|
| 5 |
+
import tempfile
|
| 6 |
+
|
| 7 |
+
token = "XQMy5NHKujX8nXr8YCGktED3f7DEdvzm"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def separate_syllables(string):
|
| 12 |
+
#numbers = [ 4, 4, 8, 5 ]
|
| 13 |
+
numbers = [ 8, 9, 8, 9 ]
|
| 14 |
+
# Split the string into a list of characters
|
| 15 |
+
parts = string.split(" ")
|
| 16 |
+
string = "".join(parts)
|
| 17 |
+
print("the new string: "+ string)
|
| 18 |
+
chars = list(string)
|
| 19 |
+
|
| 20 |
+
# Create a list to store the syllables
|
| 21 |
+
syllables = []
|
| 22 |
+
|
| 23 |
+
# Iterate over the numbers
|
| 24 |
+
for num in numbers:
|
| 25 |
+
# Get the next num characters from the string
|
| 26 |
+
syllable = "".join(chars[:num])
|
| 27 |
+
print("Appending " + "".join(chars[:num]))
|
| 28 |
+
# Add the syllable to the list
|
| 29 |
+
syllables.append(syllable)
|
| 30 |
+
# Remove the syllable from the list of characters
|
| 31 |
+
chars = chars[num:]
|
| 32 |
+
|
| 33 |
+
# If there are any remaining characters, add them as a new line
|
| 34 |
+
if chars:
|
| 35 |
+
syllables.append("-")
|
| 36 |
+
for num in numbers:
|
| 37 |
+
# Get the next num characters from the remaining characters
|
| 38 |
+
syllable = "".join(chars[:num])
|
| 39 |
+
# Add the syllable to the list
|
| 40 |
+
syllables.append(syllable)
|
| 41 |
+
# Remove the syllable from the list of characters
|
| 42 |
+
chars = chars[num:]
|
| 43 |
+
|
| 44 |
+
# Return the list of syllables joined by spaces
|
| 45 |
+
if("-" in syllables):
|
| 46 |
+
results = [[]]
|
| 47 |
+
lines = 0
|
| 48 |
+
for i ,v in enumerate(syllables):
|
| 49 |
+
if v == '-':
|
| 50 |
+
lines=lines+1
|
| 51 |
+
else:
|
| 52 |
+
if(len(results) == 1):
|
| 53 |
+
results.append([])
|
| 54 |
+
results[lines].append(v)
|
| 55 |
+
|
| 56 |
+
return list(map(lambda words: " ".join(words), results))
|
| 57 |
+
else:
|
| 58 |
+
return " ".join(syllables)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def flattenLines(lyrics):
|
| 62 |
+
newValues = []
|
| 63 |
+
for i,val in enumerate(lyrics):
|
| 64 |
+
if(type(lyrics[i]) == list):
|
| 65 |
+
newValues.append(lyrics[i][0])
|
| 66 |
+
newValues.append(lyrics[i][1])
|
| 67 |
+
else:
|
| 68 |
+
newValues.append(lyrics[i])
|
| 69 |
+
|
| 70 |
+
return newValues
|
| 71 |
+
|
| 72 |
+
def getPayload(index):
|
| 73 |
+
match index:
|
| 74 |
+
case 0:
|
| 75 |
+
return {
|
| 76 |
+
"voiceModel":"CFV_2",
|
| 77 |
+
"voiceModelStyle":"mezzo",
|
| 78 |
+
"language":"en",
|
| 79 |
+
"scoreFileRemotePath":"themes/DeckTheHalls/score/TTS_XMAS_DeckTheHalls_Melody_C_200bpm_4x4_ABCD.json",
|
| 80 |
+
"scoreDataFileRemotePath":"themes/DeckTheHalls/score/TTS_XMAS_DeckTheHalls_Score_Data_ABCD.json",
|
| 81 |
+
"dspFileRemotePath":"themes/DeckTheHalls/dsp/XML/TTS_XMAS_DeckTheHalls_DSP_C_200bpm_ABCD.xml",
|
| 82 |
+
"dspEffect":"",
|
| 83 |
+
"lyrics": [],
|
| 84 |
+
"backgroundSounds":False,
|
| 85 |
+
"artistName":"Cecilia",
|
| 86 |
+
"songName":"Deck The Halls",
|
| 87 |
+
"singerImageRemotePath":"singers/Singer-Cecilia-VideoImageBackground.png",
|
| 88 |
+
"backgroundImageRemotePath":"themes/DeckTheHalls/images/Song-DeckTheHalls-VideoImageBackground02.png"
|
| 89 |
+
}
|
| 90 |
+
case 1:
|
| 91 |
+
return {
|
| 92 |
+
"voiceModel":"CFV_2",
|
| 93 |
+
"voiceModelStyle":"mezzo",
|
| 94 |
+
"language":"en",
|
| 95 |
+
"scoreDataFileRemotePath": "themes/MoveYourBody/score/MoveYourBody_Score_Data_ABCD.json",
|
| 96 |
+
"scoreFileRemotePath": "themes/MoveYourBody/score/MoveYourBody_Melody_ABCD.json",
|
| 97 |
+
"singerImageRemotePath": "singers/Singer-Cecilia-VideoImageBackground.png",
|
| 98 |
+
"dspFileRemotePath": "themes/MoveYourBody/dsp/XML/MoveYourBody_DSP_ABCD.xml",
|
| 99 |
+
"dspEffect":"",
|
| 100 |
+
"lyrics": [],
|
| 101 |
+
"backgroundSounds":False,
|
| 102 |
+
"artistName":"Cecilia",
|
| 103 |
+
"songName":"Move Your Body",
|
| 104 |
+
"backgroundImageRemotePath":"themes/DeckTheHalls/images/Song-DeckTheHalls-VideoImageBackground02.png"
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
case 2:
|
| 108 |
+
return {
|
| 109 |
+
"voiceModel": "Randy_v3o",
|
| 110 |
+
"voiceModelStyle": "randy",
|
| 111 |
+
"language": "en",
|
| 112 |
+
"scoreFileRemotePath": "themes/DarkTrap/score/DarkTrap_Melody_ABCDEFGH.json", #"themes/DeckTheHalls/score/TTS_XMAS_DeckTheHalls_Melody_C_200bpm_4x4_ABCD.json",
|
| 113 |
+
"scoreDataFileRemotePath": "themes/DarkTrap/score/DarkTrap_Score_Data_ABCDEFGH.json", #"themes/DeckTheHalls/score/TTS_XMAS_DeckTheHalls_Score_Data_ABCD.json",
|
| 114 |
+
"dspFileRemotePath": "themes/DarkTrap/dsp/XML/DarkTrap_DSP_ABCDEFGH.xml", #"themes/DeckTheHalls/dsp/XML/TTS_XMAS_DeckTheHalls_DSP_C_200bpm_ABCD.xml",
|
| 115 |
+
"dspEffect": "",
|
| 116 |
+
"lyrics": [],
|
| 117 |
+
"backgroundSounds": False,
|
| 118 |
+
"artistName": "Jerry",
|
| 119 |
+
"songName": "Dark Trap", #"Deck The Halls",
|
| 120 |
+
"singerImageRemotePath": "singers/Singer-Jerry-VideoImageBackground.png",
|
| 121 |
+
"backgroundImageRemotePath": "themes/DeckTheHalls/images/Song-DeckTheHalls-VideoImageBackground01.png"
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
case 3:
|
| 125 |
+
return {
|
| 126 |
+
"artistName": "Jerry",
|
| 127 |
+
"backgroundImageRemotePath": "themes/HappyBirthday/images/Song-HappyBirthday-VideoImageBackground01.png",
|
| 128 |
+
"backgroundSounds": False,
|
| 129 |
+
"dspEffect": "",
|
| 130 |
+
"dspFileRemotePath": "themes/HappyBirthday/dsp/XML/HappyBirthday_DSP_ABCD.xml",
|
| 131 |
+
"language": "en",
|
| 132 |
+
"lyrics": [],
|
| 133 |
+
"scoreDataFileRemotePath": "themes/HappyBirthday/score/HappyBirthday_Score_Data_ABCD.json",
|
| 134 |
+
"scoreFileRemotePath": "themes/HappyBirthday/score/HappyBirthday_Melody_ABCD.json",
|
| 135 |
+
"singerImageRemotePath": "singers/Singer-Jerry-VideoImageBackground.png",
|
| 136 |
+
"songName": "Happy Birthday",
|
| 137 |
+
"voiceModel": "CFV_2",
|
| 138 |
+
"voiceModelStyle": "baritone"
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
case 4:
|
| 142 |
+
return {
|
| 143 |
+
"voiceModel": "Randy_v3o",
|
| 144 |
+
"voiceModelStyle": "randy",
|
| 145 |
+
"language": "en",
|
| 146 |
+
"scoreFileRemotePath": "themes/Levitate/score/Levitate_Melody_ABCD.json", #"themes/DeckTheHalls/score/TTS_XMAS_DeckTheHalls_Melody_C_200bpm_4x4_ABCD.json",
|
| 147 |
+
"scoreDataFileRemotePath": "themes/Levitate/score/Levitate_Score_Data_ABCD.json", #"themes/DeckTheHalls/score/TTS_XMAS_DeckTheHalls_Score_Data_ABCD.json",
|
| 148 |
+
"dspFileRemotePath": "themes/Levitate/dsp/XML/Levitate_DSP_ABCD.xml", #"themes/DeckTheHalls/dsp/XML/TTS_XMAS_DeckTheHalls_DSP_C_200bpm_ABCD.xml",
|
| 149 |
+
"dspEffect": "",
|
| 150 |
+
"lyrics": [],
|
| 151 |
+
"backgroundSounds": False,
|
| 152 |
+
"artistName": "Jerry",
|
| 153 |
+
"songName": "Levitate", #"Deck The Halls",
|
| 154 |
+
"singerImageRemotePath": "singers/Singer-Ed-VideoImageBackground.png",
|
| 155 |
+
"backgroundImageRemotePath": "themes/Levitate/images/Song-Levitate-VideoImageBackground02.png"
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def greet(index, lyrics):
|
| 161 |
+
url = "https://staging-gateway-api.voicemod.net/v2/cloud/partners/ttsing"
|
| 162 |
+
verification_url = "https://staging-gateway-api.voicemod.net/v2/cloud/partners/ttsing/"
|
| 163 |
+
|
| 164 |
+
print("Calling api with "+ lyrics)
|
| 165 |
+
|
| 166 |
+
lines = lyrics.split("\n")
|
| 167 |
+
#newLines = flattenLines(list(map(separate_syllables, lines)))
|
| 168 |
+
|
| 169 |
+
payload = getPayload(index)
|
| 170 |
+
payload["lyrics"] = lines
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
headers = {
|
| 174 |
+
'x-api-key': token
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
print(payload)
|
| 179 |
+
print("Before the call")
|
| 180 |
+
response = requests.request("POST", url, headers=headers, json=payload)
|
| 181 |
+
print("After the call...")
|
| 182 |
+
jsonResp = response.json()
|
| 183 |
+
print(response.text)
|
| 184 |
+
jobID = jsonResp['jobId']
|
| 185 |
+
verification_url += jsonResp['jobId']
|
| 186 |
+
while(True):
|
| 187 |
+
response = requests.request('GET', verification_url, headers=headers)
|
| 188 |
+
print(response.text)
|
| 189 |
+
print(jobID)
|
| 190 |
+
jsonResp = response.json()
|
| 191 |
+
if(jsonResp['status'] == 'failed'):
|
| 192 |
+
return ""
|
| 193 |
+
|
| 194 |
+
if('transformedAudioUrl' in jsonResp and jsonResp['transformedAudioUrl'] is not None):
|
| 195 |
+
return gr.make_waveform(download_file(jsonResp['transformedAudioUrl']))
|
| 196 |
+
#return download_file(jsonResp['urlVideoWithBackground'])
|
| 197 |
+
print("Still processing...")
|
| 198 |
+
time.sleep(1)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def download_file(url):
|
| 204 |
+
response = requests.get(url)
|
| 205 |
+
if response.status_code == 200:
|
| 206 |
+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
| 207 |
+
tmp_file.write(response.content)
|
| 208 |
+
tmp_file.flush()
|
| 209 |
+
return tmp_file.name
|
| 210 |
+
else:
|
| 211 |
+
print("Error: Unable to download file")
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
with gr.Blocks() as demo:
|
| 215 |
+
#def handleChange():
|
| 216 |
+
# line3.update(visible=False)
|
| 217 |
+
|
| 218 |
+
gr.Markdown("""
|
| 219 |
+
## Voicemod's Text-to-Song API
|
| 220 |
+
To use this API follow the instructions:
|
| 221 |
+
1. First, select the melody you want from the dropdown
|
| 222 |
+
2. Then write the lyrics for it
|
| 223 |
+
|
| 224 |
+
### Disclaimer
|
| 225 |
+
Each melody has specific requirements for the lyrics (number of notes per verse and duration of each note).
|
| 226 |
+
Use the examples provided to understand how they work and write valid lyrics to get best results
|
| 227 |
+
|
| 228 |
+
Also, the length of the song is fixed, if you go over the line numbers the extra lyrics will be ignored.
|
| 229 |
+
""")
|
| 230 |
+
|
| 231 |
+
music_options = ["Deck the Halls by Cecilia",
|
| 232 |
+
"Move your Body by Cecilia",
|
| 233 |
+
"Dark Trap by Jerry",
|
| 234 |
+
"Happy Birthday by Jerry",
|
| 235 |
+
"Levitate by Ed"]
|
| 236 |
+
|
| 237 |
+
with gr.Row():
|
| 238 |
+
with gr.Column():
|
| 239 |
+
with gr.Row():
|
| 240 |
+
dd = gr.Dropdown(choices=music_options, type="index", label="Select the melody...")
|
| 241 |
+
lines = gr.Textbox(lines=10, placeholder="Write your lyrics here...", label="Lyrics")
|
| 242 |
+
|
| 243 |
+
with gr.Row():
|
| 244 |
+
btn = gr.Button("Run")
|
| 245 |
+
with gr.Column():
|
| 246 |
+
video = gr.Video(label="Generated output")
|
| 247 |
+
video.style(height=300)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
gr.Markdown("""
|
| 252 |
+
## Example lyrics
|
| 253 |
+
|
| 254 |
+
To make your life easier, while testing the API, you can use and modify the following lyrics for each song:
|
| 255 |
+
""")
|
| 256 |
+
with gr.Row():
|
| 257 |
+
with gr.Column():
|
| 258 |
+
gr.Markdown("""
|
| 259 |
+
### Dark Trap by Jerry
|
| 260 |
+
|
| 261 |
+
> this is just a test
|
| 262 |
+
> don't worry about what I say
|
| 263 |
+
> the lyrics want to go crazy
|
| 264 |
+
> when pushed too hard
|
| 265 |
+
> take it easy and relax
|
| 266 |
+
> this is moving too fast
|
| 267 |
+
> I can help you be
|
| 268 |
+
> a better singer
|
| 269 |
+
""")
|
| 270 |
+
with gr.Column():
|
| 271 |
+
gr.Markdown("""
|
| 272 |
+
### Happy Birthday by Jerry
|
| 273 |
+
|
| 274 |
+
> happy birthday to you
|
| 275 |
+
> happy birthday to you!
|
| 276 |
+
> happy birthday dear Laura
|
| 277 |
+
> happy birthday to you!
|
| 278 |
+
""")
|
| 279 |
+
with gr.Column():
|
| 280 |
+
gr.Markdown("""
|
| 281 |
+
### Deck the Halls by Cecilia
|
| 282 |
+
|
| 283 |
+
> Deck the halls with boughs of holly
|
| 284 |
+
> Fa la la la la, la la la la
|
| 285 |
+
> 'Tis the season to be jolly
|
| 286 |
+
> Fa la la la la, la la la la
|
| 287 |
+
|
| 288 |
+
""")
|
| 289 |
+
with gr.Column():
|
| 290 |
+
gr.Markdown("""
|
| 291 |
+
### Levitate by Ed
|
| 292 |
+
|
| 293 |
+
> this is just a test
|
| 294 |
+
> don’t worry about what I say
|
| 295 |
+
> the lyrics want to go crazy
|
| 296 |
+
> when pushed too hard
|
| 297 |
+
""")
|
| 298 |
+
with gr.Column():
|
| 299 |
+
gr.Markdown("""
|
| 300 |
+
### Move Your Body by Cecilia
|
| 301 |
+
|
| 302 |
+
> this is just a test
|
| 303 |
+
> don’t worry now
|
| 304 |
+
> the lyrics will come the less you think about them
|
| 305 |
+
> just feel the melody
|
| 306 |
+
""")
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
gr.Markdown("""
|
| 311 |
+
## Want to use this API for your project?
|
| 312 |
+
|
| 313 |
+
If you'd like to use this API for your own project, request access through our [form here](https://voicemod.typeform.com/to/KqeNN6bO?typeform-source=huggingface)
|
| 314 |
+
""")
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
btn.click(fn=greet,
|
| 318 |
+
inputs=[
|
| 319 |
+
dd,
|
| 320 |
+
lines
|
| 321 |
+
],
|
| 322 |
+
outputs=video)
|
| 323 |
+
|
| 324 |
+
demo.launch()
|