Custom Beats
In addition to creating raps with the beats provided by Uberduck, you can upload your own beats to your account and use them in our rap generator through both the Uberduck website and the rap generation API.
Adding custom beats through the website
To add a custom beat through the website, go to the Rap Generator and click the Add Beat button.
Adding custom beats via the API
If you have many beats which you would like to add at once, you can add them in bulk via the API.
Here is an example script which adds all the beats in a given directory. You will need to adapt this script based on the layout of your audio files and track metadata such as BPM and genre.
import os
import re
from urllib import parse
import click
import requests
url = "https://api.uberduck.ai"
@click.command()
@click.option("--key", prompt=True)
@click.option("--secret", prompt=True)
@click.option("--dir")
def run(key: str, secret: str, dir: str):
ls_output = os.listdir(dir)
for filename in ls_output:
genres = {
"Tropical": "tropical",
"RnB": "r&b",
"Synthpop": "pop",
}
genre = genres[filename.split(" ")[0]]
# Filenames look like this: 'RnB 2 (95 bpm G Major).wav'
bpm = int(re.search(r"\((\d+)\s?bpm", filename).group(1))
seconds_per_beat = 60 / bpm
verses = [
{
"label": "Verse 1",
"length_in_measures": 8,
# 4 bars from the beginning, in seconds.
"start": round(seconds_per_beat * 4 * 4, 4),
},
{
"label": "Verse 2",
"length_in_measures": 8,
# 16 bars from the beginning, in seconds.
"start": round(seconds_per_beat * 4 * 16, 4),
},
]
response = requests.get(
f"{url}/reference-audio/upload-url",
auth=(key, secret),
params={"filename": filename, "content_type": "audio/wav"},
)
assert response.status_code == 200
print(response.json())
get_url = response.json()["get_url"]
put_url = response.json()["put_url"]
local_path = os.path.join(dir, filename)
with open(local_path, "rb") as f:
response = requests.put(
put_url,
data=f,
headers={"Content-Type": "audio/wav"},
)
assert response.status_code == 200
response = requests.post(
f"{url}/reference-audio/compress",
auth=(key, secret),
json={
"url": get_url,
},
)
assert response.status_code == 200
result = response.json()
compressed_path = result["path"]
response = requests.post(
f"{url}/reference-audio/backing-tracks",
auth=(key, secret),
json={
"name": filename,
"upload_path": parse.unquote(parse.urlparse(get_url).path[1:]),
"compressed_path": compressed_path,
"verses": verses,
# One of tropical, r&b, pop.
"genre": genre,
"bpm": bpm,
},
)
assert response.status_code == 200, response.text
if __name__ == "__main__":
run()
Using custom beats via the API
Once you have added your custom beats (either via the API or through the
website), the beats will appear in the List Backing
Tracks endpoint. Retrieve the custom beat UUID
from this endpoint, then pass it to the Generate
Rap endpoint as the backing_track
parameter.