@voxta/voxta-audio
v1.7.2
Published
Browser audio playback for the [Voxta Server](https://doc.voxta.ai/) websocket API.
Readme
Voxta: voxta-audio
Browser audio playback for the Voxta Server websocket API.
This library turns the audio referenced by replyChunk messages into ordered,
gap-aware playback through the Web Audio API. It is decoupled from any UI: pair it
with @voxta/voxta-client to
hear a character speak.
This library is early beta and subject to change.
Example usage
import { AudioPlayback } from '@voxta/voxta-audio';
import { ServerReplyChunkMessage } from '@voxta/voxta-client';
const playback = new AudioPlayback<ServerReplyChunkMessage>();
// Unlock the AudioContext from a user gesture (e.g. a click), passing the output
// device id ('' for the default device).
await playback.resume('');
// When a replyChunk arrives with an audioUrl, queue it for playback.
voxtaClient.addEventListener('replyChunk', (e) => {
if (e.detail.audioUrl) playback.play(e.detail.audioUrl, e.detail);
});Announce the content types you can play when authenticating, via
AudioPlayback.acceptedAudioContentTypes.
Building
Run nx build voxta-audio to build the library.
Running unit tests
Run nx test voxta-audio to execute the unit tests via Vitest.
