Language
Inference Space Docs

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 as multipart/form-data and receive recognized text.
  • TTS: POST https://ai.inf.space/v1/audio/speech; submit text as application/json and 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 with gk_.
  • scope: ASR requires ai:asr, and TTS requires ai:tts (select these when creating the Key; the ai:* wildcard also works).

See Authentication.

Speech recognition (ASR)

Send a multipart/form-data request to /v1/audio/transcriptions.

Fields

FieldTypeRequiredDescription
audiofileYesAudio file; the field name file is also accepted.
formatstringNoAudio format: pcm / wav / mp3 / ogg; if omitted, it is inferred from the filename extension or MIME type.
languagestringNoRecognition language; defaults to zh-CN.
sample_rateintegerNoSample 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

FieldTypeRequiredDescription
textstringYesText to synthesize; must not be empty and must contain ≤ 5,000 characters.
voicestringNoVoice; defaults to default (available voices depend on the console).
speednumberNoSpeech speed from 0.5 to 2.0; defaults to 1.0.
formatstringNoOutput format: mp3 / wav / pcm; defaults to mp3.

Response Content-Type

The response body contains raw audio bytes, and Content-Type depends on format:

formatContent-Type
mp3 (default)audio/mp3
wavaudio/wav
pcmaudio/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.mp3
import 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, scope ai:asr).
  • POST https://ai.inf.space/v1/synthesize (TTS, scope ai: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.

On this page