Created
April 28, 2025 16:46
-
-
Save skang2-sc/638207834c2662817b1b9d46b4275eb0 to your computer and use it in GitHub Desktop.
Easy way to use the VoiceML module to get Speech to Text on Spectacles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@component | |
export class SpeechToText extends BaseScriptComponent { | |
private voiceMLModule: VoiceMLModule = require("LensStudio:VoiceMLModule"); | |
onAwake() { | |
let options = VoiceML.ListeningOptions.create(); | |
options.shouldReturnAsrTranscription = true; | |
options.shouldReturnInterimAsrTranscription = true; | |
this.voiceMLModule.onListeningEnabled.add(() => { | |
this.voiceMLModule.startListening(options); | |
this.voiceMLModule.onListeningUpdate.add(this.onListenUpdate.bind(this)); | |
}); | |
} | |
onListenUpdate = (eventData: VoiceML.ListeningUpdateEventArgs) => { | |
if (eventData.isFinalTranscription) { | |
print(eventData.transcription); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment