Speech Recognition (ASR) and Speech Synthesis (TTS)
OpenAI-compatible POST /v1/audio/transcriptions speech-to-text (multipart) and POST /v1/audio/speech text-to-speech (JSON).
Inference Space provides speech recognition (ASR, speech-to-text) and speech synthesis (TTS, text-to-speech). The data-plane endpoints use OpenAI-compatible paths:
- ASR:
POST https://ai.inf.space/v1/audio/transcriptions; upload audio asmultipart/form-dataand receive recognized text. - TTS:
POST https://ai.inf.space/v1/audio/speech; submit text asapplication/jsonand receive binary audio.
The private deployment API is identical; only the Base domain needs to change → Enterprise private deployment.
The same host also exposes two master-only aliases, POST https://ai.inf.space/v1/transcribe and POST https://ai.inf.space/v1/synthesize, with the same semantics and fields. For public-cloud integrations, prefer the /v1/audio/* paths documented here.
Authentication and Base
- API data-plane Base:
https://ai.inf.space(both curl and SDK requests go to this host). - The console and API share
https://ai.inf.space; use the path shown in each example for curl and SDK requests. - Authentication header:
Authorization: Bearer $TOS_API_KEY; Keys start withgk_. - scope: ASR requires
ai:asr, and TTS requiresai:tts(select these when creating the Key; theai:*wildcard also works).
See Authentication.
Speech recognition (ASR)
Send a multipart/form-data request to /v1/audio/transcriptions.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
audio | file | Yes | Audio file; the field name file is also accepted. |
format | string | No | Audio format: pcm / wav / mp3 / ogg; if omitted, it is inferred from the filename extension or MIME type. |
language | string | No | Recognition language; defaults to zh-CN. |
sample_rate | integer | No | Sample rate; defaults to 16000 (primarily relevant for pcm). |
- Supported formats:
pcm/wav/mp3/ogg. - Empty audio (0 bytes) returns 400. Long audio significantly increases latency; split it into segments before recognition when possible.
Request examples
curl "https://ai.inf.space/v1/audio/transcriptions" \
-H "Authorization: Bearer $TOS_API_KEY" \
-F "audio=@speech.wav" \
-F "language=zh-CN"import os
import requests
with open("speech.wav", "rb") as f:
resp = requests.post(
"https://ai.inf.space/v1/audio/transcriptions",
headers={"Authorization": f"Bearer {os.environ['TOS_API_KEY']}"},
data={"language": "zh-CN"},
files={"audio": ("speech.wav", f, "audio/wav")},
timeout=120,
)
resp.raise_for_status()
print(resp.json()["text"])import fs from "node:fs";
const form = new FormData();
form.set("language", "zh-CN");
form.append("audio", new Blob([fs.readFileSync("speech.wav")]), "speech.wav");
const resp = await fetch("https://ai.inf.space/v1/audio/transcriptions", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.TOS_API_KEY}` },
body: form,
});
const data = await resp.json();
console.log(data.text);Response
The JSON response contains the complete recognized text, audio duration, and timestamped utterances:
{
"text": "The weather is nice today. Let's take a walk in the park.",
"duration_ms": 3200,
"utterances": [
{
"text": "The weather is nice today",
"start_time": 0,
"end_time": 1600
},
{
"text": "Let's take a walk in the park",
"start_time": 1600,
"end_time": 3200
}
]
}Speech synthesis (TTS)
Send an application/json request to /v1/audio/speech; the response is binary audio, not JSON.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to synthesize; must not be empty and must contain ≤ 5,000 characters. |
voice | string | No | Voice; defaults to default (available voices depend on the console). |
speed | number | No | Speech speed from 0.5 to 2.0; defaults to 1.0. |
format | string | No | Output format: mp3 / wav / pcm; defaults to mp3. |
Response Content-Type
The response body contains raw audio bytes, and Content-Type depends on format:
format | Content-Type |
|---|---|
mp3 (default) | audio/mp3 |
wav | audio/wav |
pcm | audio/L16 |
Request examples
curl "https://ai.inf.space/v1/audio/speech" \
-H "Authorization: Bearer $TOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Welcome to Inference Space speech synthesis.",
"voice": "default",
"speed": 1.0,
"format": "mp3"
}' \
--output out.mp3import os
import requests
resp = requests.post(
"https://ai.inf.space/v1/audio/speech",
headers={"Authorization": f"Bearer {os.environ['TOS_API_KEY']}"},
json={
"text": "Welcome to Inference Space speech synthesis.",
"voice": "default",
"speed": 1.0,
"format": "mp3",
},
timeout=120,
)
resp.raise_for_status()
with open("out.mp3", "wb") as f:
f.write(resp.content)import fs from "node:fs";
const resp = await fetch("https://ai.inf.space/v1/audio/speech", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TOS_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "Welcome to Inference Space speech synthesis.",
voice: "default",
speed: 1.0,
format: "mp3",
}),
});
const buf = Buffer.from(await resp.arrayBuffer());
fs.writeFileSync("out.mp3", buf);Successful TTS responses contain binary audio. Read them as a stream or with arrayBuffer and save them to disk; do not parse them as JSON. Only error responses are JSON, such as 400 parameter errors, 429 rate limits, and 502 upstream errors.
master aliases
The master host https://ai.inf.space also provides two equivalent aliases with the same fields as this page:
POST https://ai.inf.space/v1/transcribe(ASR, scopeai:asr).POST https://ai.inf.space/v1/synthesize(TTS, scopeai:tts).
These aliases are available only on the master path. For public-cloud integrations, prefer /v1/audio/transcriptions and /v1/audio/speech; follower deployments authenticate and audit those requests locally before forwarding them for processing.
Related pages
Nano Banana Image Generation and Editing
Inference Space Nano Banana (Gemini image generation) series text-to-image and image-to-image API, centered on the native Google generateContent protocol, compatible with OpenAI Images, with unified asynchronous jobs and per-image billing.
OCR Text Recognition
POST /v1/recognize for image/PDF text recognition with multipart upload and multiple OCR providers.