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 before languageDetected fires. "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 fires languageDetected, so a caller who switches back to the primary language is reported too. #getDetectedLanguage().text is 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 TextPunctuationRecognized Text
how are youtrue (default)How are you?
how are youfalsehow are you
we can go to the mall park or beachtrue (default)We can go to the mall, park, or beach.
we can go to the mall park or beachfalsewe can go to the mall park or beach

Normalization

Spoken TextNormalizationRecognized Text
support at dasha dot aitrue (default)support@dasha.ai
support at dasha dot aifalsesupport at dasha dot ai
that will cost nine hundred dollarstrue (default)That will cost $900.
that will cost nine hundred dollarsfalsethat will cost nine hundred dollars

Example:

when opened do { #setSttOptions(options: { normalization: false }); }

Functions

setSttOptions

Configures Speech to Text settings.

Parameters

NameTypeDescription
contextstringSpeech to text context. Deprecated.
optionsSttOptionsAdditional configuration

SttOptions (type)

NameTypeDescription
autoDetectLanguagesstring[]List of language codes, such as ["en-US", "de-DE"], for automatic detection. Up to 10 codes.
punctuationboolean?Controls automatic punctuation.
normalizationboolean?Controls Inverse Text Normalization. If disabled, text will be as pronounced (e.g., "four" instead of "4").
keywordsstring[]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.
Found a mistake? Let us know.

Enroll in beta

Request invite to our private Beta program for developers to join the waitlist. No spam, we promise.