Skip to content

Commit

Permalink
Map ListenMode.search to web_search language model in Android (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
vongrad authored Oct 1, 2024
1 parent 69ec729 commit 37a8f28
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,14 @@ public class SpeechToTextPlugin :
result.success(false)
return
}
var listenMode = enumValues<ListenMode>()[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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}

Expand All @@ -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) {
Expand Down

0 comments on commit 37a8f28

Please sign in to comment.