Create speech
The OpenAI speech API: synthesizes `input` with a voice and returns the audio bytes. B3OS extension: `timestamps: "word"` returns JSON instead, with the audio base64-encoded and the start and end time of every word, which render uses to place clicks on words and cut captions. Every `response_format` is produced: `mp3`, `opus` (Ogg), `aac` (ADTS), `flac`, `wav` and `pcm` (16-bit mono at `sample_rate`, 24 kHz for `kokoro-82m`). `kokoro-82m` speaks at `speed` 0.5 to 2 and takes no `instructions`; other values return `400 unsupported_parameter`. While the node's voice service is down the answer is `503 infer_backend_unavailable` with `Retry-After`. `Server-Timing` carries the voice service's own `voice_queue` and `voice_run` beside b3osd's `synthesize` and `encode`. Bills `infer.audio_chars` (characters of `input`).
/v1/infer/audio/speech
Authentication
Request Body required
application/jsonmodel
string
REQUIRED
input
string
REQUIRED
voice
string
REQUIRED
response_format
string | null
mp3, opus, aac, flac, wav, pcm, nullspeed
number | null
instructions
string | null
timestamps
string | null
none, word, nullResponses
application/jsonobject
string
REQUIRED
speechmodel
string
REQUIRED
voice
string
REQUIRED
format
string
REQUIRED
mp3, opus, aac, flac, wav, pcmsample_rate
integer
REQUIRED
duration_ms
integer
REQUIRED
audio_base64
string (byte)
REQUIRED
words
object[]
REQUIRED
text
string
REQUIRED
start_ms
integer
REQUIRED
end_ms
integer
REQUIRED
curl -X POST 'https://beta-api.b3os.org/v1/infer/audio/speech' \ -H 'Authorization: Bearer YOUR_API_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "model": "string", "input": "string", "voice": "string", "response_format": "mp3", "speed": 1, "instructions": "string", "timestamps": "none"}'
const response = await fetch('https://beta-api.b3os.org/v1/infer/audio/speech', { method: 'POST', headers: { "Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json" }, body: JSON.stringify({ "model": "string", "input": "string", "voice": "string", "response_format": "mp3", "speed": 1, "instructions": "string", "timestamps": "none" })});const data = await response.json();console.log(data);
import requestsheaders = { 'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('https://beta-api.b3os.org/v1/infer/audio/speech', headers=headers, json={ "model": "string", "input": "string", "voice": "string", "response_format": "mp3", "speed": 1, "instructions": "string", "timestamps": "none"})print(response.json())
{ "object": "speech", "model": "kokoro-82m", "voice": "af_heart", "format": "wav", "sample_rate": 24000, "duration_ms": 1330, "audio_base64": "UklGRiQAAABXQVZFZm10IBAAAAABAAEAwF0AAIC7AAACABAAZGF0YQAAAAA=", "words": [ { "text": "Open", "start_ms": 40, "end_ms": 310 }, { "text": "the", "start_ms": 310, "end_ms": 420 }, { "text": "billing", "start_ms": 420, "end_ms": 820 }, { "text": "page.", "start_ms": 820, "end_ms": 1290 } ]}
Try this endpoint
/v1/infer/audio/speech