Viam SDK
    Preparing search index...

    Class AudioOutClient

    A gRPC-web client for the AudioOut component.

    Implements

    Index

    Constructors

    Properties

    callOptions: CallOptions = ...
    name: string

    The name of the resource.

    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.

      • callOptions: CallOptions = ...

      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' } }));
    • Return the audio output properties.

      Parameters

      • extra: {} = {}
      • callOptions: CallOptions = ...

      Returns Promise<
          { numChannels: number; sampleRateHz: number; supportedCodecs: string[] },
      >

      const audioOut = new VIAM.AudioOutClient(machine, 'my_audio_out');
      const properties = await audioOut.getProperties();
    • Get the status of the resource.

      Parameters

      • callOptions: CallOptions = ...

      Returns Promise<JsonValue>

    • Play audio on the device.

      Parameters

      • audioData: Uint8Array

        The audio data to play

      • OptionalaudioInfo: AudioInfo

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

      • extra: {} = {}
      • callOptions: CallOptions = ...

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

      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

      • extra: {} = {}
      • callOptions: CallOptions = ...

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