Viam SDK
    Preparing search index...

    Interface AudioOut

    Represents a device that outputs audio.

    interface AudioOut {
        getProperties: (extra?: Struct) => Promise<AudioProperties>;
        name: string;
        play: (
            audioData: Uint8Array,
            audioInfo?: AudioInfo,
            extra?: Struct,
        ) => Promise<void>;
        playStream: (
            audioInfo: AudioInfo,
            chunks: AsyncIterable<Uint8Array<ArrayBufferLike>>,
            extra?: Struct,
        ) => Promise<void>;
        doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
        getStatus(): Promise<JsonValue>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    getProperties: (extra?: Struct) => Promise<AudioProperties>

    Return the audio output properties.

    const audioOut = new VIAM.AudioOutClient(machine, 'my_audio_out');
    const properties = await audioOut.getProperties();
    name: string

    The name of the resource.

    play: (
        audioData: Uint8Array,
        audioInfo?: AudioInfo,
        extra?: Struct,
    ) => Promise<void>

    Play audio on the device.

    Type Declaration

      • (audioData: Uint8Array, audioInfo?: AudioInfo, extra?: Struct): Promise<void>
      • Parameters

        • audioData: Uint8Array

          The audio data to play

        • OptionalaudioInfo: AudioInfo

          Information about the audio format (optional, required for raw pcm data)

        • Optionalextra: Struct

        Returns Promise<void>

    const audioOut = new VIAM.AudioOutClient(machine, 'my_audio_out');
    const audioData = new Uint8Array([...]); // Your audio data
    const audioInfo = { codec: 'pcm16', sampleRateHz: 48000, numChannels: 2 };
    await audioOut.play(audioData, audioInfo);
    playStream: (
        audioInfo: AudioInfo,
        chunks: AsyncIterable<Uint8Array<ArrayBufferLike>>,
        extra?: Struct,
    ) => Promise<void>

    Stream audio chunks to the device for playback.

    The caller provides an async iterable of raw audio bytes. Each chunk must match the codec and format described by audioInfo. Playback starts as chunks arrive on the server, before the iterable is exhausted.

    Type Declaration

      • (
            audioInfo: AudioInfo,
            chunks: AsyncIterable<Uint8Array<ArrayBufferLike>>,
            extra?: Struct,
        ): Promise<void>
      • Parameters

        • audioInfo: AudioInfo

          Information about the audio format (codec, sample rate, channels) that applies to every chunk

        • chunks: AsyncIterable<Uint8Array<ArrayBufferLike>>

          Async iterable of audio byte chunks to play in order

        • Optionalextra: Struct

        Returns Promise<void>

    const audioOut = new VIAM.AudioOutClient(machine, 'my_audio_out');
    const audioInfo = {
    codec: 'pcm16',
    sampleRateHz: 22050,
    numChannels: 1,
    };

    async function* chunks() {
    for (const chunk of pcmChunks) yield chunk;
    }

    await audioOut.playStream(audioInfo, chunks());

    Methods

    • Send/Receive arbitrary commands to the resource.

      Parameters

      • command: Struct | Record<string, JsonValue>

        The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.

      Returns Promise<JsonValue>

      // Plain object (recommended)
      const result = await resource.doCommand({
      myCommand: { key: 'value' },
      });

      // Struct (still supported)
      import { Struct } from '@viamrobotics/sdk';

      const result = await resource.doCommand(Struct.fromJson({ myCommand: { key: 'value' } }));