Skip to content

Instantly share code, notes, and snippets.

@skang2-sc
Created April 28, 2025 16:46
Show Gist options
  • Save skang2-sc/638207834c2662817b1b9d46b4275eb0 to your computer and use it in GitHub Desktop.
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
@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