Lens Scripting API
    Preparing search index...

    Class MicrophoneAudioProvider

    The Audio Track Provider of the audio from microphone.

    // @input Asset.AudioTrackAsset audioTrack
    // @input int sampleRate = 44100

    var control = script.audioTrack.control;
    if (control.isOfType("Provider.MicrophoneAudioProvider")) {
    control.start();
    }

    control.sampleRate = script.sampleRate;
    var audioFrame = new Float32Array(control.maxFrameSize);

    script.createEvent("UpdateEvent").bind(function (eventData) {
    var audioFrameShape = control.getAudioFrame(audioFrame);
    if (audioFrameShape.x == 0) {
    return;
    }
    // do something with data
    })

    Hierarchy (View Summary)

    Index

    Properties

    maxFrameSize: number

    The maximum frame size of the audio track asset.

    sampleRate: number

    Sample rate (samples per second) of the audio track asset.

    Methods

    • Exposes User Data

      Writes current frame audio data to the passed in Float32Array and returns its shape. The length of the array can't be more than maxFrameSize.

      Parameters

      • audioFrame: Float32Array

      Returns vec3

    • Exposes User Data

      Retrieves the current audio frame, converts it to PCM16 (Pulse-Code Modulation) format, and writes the raw audio samples into the provided audioFrame as an Int16Array. The length of the array cant be more than maxFrameSize.

      Parameters

      • audioFrame: Int16Array

      Returns vec3

    • Returns true if the object matches or derives from the passed in type.

      Parameters

      • type: string

      Returns boolean

    • Start processing audio from microphone. Useful to avoid redundant processing.

      Returns void

    • Stop processing audio from microphone.

      Returns void