From 37a8f28d6bfc4c5a10bbe22b53b3ea122da6d776 Mon Sep 17 00:00:00 2001 From: Adam Vongrej Date: Tue, 1 Oct 2024 20:28:17 +0200 Subject: [PATCH] Map ListenMode.search to web_search language model in Android (#557) --- .../speech_to_text/SpeechToTextPlugin.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/speech_to_text/android/src/main/kotlin/com/csdcorp/speech_to_text/SpeechToTextPlugin.kt b/speech_to_text/android/src/main/kotlin/com/csdcorp/speech_to_text/SpeechToTextPlugin.kt index 7dac9c9..16de409 100644 --- a/speech_to_text/android/src/main/kotlin/com/csdcorp/speech_to_text/SpeechToTextPlugin.kt +++ b/speech_to_text/android/src/main/kotlin/com/csdcorp/speech_to_text/SpeechToTextPlugin.kt @@ -267,15 +267,14 @@ public class SpeechToTextPlugin : result.success(false) return } + var listenMode = enumValues()[listenModeIndex] + resultSent = false - createRecognizer(onDevice) + createRecognizer(onDevice, listenMode) minRms = 1000.0F maxRms = -100.0F debugLog("Start listening") - var listenMode = ListenMode.deviceDefault - if ( listenModeIndex == ListenMode.dictation.ordinal) { - listenMode = ListenMode.dictation - } + optionallyStartBluetooth() setupRecognizerIntent(languageTag, partialResults, listenMode, onDevice ) handler.post { @@ -570,7 +569,7 @@ public class SpeechToTextPlugin : return list.firstOrNull()?.serviceInfo?.let { ComponentName(it.packageName, it.name) } } - private fun createRecognizer(onDevice: Boolean) { + private fun createRecognizer(onDevice: Boolean, listenMode: ListenMode) { if ( null != speechRecognizer && onDevice == lastOnDevice ) { return } @@ -617,7 +616,7 @@ public class SpeechToTextPlugin : } } debugLog("before setup intent") - setupRecognizerIntent(defaultLanguageTag, true, ListenMode.deviceDefault, false ) + setupRecognizerIntent(defaultLanguageTag, true, listenMode, false ) debugLog("after setup intent") } @@ -633,7 +632,12 @@ public class SpeechToTextPlugin : run { recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply { debugLog("In RecognizerIntent apply") - putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) + if (listenMode == ListenMode.search) { + putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH) + } + else { + putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) + } debugLog("put model") val localContext = pluginContext if (null != localContext) {