Lens Scripting API

    Class AsrModule

    Allows the Lens to incorporate voice transcription with higher quality than the VoiceMlModule and supports a vast number of different languages.

    JavaScript

    const asrModule = require("LensStudio:AsrModule");

    function onTranscriptionError(errorCode) {
    print(`onTranscriptionErrorCallback errorCode: ${errorCode}`);
    switch (errorCode) {
    case AsrModule.AsrStatusCode.InternalError:
    print("stopTranscribing: Internal Error");
    break;
    case AsrModule.AsrStatusCode.Unauthenticated:
    print("stopTranscribing: Unauthenticated");
    break;
    case AsrModule.AsrStatusCode.NoInternet:
    print("stopTranscribing: No Internet");
    break;
    }
    }

    function onTranscriptionUpdate(eventArgs) {
    var text = eventArgs.text;
    var isFinal = eventArgs.isFinal;
    print(`onTranscriptionUpdateCallback text=${text}, isFinal=${isFinal}`)
    }

    function startSession() {
    var options = AsrModule.AsrTranscriptionOptions.create();
    options.silenceUntilTerminationMs = 1000;
    options.mode = AsrModule.AsrMode.HighAccuracy;
    options.onTranscriptionUpdateEvent.add(onTranscriptionUpdateCallback);
    options.onTranscriptionErrorEvent.add(onTranscriptionErrorCallback);

    // Start session
    asrModule.startTranscribing(options);
    }

    function stopSession() {
    asrModule
    .stopTranscribing()
    .then(function () {
    print(
    `stopTranscribing successfully`
    );
    });
    }

    TypeScript

    @component
    export class AsrExample extends BaseScriptComponent {
    private asrModule = require("LensStudio:AsrModule")

    private onTranscriptionUpdate(eventArgs: AsrModule.TranscriptionUpdateEvent) {
    print(`onTranscriptionUpdateCallback text=${eventArgs.text}, isFinal=${eventArgs.isFinal}`)
    }

    private onTranscriptionError(eventArgs: AsrModule.AsrStatusCode) {
    print(`onTranscriptionErrorCallback errorCode: ${eventArgs}`);
    switch (eventArgs) {
    case AsrModule.AsrStatusCode.InternalError:
    print("stopTranscribing: Internal Error");
    break;
    case AsrModule.AsrStatusCode.Unauthenticated:
    print("stopTranscribing: Unauthenticated");
    break;
    case AsrModule.AsrStatusCode.NoInternet:
    print("stopTranscribing: No Internet");
    break;
    }
    }

    onAwake(): void {
    const options = AsrModule.AsrTranscriptionOptions.create()
    options.silenceUntilTerminationMs = 1000
    options.mode = AsrModule.AsrMode.HighAccuracy
    options.onTranscriptionUpdateEvent.add((eventArgs) => this.onTranscriptionUpdate(eventArgs))
    options.onTranscriptionErrorEvent.add((eventArgs) => this.onTranscriptionError(eventArgs))

    this.asrModule.startTranscribing(options)
    }

    private stopSession(): void {
    this.asrModule.stopTranscribing()
    }
    }

    Hierarchy (View Summary, Expand)

    Index

    Properties

    name: string

    The name of the Asset in Lens Studio.

    uniqueIdentifier: string

    Methods

    • Returns the name of this object's type.

      Returns string

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

      Parameters

      • type: string

      Returns boolean

    • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

      Parameters

      Returns boolean

    • Wearable Only

      Starts a new ASR session. While active the Lens will transcribe speech to text. asrTranscriptionOptions provides the options for the session

      The event onTranscriptionUpdateEvent is triggered when the transcription is updated. The event onTranscriptionErrorEvent is triggered when there is an error in the transcription process.

      If startTranscribing is called again while a session is active, the current session is cancelled and a new one started.

      Parameters

      Returns void

    • Wearable Only

      Stops an active ASR Session before transcription is finished and discards the current session.

      Returns Promise<void>

    MMNEPVFCICPMFPCPTTAAATR