Skip to main content

Riffusion API

Project description

Riffusion API

Banner

This repo contains code for crafting music using Riffusion's foundational music models via API. You can either use the typed Python client in this library or make requests directly.

Please note that this API is in a private beta and subject to change. Contact api@riffusion.com for inquiries and access.

Getting Started

Set your API key:

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

Install the Python client:

pip install riff-api

Make some music:

import riff_api

riff_api.create_from_topic(
    "Indie pop banger about my dog Boris",
    save_to="output.wav",
)

This will generate lyrics and music for a 30s song. Run multiple times to create variations.

Sample: output.wav

Have fun 💙

/topic Endpoint

This endpoint creates a song from a single natural language description the desired lyrical content and/or musical style. It's the simplest way to create.

The API will generate lyrics based on your topic, as well as pick specific sound prompts. If you don't describe a musical style in your prompt, the API will choose randomly for you each time you call.

Get creative with your topics! Here are a few ideas:

  • "Rap fun facts about Alaska's history"
  • "Explain the concept of time in French"
  • "My nephew Remi is a superhero with laser eyes. Make him a theme song with a rock orchestra"

Run via Python client, saving the audio (decoded from base64) and printing the generated lyrics:

import riff_api

response = riff_api.create_from_topic(
    "Rap fun facts about Alaskan history",
    save_to="output.wav",
)
print(response.lyrics)

Alternatively, execute a request directly instead of using the Python client:

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": "Rap fun facts about Alaskan history",
    },
).json()

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

Or via curl:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Api-Key: ${RIFFUSION_API_KEY}" \
  -d '{"topic": "Rap fun facts about Alaskan history"}' \
  https://backend.riffusion.com/v1/topic \
  | jq -r .audio_b64 | base64 -d > output.wav

Examples

Check out examples/topic for runnable scripts that demonstrate this endpoint.

  • 1_request.py - Call the topic endpoint with requests, not using the Python client.

  • 2_standard.py - Call the topic endpoint with the Python client.

The full schema is in datatypes.py.

/riff Endpoint

This endpoint provides a more powerful capability for music lovers to craft the exact sound they want. You can specify custom lyrics and multiple sound prompts with individually controllable strengths and time ranges.

Here's a call that creates a 10 second orchestral intro in a chillstep pop song with custom lyrics:

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()

riff_api.create(
    prompts=[
        riff_api.Prompt(
            text="chillstep pop",
            strength=4.0,
        ),
        riff_api.Prompt(
            text="orchestral cellos",
            strength=3.0,
            start_s=0.0,
            end_s=10.0,
        ),
    ],
    lyrics=lyrics,
    save_to="output.wav",
)

Examples

Check out examples/riff for runnable scripts that demonstrate this endpoint.

The full schema is in datatypes.py.

Streamlit Demo

demo_app.py is a basic web app built with Streamlit that demonstrates using the api.

Try it: https://riff-api.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.4.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

riff_api-0.1.4-py3-none-any.whl (9.5 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