Reputation: 31
I've built a voice-driven android app that uses the android speech recognition API. I'm currently trying to convert the app to a wear-os version. I've included the speech recognition permission in the apps manifest and have initialized the speech recognition instance the same as I have in the mobile app (which works!). The app launches well, however when I begin the speech recognition I get the following error: E/SpeechRecognizer: no selected voice recognition service
I've tested on both a physical Galaxy 5 watch, and an API 30 wear-os emulator and the problem occurs with both devices. I've installed google assistant on the devices, and google assistants voice recognition works well. I can't find and voice input / speech recognition settings on the app. I'm not sure what next steps to take in debugging this.
Upvotes: 3
Views: 742
Reputation: 45
This worked for me when using speech recognition on Android 11 in Wear OS:
private fun checkPermissions() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.RECORD_AUDIO),
REQUEST_MICROPHONE_PERMISSION
)
}
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int,
data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_SPEECH_INPUT && resultCode ==
Activity.RESULT_OK && data != null) {
val results =
data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
val spokenText = results?.firstOrNull()
spokenText?.let {
sendRequest(it)
}
}
}
@SuppressLint("SetTextI18n", "InflateParams")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.RECORD_AUDIO
) != PackageManager.PERMISSION_GRANTED
) {
checkPermissions()
}
val voiceButton = findViewById<ImageButton>(R.id.voiceButton)
voiceButton.setOnClickListener {
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
// on below line we are passing language model
// and model free form in our intent
intent.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
// on below line we are passing our
// language as a default language.
intent.putExtra(
RecognizerIntent.EXTRA_LANGUAGE, "en-US"
)
// on below line we are specifying a prompt
// message as speak to text on below line.
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak to
text")
try {
startActivityForResult(intent,
REQUEST_CODE_SPEECH_INPUT)
} catch (e: Exception) {
// on below line we are displaying error message in
toast
Toast
.makeText(
this@MainActivity, " " + e.message,
Toast.LENGTH_SHORT
)
.show()
}
}
Upvotes: 1
Reputation: 136
Changes to SpeechRecognition in API Level 30
I have the same problem: Testing it on an android 30 emulator prints "no selected voice recognition service". However, testing it on an emulator running API version 28 works just fine.
I asked for user permission and specified an intent in the "queries"-Part of AndroidManifest.xml it still doesnt work. It seems to be an API Problem.
Upvotes: 0