Skip to content

fix(kokoro): refuse unreadable and unspeakable text per item - #1156

Draft
ShaiShmuel wants to merge 1 commit into
mainfrom
fix/kokoro-unspeakable-input-item-errors
Draft

ShaiShmuel wants to merge 1 commit into
mainfrom
fix/kokoro-unspeakable-input-item-errors

Conversation

@ShaiShmuel

Copy link
Copy Markdown
Contributor

Before

Two kinds of text that Kokoro-82M cannot speak were not reported as item errors:

  1. A very long number. misaki reads digits with num2words, which raises OverflowError for a number of more than about 300 digits in a row. The error escaped the adapter, so the whole extract call failed with a 500 (INFERENCE_ERROR, "internal error during extraction"), including every other item in the batch. POST /v1/audio/speech returned a 500 as well.
  2. Text with nothing to speak. The English G2P drops other scripts and emoji. Text made only of them (or only of punctuation) returned success with zero or a few phoneme ids and an empty or near-silent WAV: for example 你好世界 and 😀🎉👍 gave a 44-byte WAV with no samples, Привет, мир! and ...!? well under a second of punctuation pauses.

Now

Both fail on their own with INVALID_INPUT, the code the adapter already uses for an item with no text, while the rest of the batch is synthesized:

Input Item error message
A number of more than about 300 digits text has a number too long to read aloud; separate long runs of digits with spaces
Only other scripts, emoji or punctuation text has nothing to speak: it has no English words, numbers or symbols, only other scripts, emoji or punctuation
  • The pipeline turns a ValueError or ArithmeticError raised by the G2P on the text (misaki, num2words, spaCy) into UnreadableTextError, and the adapter reports it for that item only. Other errors, such as torch runtime and device errors, MemoryError or programming errors, still propagate and fail the call as before.
  • After synthesis, an item whose phonemes contain no phoneme letter (only punctuation) is refused rather than returned as audio. Partly speakable text (Hello 😀 world, Hello 你好 world) is read as before.
  • A refused item counts no phoneme ids, like the existing INPUT_TOO_LONG refusals.
  • POST /v1/audio/speech already maps an item error to a 400 invalid_request_error; these messages name no option, so param is input. No route change was needed; a server route test covers the two messages.

Behaviour change: text made only of punctuation (for example ...!?) used to return a short WAV of pauses and is now refused with the same INVALID_INPUT error. No existing test covered it.

Testing

  • Unit tests (no GPU, no downloads; fake model and pipeline as in the existing Kokoro tests): a long number and nothing-to-speak text each fail alone in a mixed batch while the other item succeeds; partly speakable text is still spoken; a failure that is not about the text still fails the call; the pipeline maps OverflowError, ValueError and ArithmeticError from the G2P and the prefetch pass to UnreadableTextError and lets RuntimeError, torch.OutOfMemoryError, MemoryError and TypeError through unchanged; the speech route returns a 400 on input for both messages.
  • pytest packages/sie_server/tests/adapters/test_kokoro*.py packages/sie_server/tests/api: 2994 passed. ruff check and ruff format --check on the changed files pass.
  • Real run with the pinned Kokoro-82M checkpoint on CPU through a local sie-server, before and after:
Input Before After
The quick brown fox jumps over the lazy dog. 200, 3.25 s of audio unchanged
1 × 1000 speech: 500 server_error; extract: whole call 500 400 param: input, number message; extract: that item INVALID_INPUT
你好世界,今天天气很好。 200, empty WAV 400 param: input, nothing-to-speak message
😀🎉👍 200, empty WAV 400 param: input, nothing-to-speak message
...!? 200, short WAV of pauses 400 param: input, nothing-to-speak message
Hello 😀 world 200 unchanged
Extract batch [1 × 1000, sentence, 😀🎉👍] 500 for the whole call 200: item 1 and 3 INVALID_INPUT, item 2 audio

The gateway's /v1/audio/speech handler already turns any item error into a 400 on input unless the message names a sent option; it was not run for this change.

A number too long for the number reader (more than about 300 digits in a
row) raised OverflowError from num2words inside the G2P, which failed the
whole extract call and every other item in it. Text the English G2P drops
entirely (only other scripts, emoji or punctuation) returned success with
empty or near-silent audio.

Both now fail on their own with INVALID_INPUT and a short message, like an
item with no text, while the rest of the batch is synthesized. ValueError
and ArithmeticError raised by the G2P on the text become item errors; other
failures (torch runtime and device errors, MemoryError, programming errors)
still propagate. Text that is partly speakable is read as before, and the
speech route returns a 400 on `input` for these items.
@coderabbitai

coderabbitai Bot commented Dec 6, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant