Skip to content

Instantly share code, notes, and snippets.

@Rhincodon
Last active October 24, 2018 13:30
Show Gist options
  • Save Rhincodon/359d78f2391350bb18fccfb164f21fa3 to your computer and use it in GitHub Desktop.
Save Rhincodon/359d78f2391350bb18fccfb164f21fa3 to your computer and use it in GitHub Desktop.
<script src="https://speech-poc.awsext.berlitz.net/libs/speech-to-text.js"></script>
<!-- Azure Only -->
<script src="https://speech-poc.awsext.berlitz.net/libs/microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<script>
// INITIALIZATION
const speechToText = new SpeechToText();
speechToText.addService('azure', new SpeechToTextAzure({
key: 'key',
region: 'westus',
language: 'en-US'
}));
speechToText.addService('google', new SpeechToTextGoogle({
socketUrl: 'https://some-url'
}));
speechToText.addService('browser', new SpeechToTextBrowserApi());
speechToText.setCurrentService('azure');
// or
speechToText.setServicePriority(['browser', 'azure', 'google']);
// USAGE
try {
speechToText.init(); // check microphone, throw exception if none of services works
} catch (e) {
// mic or services not working
}
speechToText.onResults = (text, isCorrect, isCorrectByAlternative) => {
// process results
}
speechToText.startRecognition({answer: 'Some Text', alternatives: ['alternative'], maxListenTime: 10});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment