Skip to content

fix(audio): keep chunk audio when GAP_TRIM_MS is 0 - #593

Open
lbarrosby wants to merge 1 commit into
remsky:masterfrom
lbarrosby:fix/zero-gap-trim
Open

lbarrosby wants to merge 1 commit into
remsky:masterfrom
lbarrosby:fix/zero-gap-trim

Conversation

@lbarrosby

Copy link
Copy Markdown

GAP_TRIM_MS is documented as the base trim from each chunk end, so 0 reads as "no base trim". Instead it empties every chunk: samples_to_trim is 0 and audio[0:-0] is an empty slice, and the len > 2 * samples_to_trim guard is always true. Every request then returns silence, streamed or not.

The base trim is now skipped when there is nothing to trim. The dynamic silence trim after it is unchanged.

Testing

  • uv run pytest passes locally (API changes)
  • npm run test:web passes locally (web player changes)
  • New or changed behavior has a test
  • Ran in Docker (npm run cpu:up / gpu:up), for inference or docker changes
  • CHANGELOG.md entry, if users will notice the change

test_zero_gap_trim_keeps_audio sets gap_trim_ms = 0 and checks the chunk keeps its samples, for both last and non-last chunks. It fails on master (0 == 2400) and passes with the fix. test_audio_service.py passes and ruff check / ruff format --check are clean. I didn't tick the full uv run pytest box: on my Mac (Python 3.12, no model weights) the run stops at test_tts_service.py::test_split_multi_voice_resolves_each_speaker_once, the same on master, so it's my environment and not this change.

AI disclosure: written with the help of Claude Code, reviewed and tested by me.

With a zero base trim, audio[0:-0] slices every chunk down to an empty
array, so the whole response is silent. Skip the base trim when there is
nothing to trim.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
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