Skip to main content

Riffusion API

Project description

🎸 Riffusion API

This repo contains examples for creating music with the Riffusion API, either vai

[!NOTE]
This API is in a private beta and subject to change. Contact api@riffusion.com for questions.

To use the API, first set your API key:

export RIFFUSION_API_KEY="<your-api-key>"

/topic

Run via request (pip install requests):

import base64
import os
import requests

response = requests.post(
    "https://backend.riffusion.com/v1/topic",
    headers={
        "Content-Type": "application/json",
        "Api-Key": os.environ.get("RIFFUSION_API_KEY"),
    },
    json={
        "topic": "Indie pop banger about my dog Boris",
    },
).json()

with open("output.wav", "wb") as f:
    f.write(base64.b64decode(response["audio_b64"]))

Listen: output.wav

Run via Python client (pip install .):

import riff_api

response = riff_api.generate_from_topic(
    "Indie pop banger about my dog Boris"
)
riff_api.save_audio(response, "boris.wav")

Run via curl:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Api-Key: ${RIFFUSION_API_KEY}" \
  -d '{"topic": "Indie pop banger about my dog Boris"}' \
  https://backend.riffusion.com/v1/topic \
  | jq -r .audio_b64 | base64 -d > output.wav

The file datatypes.py shows the schema of the API.

/riff

Run via request:

import base64
import os
import requests

response = requests.post(
    'https://backend.riffusion.com/v1/riff',
    headers={
        'Content-Type': 'application/json',
        'Api-Key': os.environ.get("RIFFUSION_API_KEY"),
    },
    json={
        'prompts': [
            { "text": "chillstep pop" },
        ],
        'lyrics': (
            "Hello from outer space\n"
            "Can you hear me?\n"
            "I'm a satellite\n"
            "And I want to be by your side"
        ),
    },
).json()

with open("output.wav", "wb") as f:
    f.write(base64.b64decode(response["audio_b64"]))

Run via Python client:

import riff_api

lyrics = """
Hello from outer space
Can you hear me?
I'm a satellite
And I want to be by your side
""".strip()

response = riff_api.generate(
    prompts=[
        Prompt(text="chillstep pop"),
    ],
    lyrics=lyrics,
)

riff_api.save_audio(response.audio_b64, "output.wav")

Examples

The examples directory explains use cases of the API. To run, first pip install . then execute with Python 3.

Streamlit Demo

demo_app.py is a basic web app that demonstrates using the api to create musical transitions using two sound prompts with time ranges.

Try it: https://riffusion-api-demo.streamlit.app/

Or run locally:

pip install streamlit
python -m streamlit run demo_app.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

riff_api-0.1.0.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

riff_api-0.1.0-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page