Prompt based instrumental music generation.
Melody Engine is a thin but practical wrapper on MagentaRT, providing:
- REST API for programmatic music generation
- Serialized job queue to avoid GPU thrashing
- Containerized runtime for reproducible deployment
- Web interface that hides MagentaRT's operational complexity
You would need a machine with a powerful Nvidia GPU, and a linux host with podman or docker installed. The MagentaRT's official repository suggests a GPU with at least 40GB VRAM, but in my experience, a powerful enough GPU like NVIDIA RTX A5000 with 24GB VRAM works just fine, especially for what I have experimented with.
Use the pre-built container image from Docker Hub to run Melody Engine.
-
Pull the latest container image from Docker Hub.
podman image pull docker.io/zbhavyai/melody-engine:latest
-
Create output and cache directories on the host
mkdir -p "$(pwd)/outputs" && mkdir -p "$HOME/.cache/melody-engine"
-
Run the container. This will load MagentaRT on your GPU and start a
uvicornserver on port8080.podman container run \ --detach \ --name melody-engine \ --restart unless-stopped \ --publish 8080:8080 \ --security-opt=label=disable \ --env TF_GPU_ALLOCATOR=cuda_malloc_async \ --device=nvidia.com/gpu=all \ --volume "$(pwd)/outputs:/opt/app/outputs:rw,Z" \ --volume "$HOME/.cache/melody-engine:/magenta-realtime/cache:rw,Z" \ docker.io/zbhavyai/melody-engine:latest
Alternatively, build and run container image locally.
-
Build the container image.
make container-build
-
Run the container. This will load MagentaRT on your GPU and start a
uvicornserver on port8080.make container-run
Once the container is running, you can interact with the Melody Engine web interface or REST API.
-
Access the web interface at localhost:8080 or explore the API documentation at localhost:8080/docs.
-
Generated audio files are saved locally in the
outputsdirectory, or can be downloaded from the web interface or REST API.
Generate a 1-hour spacey electronica track using the REST API.
-
Submit a generation job. The response will include a job ID, which uniquely identifies your generation request.
curl \ --request POST \ --location 'localhost:8080/api/v1/jobs' \ --header 'Content-Type: application/json' \ --data '{ "prompt": "spacey electronica with drifting pads and gentle rhythmic motion", "duration_s": 3600, "gain_db": 0, "format": "mp3" }'
-
Poll the status of your job.
curl \ --request GET \ --location 'localhost:8080/api/v1/jobs/{job_id}' -
Once the job is complete, you may download the generated audio file.
curl \ --request GET \ --location 'localhost:8080/api/v1/jobs/{job_id}/download' \ --output 'generated_track.mp3'