# Class SpeechRecognizer

java.lang.Object
com.codename1.media.SpeechRecognizer

public final class SpeechRecognizer extends java.lang.Object

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);
            }
        });
    }

- ## Method Summary

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

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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(RecognitionOptions, RecognitionCallback)`.

  - ### 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.