Skip to content

feat: built-in sounddevice stream player - #4

Merged
mikejgray merged 2 commits into
mainfrom
feat/sounddevice-player
Oct 29, 2026
Merged

mikejgray merged 2 commits into
mainfrom
feat/sounddevice-player

Conversation

@mikejgray

Copy link
Copy Markdown
Contributor

Closes #2.

Why

ffplay reading stdin discards about 0.4 s and resyncs when a chunk arrives as its buffer empties. This is the clip heard in the demos (measured played vs. sent). It also drops the first ~0.1 s of a stream and clips the end, which is why streams carried a 0.2 s silence pad.

What

  • player.py: PcmPlayer, a sounddevice RawOutputStream with its own buffer. On underrun it plays silence and continues. Nothing that was written is skipped. It counts underruns as events, not callbacks, and reports the device latency (about 30 ms on MacBook Pro speakers).
  • stream_players.py:
    • SoundDeviceStreamCallbacks (no pad, real latency).
    • FfplayStreamCallbacks (previous behavior, kept as the fallback).
    • make_stream_callbacks picks a player from the new stream_player key (auto/sounddevice/ffplay). auto uses the built-in player when sounddevice and an output device exist, and falls back to ffplay with a log line. stream_player_args still forces a subprocess player.
  • visemes.py: VisemeStreamCallbacks is now a player-independent VisemeScheduler.
  • tts.py: stream_tts takes its pad and playback latency from the active player, so the chunk scheduler uses the real device latency.
  • New optional extra [player] (sounddevice>=0.4). README updated.

Verification

  • 78 tests pass (12 new): PcmPlayer with a fake stream, both callback classes, factory selection, and the pad following the player. Ruff is clean.
  • Spike on the real device: one stall gives one underrun event, 30.5 ms latency, correct drain timing.
  • Deployed to the live Mac OVOS venv (freeze diff: only this plugin changed). The live venv selects SoundDeviceStreamCallbacks. Two live utterances played with no fallback, no underrun, and no synth errors in audio.log.

Not in this PR: reducing STARTUP_CHUNK_FRAMES for lower time-to-first-audio. That needs its own measurements.

🤖 Generated with Claude Code

https://claude.ai/code/session_012QBrfL1NoPWS1MG92dnWm7

mikejgray and others added 2 commits October 29, 2026 15:02
ffplay reading stdin discards ~0.4 s and resyncs when a chunk lands as
its buffer empties, drops the first ~0.1 s of a stream and clips the
end. PcmPlayer owns the buffer instead: an underrun plays silence and
nothing written is skipped, and the device's reported latency replaces
the 0.1 s guess in the chunk scheduler.

- stream_player: auto (default) | sounddevice | ffplay. auto uses the
  built-in player when sounddevice and an output device exist.
- The built-in player needs no silence pad; ffplay keeps its 0.2 s pad.
- VisemeStreamCallbacks splits into VisemeScheduler plus one callbacks
  class per player.
- New optional extra: ovos-tts-plugin-audio8[player].

Closes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012QBrfL1NoPWS1MG92dnWm7
The ffplay fallback cases built real OPM callbacks, which raise when no
player is on PATH (CI runners have no ffmpeg).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012QBrfL1NoPWS1MG92dnWm7
@mikejgray
mikejgray merged commit 9f7c9b1 into main Oct 29, 2026
4 checks passed
@mikejgray
mikejgray deleted the feat/sounddevice-player branch October 29, 2026 20:24
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.

Replace ffplay with a built-in streaming player

1 participant