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>;
    doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
}

Hierarchy (View Summary)

Implemented by

Properties

Methods

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);

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' } })
    );