SpeechRecognizer causes ANR… I need help with Android speech API

后端 未结 6 1159
一生所求
一生所求 2020-12-01 02:14

EDIT: I should have mentioned this already, but I\'m running this code in a service. The entire app is turned on/off by a widget button and has no activity.

6条回答
  •  失恋的感觉
    2020-12-01 02:53

    You shouldn't need to create the SpeechRecognizer class yourself, nor do you need to implement a RecognizerListener. Google made them public to be nice, but they look pretty complicated and probably for use by experts only.

    To get text from the users speech yo simply need to use the RecognizerIntent.ACTION_RECOGNIZE_SPEECH to launch the built-in speech recognizer Activity and then wait for the result to come back in onActivityResult. Take a look at the example code here:

    http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html

    I pulled it from this article.

    http://developer.android.com/resources/articles/speech-input.html

    Good Luck.

提交回复
热议问题