Configuring Speech to Text
Configuring Automatic Language Detection
You can configure the system to handle up to 10 languages using the function #setSttOptions. For example:
#setSttOptions(options: { autoDetectLanguages: ["en-US", "de-DE"] });
Handling Language Change
To handle language changes dynamically, use the following code:
context { input language: string = "en-US"; input autoDetectLanguages: string[] = ["en-US", "de-DE"]; prompt = `Your prompt... # Language instruction Reply in {{language}}`; } when opened do { #changeLanguage($language, #getCurrentSpeaker().speaker); #setSttOptions(options: { autoDetectLanguages: $autoDetectLanguages }); } when languageDetected do { var lang = #getDetectedLanguage()?.language; if (lang is not null) { #log("Detected language: " + lang); #changeLanguage(lang, #getCurrentSpeaker().speaker); set $language = lang; } }
Requiring evidence before a language change
By default languageDetected fires as soon as one recognized phrase is tagged with another language — even a single word such as "Ok" or "Hello" that the recognizer happened to hear as Spanish. With the connect option stt_language_switch_evidence the language of each speaker route is decided on accumulated evidence instead:
#connectSafe($endpoint, { stt_language_switch_evidence: "3" // distinct words in the other language before the route switches });
stt_language_switch_evidence— the number of distinct words tagged with another language the route must accumulate across phrases beforelanguageDetectedfires."0"(default) keeps the immediate per-phrase behavior. With"3", a whole sentence in the other language switches at once; short answers add up ("¿Bueno?", "SÃ", "DÃgame"); a lone "Ok" never does. Switching back is symmetric and also fireslanguageDetected, so a caller who switches back to the primary language is reported too.#getDetectedLanguage().textis then the words that produced the decision.stt_language_clear_words— a phrase of at least this many words in the current language discards the evidence collected before it (default"3"): a misheard greeting followed by an ordinary sentence does not count towards a switch.stt_language_ignore_capitalized— capitalized words that do not start a sentence (names, abbreviations) are not evidence (default"true").stt_language_neutral_words— comma-separated interjections that count for no language; replaces the default list (ok, okay, uh, um, mm, mhm, hmm, hm, ah, oh, eh, huh, aha).
Digits and single letters never count. A #changeLanguage call restarts the evidence for that speaker from the new language.
Text Normalization Control
Inverse Text Normalization (ITN) is the process of converting spoken words into their written form. For example, converting the spoken word "four" to the written form "4".
Punctuation
| Spoken Text | Punctuation | Recognized Text |
|---|---|---|
| how are you | true (default) | How are you? |
| how are you | false | how are you |
| we can go to the mall park or beach | true (default) | We can go to the mall, park, or beach. |
| we can go to the mall park or beach | false | we can go to the mall park or beach |
Normalization
| Spoken Text | Normalization | Recognized Text |
|---|---|---|
| support at dasha dot ai | true (default) | support@dasha.ai |
| support at dasha dot ai | false | support at dasha dot ai |
| that will cost nine hundred dollars | true (default) | That will cost $900. |
| that will cost nine hundred dollars | false | that will cost nine hundred dollars |
Example:
when opened do { #setSttOptions(options: { normalization: false }); }
Functions
setSttOptions
Configures Speech to Text settings.
Parameters
| Name | Type | Description |
|---|---|---|
| context | string | Speech to text context. Deprecated. |
| options | SttOptions | Additional configuration |
SttOptions (type)
| Name | Type | Description |
|---|---|---|
| autoDetectLanguages | string[] | List of language codes, such as ["en-US", "de-DE"], for automatic detection. Up to 10 codes. |
| punctuation | boolean? | Controls automatic punctuation. |
| normalization | boolean? | Controls Inverse Text Normalization. If disabled, text will be as pronounced (e.g., "four" instead of "4"). |
| keywords | string[] | Array of keyword strings for boosting or suppressing recognition probability. Each string can be a plain word (e.g., "apple") or a word with weight in format "word:weight" where weight is a number in range [-1, 1]. 1 = maximum boost (increase probability), -1 = maximum suppression (decrease probability). Note: Some STT providers may not support negative weight values for suppression. |