public final class SpeechRecognizer

  1. Object
  2. SpeechRecognizer

On-device speech-to-text.

  • iOS – backed by SFSpeechRecognizer. The first call prompts the user for microphone + speech-recognition permission (the latter requires NSSpeechRecognitionUsageDescription in Info.plist, which the build server injects automatically when this class is referenced).
  • Android – backed by android.speech.SpeechRecognizer. May use Google’s cloud speech endpoint on older devices; on Pixel and modern flagships it runs fully on-device.
  • JavaSE simulator – no built-in implementation. Add cn1-ai-whisper to enable on-device transcription via whisper.cpp, or expect isSupported to return false.
if (SpeechRecognizer.isSupported()) {
    SpeechRecognizer.recognizeOnce(new RecognitionCallback.Adapter() {
        public void onResult(String t, float c, String[] a) {
            form.findTextField().setText(t);
        }
    });
}

Methods

public static boolean isSupported()True when the current platform implements on-device or platform-bundled speech recognition.
public static void recognizeOnce(RecognitionCallback callback)Captures one utterance with default options (RecognitionOptions en-US, partial results on, max 1 alternative).
public static void recognize(RecognitionOptions options, RecognitionCallback callback)Starts a recognition session.
public static void stop()Stops the active recognition session, if any.

Inherited methods

Method details

isSupported

public static boolean isSupported()
True when the current platform implements on-device or platform-bundled speech recognition. Even when true, the user may still deny permission at runtime.

recognizeOnce

public static void recognizeOnce(RecognitionCallback callback)
Captures one utterance with default options (RecognitionOptions en-US, partial results on, max 1 alternative). Convenience wrapper around recognize.

recognize

public static void recognize(RecognitionOptions options, RecognitionCallback callback)
Starts a recognition session. Use RecognitionOptions.setContinuous(boolean) to keep listening across silences. Call stop() to end a continuous session.

stop

public static void stop()
Stops the active recognition session, if any. No-op when none.