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
| Signature | Description |
|---|---|
SpeechRecognizer() | Creates a new instance of SpeechRecognizer. |
Virtual Attributes
| Name | Type | Access | Description |
|---|---|---|---|
enableRecognition | boolean | get/set | Virtual attribute exposed by isEnableRecognition. Access it like a field to read or write the underlying value. |
language | String | get/set | Virtual attribute exposed by getLanguage. Use a BCP-47 language tag such as pt-BR. |
partialResults | String | get | Virtual attribute exposed by getPartialResults. Returns temporary recognition text on frames with new partial speech data; otherwise returns an empty string. |
results | String | get | Virtual attribute exposed by getResults. Returns final recognition text for exactly one frame when a speech recognition pass completes; otherwise returns an empty string. |
Methods
| Signature | Returns | Description |
|---|---|---|
getPartialResults() | String | Returns temporary recognition text on frames with new partial speech data; otherwise returns an empty string. |
getResults() | String | Returns final recognition text for exactly one frame when a speech recognition pass completes; otherwise returns an empty string. |
getLanguage() | String | Returns the speech recognition language tag. |
setLanguage(String) | void | Sets the speech recognition language tag. |
isEnableRecognition() | boolean | Returns whether speech recognition is enabled. |
setEnableRecognition(boolean) | void | Sets whether speech recognition is enabled. |