Member Junction
    Preparing search index...

    Web Audio playout scheduler for raw PCM16 model audio at a driver-supplied sample rate.

    Chunks are wrapped in AudioBuffers and scheduled back-to-back against a playhead clock: each chunk starts at max(playheadTime, currentTime) and advances the playhead by its duration, producing gapless playout regardless of network jitter. IsPlaying is computed directly from that clock — the playhead being ahead of currentTime (with live sources) means audio is audibly coming out of the speaker. On interruption, Flush stops every scheduled source and rewinds the playhead.

    It is also the voice's playback clock (IPlaybackClock): each chunk enqueued with a media time keeps its place on the context's clock, and CurrentTimeMs reads out the media time of the audio heard now (the context's time less the output latency the browser reports). A video player given this clock shows each frame when the voice reaches it.

    Generalized from the Gemini driver's original 24 kHz-fixed engine: the sample rate is now a constructor parameter so providers that negotiate their output format at session start (e.g. ElevenLabs' agent_output_audio_format) can construct the playout engine with the negotiated rate.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Accessors

    • get CurrentTimeMs(): number

      The media time (ms) of the audio heard now: the context's time, less the output latency the browser reports (outputLatency and baseLatency, where it has them), placed in the chunk playing then. null while nothing plays, between chunks, or while the chunk playing carries no media time (untimed audio with no timed audio before it).

      Returns number

    Methods

    • Takes a media element's audio into the master gain, beside the PCM sources: the speakers, the meter and the recording tap then carry it. The audio arrives as the element's stream from the page's MediaElementAudioRouter, which connects the element to Web Audio once per page (a browser allows that once per element, ever), so the next call that shows the same element takes its voice too. Once per element for this engine. When the router can't route the element, it logs why; a failure here is logged too, never thrown: the call goes on without that element's voice.

      Parameters

      • element: HTMLMediaElement

      Returns void

    • Schedules a raw PCM16 mono chunk back-to-back after any already-queued audio.

      Parameters

      • pcm16: ArrayBuffer

        The chunk.

      • OptionalmediaTimeMs: number

        Where the chunk starts on the stream's media timeline (ms), when the driver knows it: a playback that is also an IPlaybackClock then reads out the media time of the audio heard. A chunk without one continues the chunk before it.

      Returns void

    • The agent's output audio as a MediaStream, or null when unsupported. Hosts mix this into a recording: WebRTC drivers get the agent voice from the peer connection, PCM drivers (which play through Web Audio) must expose it from here. The stream lives on this engine's own (e.g. 24 kHz) context, so consumers wrap it in a source node on THEIR context rather than reusing this one.

      Returns MediaStream