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
    True when the current platform implements on-device or platform-bundled speech recognition.
    static void
    Starts a recognition session.
    static void
    Captures one utterance with default options (RecognitionOptions en-US, partial results on, max 1 alternative).
    static void
    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