UNPKG

adaptive-speech-recognizer

Version:

Adaptive dictation-mode speech recognizer ponyfill compatible with WebChat that gives the user time to think and stutter/stammer.

43 lines (39 loc) 1.54 kB
/** * Microsoft speech service configuration * * 1. Copy and rename this file to: "directline-config.js" (?!) * 2. Add your speech subscription key below. * 3. Edit the 'region' to match the subscription key. * * @WARNING Edit the other settings at your own risk! * * @see https://github.com/nfreear/dictation/blob/main/src/createDictationRecognizerPonyfill.js#L42-L57 */ export const EVENT_INCOMING_ACT = 'webchat:incoming_activity'; // Refer to 'DEFAULTS' :~ ./src/createDictationRecognizerPonyfill.js#L42-L57 export function getDictationRecognizerConfig () { return { subscriptionKey: param(/[?&]key=(\w+)/, '__EDIT_ME__'), // << Add your subscription key << region: param(/region=(\w+)/, 'westeurope'), lang: param(/lang=([\w-]+)/, 'en-GB'), actionRecognizerEnable: !!param(/action(?:s)?=(1|true|enable)/, false), actionRecognizerOptions: { eventName: EVENT_INCOMING_ACT, initialActionPhrases: ['help', 'help me'] } /* format: 'detailed', // Was: OutputFormat.Detailed, mode: 'dictation', initialSilenceTimeoutMs: param(/initialSilenceTimeoutMs=(\d+)/, 5 * 1000), endSilenceTimeoutMs: param(/endSilenceTimeoutMs=(\d+)/, 5 * 1000), audioLogging: false, stopStatusRegex: '(NOT__EndOfDictation|InitialSilenceTimeout)', // NOT_ to disable! normalize: true, // Text normalization. separator: ' ' // A space. */ }; } function param (regex, def = null) { const matches = window.location.href.match(regex); return matches ? matches[1] : def; }