S4daharu/Kokoro-TTS
0
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
API
This Space exposes stable Gradio API endpoints designed to work well with audioreader (VoxBook).
/generate- Inputs:
text,voice,speed,format(optional:wav(default),mp3,opus) - Outputs: audio file, JSON metadata
- Notes:
- Rejects empty input and text longer than 4000 chars.
- Automatically sanitizes control characters to prevent model crashes.
/generate_batch- Inputs:
texts(JSON array),voice,speed,format - Outputs: list of audio files, JSON metadata
- Notes:
- Graceful Failures: If a single text chunk fails, the endpoint no longer crashes the entire batch. Instead, the metadata includes an
errorsarray ([{"index": i, "error": "msg"}]) and returnsNonefor failed audio slots.
/generate_stream[NEW]- Inputs:
text,voice,speed - Outputs: Stream of raw WAV files (yielded sequentially per sentence)
- Notes: Drops Time-To-First-Byte (TTFB) to near zero, perfect for real-time playback.
/manifest[NEW]- Inputs:
text,voice,speed - Outputs: JSON array of phoneme boundaries mapping sentence indices to exact
phoneme_count,char_start, andchar_end. - Notes: Useful for precision UI text highlighting.
/voicesand/previews/{voice_id}.wavGET /voices: Returns JSON dictionary of all loaded voices and their metadata.GET /previews/{voice_id}.wav: Returns a static HTTP audio file preview of the requested voice.
/health&/metricsGET /health: Returns runtime metadata (status, cache limits, voice counts) useful for client restart-detection.GET /metrics: Exposes Prometheus-style plaintext metrics (kokoro_cache_hit_total,kokoro_generate_latency_seconds_sum,kokoro_queue_depth).
Performance & Resilience
- Rate Limiting: Enforces a token-bucket rate limit (10 requests + 10/min) keyed on the
Authorization: Bearer hf_...token to prevent abuse. - Bandwidth Optimization: Requesting
format="opus"orformat="mp3"dramatically reduces network payload size (up to 90%) at a marginal latency cost. - Caching: Generated audio is cached on disk by normalized
text + voice + speed + format. Bounded by LRU size/count limits. - Lazy Loading: Voice packs load lazily on first use and stay cached in memory.
audioreader (VoxBook) Compatibility
- SSE Protocol: Uses
/gradio_api/call/generate(and_batch,_stream) via Server-Sent Events (SSE) protocol. - Streaming Mode: The client connects to
_streamand uses aConcatenatingAudioSourceto pipe raw PCM into playback instantly. - Audio Formats: MP3/Opus formats are actively used by the client's Settings to minimize offline download storage footprint.
- Authentication: A huggingface token (e.g.
hf_...) is strictly required.
