Speech Recognition Service in Android

2019-03-30 10:01发布

问题:

I have an Android application that uses speech recognition in an Activity. The GUI doesn't do anything except for contain the speech recognition objects. I would like to port this over to a service so I can talk to the application while it's running in the background.

However, as far as I know, the speech recognition service has to use onActivityResult, which is unavailable for Services. Is there a way to either contain an Activity in a Service such that its GUI is not displayed, or perform speech recognition in a service instead of an activity?

回答1:

See Google's voice search speech recognition service - it might have some useful links to information. I don't think you can do non-Gui voice recognition because the recognizer is only exposed as the recognizer intent.

I don't think that Google wants people to call this service directly, and it likely violates some terms of service somewhere if you do, but check out http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/ to see the service behind Chrome speech recognition which I suspect is similar to Android.



回答2:

what if you have your service wake up an activity when it detects any incoming audio signal,

that acts like a widget only taking up a small part of the screen or even just a single pixel, then call voice recognition from the invisible activity?

Just an idea, I don't remember if a widget can be an activity or if you can make an activity that doesn't take up the screen.