u/CheatCodeSam

Trouble getting ASR to work?

I’ve been trying to get the ASR module to work. I can occasionally get it to spit out a “Internal Error”, but otherwise I’m not getting any good information out of it.

The ASR module seems to start, but no event seems to get outputted. Sometimes when I stop it I get the internal error. I’ve tried waiting for the terminationMs and manually stopping after talking. I’m just not getting anything.

Spectacles: v5.64.453 Lens Studio: 5.15.4.26022322

I have a new project with SIK, SUK, and utilities. I also have this script in the Scene Hierarchy. I also have ASR Modules in my Packages.

import { RectangleButton } from 'SpectaclesUIKit.lspkg/Scripts/Components/Button/RectangleButton';
 
@component
export class ExampleButtonScript extends BaseScriptComponent {
 
    private asrModule: AsrModule = require('LensStudio:AsrModule');
    private isRecording = false
 
    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() {
        const options = AsrModule.AsrTranscriptionOptions.create();
        options.silenceUntilTerminationMs = 100;
        options.mode = AsrModule.AsrMode.HighAccuracy;
        options.onTranscriptionUpdateEvent.add((eventArgs) =>
            this.onTranscriptionUpdate(eventArgs)
        );
        options.onTranscriptionErrorEvent.add((eventArgs) =>
            this.onTranscriptionError(eventArgs)
        );
 
        const button = this.sceneObject.createComponent(
            RectangleButton.getTypeName()
        ) as RectangleButton;
        button.size = new vec3(10, 4, 1);
        button.transform.setLocalPosition(new vec3(0, 0, -100))
        button.initialize();
        button.onTriggerUp.add(() => {
            if (this.isRecording) {
                this.asrModule.stopTranscribing()
                this.isRecording = false
                print("Stopping")
            }
            else {
                this.asrModule.startTranscribing(options);
                this.isRecording = true
                print("Starting");
            }
        });
    }
 
}
reddit.com
u/CheatCodeSam — 4 days ago