Skip to main content

SpeechRecognizer

SpeechRecognizer captures the device microphone through Android's speech recognition service and converts spoken audio into text. It is useful for voice commands, text dictation, search fields, accessibility interactions, and any gameplay or app flow that needs speech-driven input.

The component starts listening when enableRecognition is enabled. While listening, Android may send partial hypotheses before the final transcription is ready. getPartialResults() returns temporary text on frames where Android reports a partial hypothesis. getResults() returns text for exactly one engine frame, and only when Android finishes a speech recognition pass. On frames with no new recognition data, both values are empty. Read the component every update and copy any non-empty value you need to keep; otherwise a final result can be missed after that one frame passes.

Set language with a BCP-47 language tag such as pt-BR, en-US, or es-ES. If the tag is invalid, the component reports the issue in the Terminal and stops recognition instead of starting with an unknown language.

Package: JAVARuntime

Category: Sound

Component: yes


public class SpeechRecognizer extends Component

Constructors

SignatureDescription
SpeechRecognizer()Creates a new instance of SpeechRecognizer.

Virtual Attributes

NameTypeAccessDescription
enableRecognitionbooleanget/setVirtual attribute exposed by isEnableRecognition. Access it like a field to read or write the underlying value.
languageStringget/setVirtual attribute exposed by getLanguage. Use a BCP-47 language tag such as pt-BR.
partialResultsStringgetVirtual attribute exposed by getPartialResults. Returns temporary recognition text on frames with new partial speech data; otherwise returns an empty string.
resultsStringgetVirtual attribute exposed by getResults. Returns final recognition text for exactly one frame when a speech recognition pass completes; otherwise returns an empty string.

Methods

SignatureReturnsDescription
getPartialResults()StringReturns temporary recognition text on frames with new partial speech data; otherwise returns an empty string.
getResults()StringReturns final recognition text for exactly one frame when a speech recognition pass completes; otherwise returns an empty string.
getLanguage()StringReturns the speech recognition language tag.
setLanguage(String)voidSets the speech recognition language tag.
isEnableRecognition()booleanReturns whether speech recognition is enabled.
setEnableRecognition(boolean)voidSets whether speech recognition is enabled.