{
 "openapi": "3.1.0",
 "info": {"title": "Speech API (STT + TTS)", "version": "local",
  "description": "OpenAI-compatible speech-to-text (NVIDIA Parakeet TDT v3, 25 European languages) and text-to-speech (Kyutai Pocket TTS, cloned voices, English and French). Authenticate with X-API-Key or Authorization: Bearer."},
 "servers": [{"url": "/speech"}],
 "components": {"securitySchemes": {
   "apiKey": {"type": "apiKey", "in": "header", "name": "X-API-Key"},
   "bearer": {"type": "http", "scheme": "bearer"}}},
 "security": [{"apiKey": []}, {"bearer": []}],
 "paths": {
  "/v1/audio/speech": {"post": {"summary": "Text to speech", "description": "Streams audio sentence by sentence. Each sentence is checked by transcribing it back and regenerated when words are missing; loudness is normalised to -18 LUFS.",
   "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["input"], "properties": {
     "input": {"type": "string", "maxLength": 4096},
     "voice": {"type": "string", "example": "alba", "description": "A name from GET /v1/voices (the voices your key may use), or an alias such as alloy or nova. Optional: defaults to the voice marked default there"},
     "language": {"type": "string", "enum": ["en", "fr"], "description": "Optional; detected from the text when absent"},
     "response_format": {"type": "string", "enum": ["mp3", "opus", "aac", "flac", "wav", "pcm"], "default": "mp3"},
     "model": {"type": "string", "description": "Ignored (pocket-tts)"},
     "verify": {"type": "boolean", "default": true, "description": "Round-trip check and retry of each sentence"}}}}}},
   "responses": {"200": {"description": "Audio (24 kHz mono)", "content": {"audio/mpeg": {}, "audio/ogg": {}, "audio/wav": {}, "audio/L16": {}}},
     "400": {"description": "Invalid input, language, or voice (invalid_voice: the voice is unknown or not available for this key; the message lists the available ones)"}}}},
  "/v1/audio/transcriptions": {"post": {"summary": "Speech to text (audio or video file)",
   "requestBody": {"required": true, "content": {"multipart/form-data": {"schema": {"type": "object", "required": ["file"], "properties": {
     "file": {"type": "string", "format": "binary", "description": "mp3, m4a, ogg, opus, wav, flac, mp4, mkv, mov, webm…"},
     "model": {"type": "string", "description": "Ignored (parakeet)"},
     "response_format": {"type": "string", "enum": ["json", "text", "verbose_json", "srt", "vtt"], "default": "json"},
     "timestamp_granularities[]": {"type": "string", "enum": ["segment", "word"]},
     "stream": {"type": "boolean", "description": "Server-sent events: transcript.text.delta then transcript.text.done"},
     "remove_fillers": {"type": "boolean", "default": true, "description": "Drop uh/um/euh (send false to keep them)"}}}}}},
   "responses": {"200": {"description": "Transcript"}, "413": {"description": "Too long: use /v1/jobs"}}}},
  "/v1/jobs": {"post": {"summary": "Transcribe a long file in the background", "description": "Same form as /v1/audio/transcriptions. Poll GET /v1/jobs/{id}.",
   "requestBody": {"required": true, "content": {"multipart/form-data": {"schema": {"type": "object", "required": ["file"], "properties": {"file": {"type": "string", "format": "binary"}}}}}},
   "responses": {"202": {"description": "Job accepted"}, "429": {"description": "Too many pending jobs"}}}},
  "/v1/jobs/{id}": {"get": {"summary": "Job status and result", "parameters": [
     {"name": "id", "in": "path", "required": true, "schema": {"type": "string"}},
     {"name": "format", "in": "query", "schema": {"type": "string", "enum": ["json", "text", "verbose_json", "srt", "vtt"]}, "description": "Return only the transcript in this format once done"}],
   "responses": {"200": {"description": "Job"}, "404": {"description": "Unknown job"}}},
   "delete": {"summary": "Cancel a job", "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "string"}}], "responses": {"204": {"description": "Cancelled"}}}},
  "/v1/realtime": {"get": {"summary": "Live transcription (WebSocket)", "description": "Send binary PCM16 little-endian mono frames (sample_rate query, default 16000) and {\"type\":\"stop\"} to finish. Receive JSON events: ready, partial {text,start}, final {text,start,end}, done {reason}, error. Browsers: get a 60-second token from POST /auth/token and pass ?access_token=…",
   "parameters": [{"name": "sample_rate", "in": "query", "schema": {"type": "integer", "default": 16000}}, {"name": "access_token", "in": "query", "schema": {"type": "string"}}],
   "responses": {"101": {"description": "Switching protocols"}, "429": {"description": "Live session limit reached"}}}},
  "/v1/voices": {"get": {"summary": "Voices available to your key", "description": "Standard voices for every key; custom voices only for keys allowed to use them. Each entry: name, languages, kind (standard/custom), gender, accent, aliases, license, attribution, source. 'default' is the voice used when a request names none.", "responses": {"200": {"description": "{voices: [...], default: name}"}}}},
  "/v1/models": {"get": {"summary": "Models", "responses": {"200": {"description": "OpenAI-style model list"}}}},
  "/health": {"get": {"summary": "Health", "security": [], "responses": {"200": {"description": "ok"}}}}
 }
}