Class SpeechRecognizer
java.lang.Object
com.codename1.media.SpeechRecognizer
On-device speech-to-text.
- iOS -- backed by
SFSpeechRecognizer. The first call prompts the user for microphone + speech-recognition permission (the latter requiresNSSpeechRecognitionUsageDescriptionin 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-whisperto enable on-device transcription via whisper.cpp, or expectisSupported()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 TypeMethodDescriptionstatic booleanTrue when the current platform implements on-device or platform-bundled speech recognition.static voidrecognize(RecognitionOptions options, RecognitionCallback callback) Starts a recognition session.static voidrecognizeOnce(RecognitionCallback callback) Captures one utterance with default options (RecognitionOptionsen-US, partial results on, max 1 alternative).static voidstop()Stops the active recognition session, if any.
-
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
Captures one utterance with default options (RecognitionOptionsen-US, partial results on, max 1 alternative). Convenience wrapper aroundrecognize(RecognitionOptions, RecognitionCallback). -
recognize
Starts a recognition session. UseRecognitionOptions.setContinuous(boolean)to keep listening across silences. Callstop()to end a continuous session. -
stop
public static void stop()Stops the active recognition session, if any. No-op when none.
-