Developers · HTTP API
Get a sound from the API
Send one request and save the sound it returns, with curl, Python or JavaScript.
Send one request to the Mirli server and save the sound it returns as a WAV file. The request waits while the model renders, so there is no job to follow.
Before you begin
- Mirli is running on this machine. The desktop app starts the server; from a clone, Run Mirli from source describes how to start it.
- The Stable Audio 3.0 SFX model is installed. In the app, go to the Models page to install it.
- For the Python example, Python 3. For the JavaScript example, Node.js 18 or later.
Render a sound
Check that the server answers on its default address:
Terminal curl http://127.0.0.1:17494/api/healthThe response is JSON with
"status": "ok". If the connection is refused, the server is not running or listens on another port.Send a render request for a two-second door slam. For Python, save the code as
render.pyand runpython render.py; for JavaScript, save it asrender.mjsand runnode render.mjs:Terminal curl -X POST http://127.0.0.1:17494/api/render \ -H 'Content-Type: application/json' \ -d '{ "model": "audiocpp-stable-audio-3-sfx", "prompt": "heavy wooden door slam, dry room", "duration_s": 2 }' \ -o door.wavPython import json import urllib.request body = json.dumps({ "model": "audiocpp-stable-audio-3-sfx", "prompt": "heavy wooden door slam, dry room", "duration_s": 2, }).encode() request = urllib.request.Request( "http://127.0.0.1:17494/api/render", data=body, headers={"Content-Type": "application/json"}, ) with urllib.request.urlopen(request) as response: with open("door.wav", "wb") as out: out.write(response.read())JavaScript import { writeFile } from "node:fs/promises"; const response = await fetch("http://127.0.0.1:17494/api/render", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ model: "audiocpp-stable-audio-3-sfx", prompt: "heavy wooden door slam, dry room", duration_s: 2, }), }); if (!response.ok) throw new Error(await response.text()); const audio = Buffer.from(await response.arrayBuffer()); await writeFile("door.wav", audio);The request returns when the render is done, which takes seconds to a minute, and
door.wavappears in the current folder.Open
door.wavin an audio player to hear the result. The sound is also in the app's library, because the server keeps every render by default.
If a step returns an error instead, its detail says why.
Errors lists every status and what causes it.
What's next
- Generation endpoints describe every field of a render, and the job-based endpoints for long renders.
- Speech endpoints describe reading text aloud with a saved voice.
- OpenAI-compatible endpoints describe using an OpenAI client library with Mirli.