Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddyVerbruggen/f3509c1f338194b0f09298fde7bbff23 to your computer and use it in GitHub Desktop.
Save EddyVerbruggen/f3509c1f338194b0f09298fde7bbff23 to your computer and use it in GitHub Desktop.
Speech Recognition in NativeScript
// import the plugin
import { SpeechRecognition } from "nativescript-speech-recognition";
class SpeechRecognition {
// instantiate the plugin
private speechRecognition = new SpeechRecognition();
public checkAvailability(): void {
this.speechRecognition.available().then(
(available: boolean) => console.log(available ? "YES!" : "NO"),
(err: string) => console.log(err)
);
}
public startListening(): void {
this.speechRecognition.startListening({
// optional, uses the device locale by default
locale: "en-US",
// this callback will be invoked repeatedly during recognition
onResult: (transcription: SpeechRecognitionTranscription) => {
console.log(`User said: ${transcription.text}`);
console.log(`User finished?: ${transcription.finished}`);
},
}).then(
(started: boolean) => { console.log(`started listening`) },
(errorMessage: string) => { console.log(`Error: ${errorMessage}`); }
);
}
public stopListening(): void {
this.speechRecognition.stopListening().then(
() => { console.log(`stopped listening`) },
(errorMessage: string) => { console.log(`Stop error: ${errorMessage}`); }
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment