feat(speech-api): streaming playback with MediaSource #26

Open
opened 2026-10-27 15:06:22 +00:00 by crapougnax · 0 comments
Owner

Context

ApiSpeechSynthesizer (@quatrain/speech-api, #22) downloads the whole audio file of a sentence before playback starts. With providers that support chunked output, time-to-first-audio could drop to the first chunk.

Proposal

  • When the response is a streamable audio/mpeg (or audio/webm), feed chunks into a MediaSource SourceBuffer and start playback on the first appended chunk.
  • Fall back to the current full-download path when MediaSource or the MIME type is unsupported (Safari iOS: ManagedMediaSource).
  • Keep prepare() / play() / cancel() semantics; cancel() aborts the fetch.

Acceptance criteria

  • Jest tests with a fake MediaSource cover streaming, fallback and cancellation.
  • README documents server requirements (chunked transfer, MIME type).
## Context `ApiSpeechSynthesizer` (`@quatrain/speech-api`, #22) downloads the whole audio file of a sentence before playback starts. With providers that support chunked output, time-to-first-audio could drop to the first chunk. ## Proposal - When the response is a streamable `audio/mpeg` (or `audio/webm`), feed chunks into a `MediaSource` `SourceBuffer` and start playback on the first appended chunk. - Fall back to the current full-download path when `MediaSource` or the MIME type is unsupported (Safari iOS: `ManagedMediaSource`). - Keep `prepare()` / `play()` / `cancel()` semantics; `cancel()` aborts the fetch. ## Acceptance criteria - Jest tests with a fake `MediaSource` cover streaming, fallback and cancellation. - README documents server requirements (chunked transfer, MIME type).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
quatrain/core#26
No description provided.