FFmpeg Automation API
Convert and process audio directly through the Kokoro infrastructure. These endpoints expose the same FFmpeg helpers we use internally so you can automate WAV → MP3 conversion and tempo changes without maintaining a custom media server.
Available endpoints
| Method | Path | Description |
|---|---|---|
| POST | /api/v1/ffmpeg/wav-to-mp3 | Convert base64 WAV input into MP3 with a selectable bitrate. |
| POST | /api/v1/ffmpeg/speed | Adjust playback speed (0.25x–5x) and optionally return MP3. |
Both endpoints require the same bearer token used by the speech API. Swagger docs live at /api/v1/index.html.
Preparing payloads
- Encode the WAV file you want to process with
base64(example below). - Strip newlines so the JSON body stays compact:
BASE64_WAV=$(base64 -i input.wav | tr -d '\n'). - Send the value in the
audiofield. The API validates RIFF/WAVE headers. - Set
response_typetobase64for JSON output or omit it to receive a binary stream.
WAV → MP3 conversion
Supply a base64 WAV payload and optionally override the bitrate (defaults
to 192k). Use response_type=base64 when testing from
terminals, or keep the binary response to pipe directly to a file.
Request fields
| Field | Required | Description |
|---|---|---|
audio | Yes | Base64-encoded WAV file. |
bitrate | No | FFmpeg bitrate such as 128k, 192k, 320k. |
response_type | No | binary (default) or base64. |
curl example
BASE64_WAV=$(base64 -i input.wav | tr -d '
')
curl -X POST https://kokoro.lancesmith.cc/api/v1/ffmpeg/wav-to-mp3 -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" --data '{
"audio": "'"$BASE64_WAV"'",
"bitrate": "256k",
"response_type": "base64"
}'Speed adjustment
Send a WAV payload plus the desired multiplier. The API returns WAV by
default, or MP3 when output_format is set to mp3 (you can
also pick a bitrate).
Request fields
| Field | Required | Description |
|---|---|---|
audio | Yes | Base64 WAV payload. |
speed | Yes | Multiplier between 0.25 and 5. |
output_format | No | wav (default) or mp3. |
bitrate | No | Only used when returning MP3. |
response_type | No | binary (default) or base64. |
curl example
BASE64_WAV=$(base64 -i input.wav | tr -d '
')
curl -X POST https://kokoro.lancesmith.cc/api/v1/ffmpeg/speed -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" --data '{
"audio": "'"$BASE64_WAV"'",
"speed": 1.25,
"output_format": "mp3",
"response_type": "base64"
}'Node example
import fs from "fs";
const wav = await fs.promises.readFile("input.wav");
const base64 = wav.toString("base64");
const response = await fetch("https://kokoro.lancesmith.cc/api/v1/ffmpeg/speed", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
audio: base64,
speed: 0.8,
output_format: "mp3",
response_type: "base64",
}),
});
if (!response.ok) {
throw new Error(`FFmpeg API failed: ${response.status}`);
}
const payload = await response.json();
await fs.promises.writeFile("slower.mp3", Buffer.from(payload.audio, "base64"));Need more?
Let us know if you need additional FFmpeg routines exposed—transcoding, trimming, mixing, or waveform analytics can be added using the same pattern.
