Mohammad Faizan
Mohammad Faizan

Reputation: 844

Can I run voice recognition, speaker output, and continuous audio recording simultaneously on Android without issues?

I'm developing an Android app where I need to have voice recognition, play audio through the speaker, and continuously record audio from the microphone simultaneously. The components I’m using include:

I have implemented the code for this functionality. Still, I’m experiencing performance issues where the phone's audio and video playback become choppy and stick for a few seconds approximately every 5 seconds. This disruption occurs even when I try to manage audio focus.

Here are my specific questions:

  1. How can I handle audio focus properly when both SpeechRecognizer and MediaPlayer are active alongside the continuous AudioRecord?
  2. Is it feasible to run AudioRecord continuously while also using SpeechRecognizer without causing conflicts or errors?
  3. Are there recommended best practices for prioritizing and managing these audio sources in Android, especially when the microphone must always be active?
  4. What could be causing the audio and video playback issues, and how can I mitigate them?

Here’s a simplified version of what I’m trying to achieve:

The SpeechRecognizer listens for commands. Depending on the recognized commands, I play an audio response using MediaPlayer. AudioRecord runs continuously in the background to capture audio.

Any advice, insights, or code samples for effectively managing these audio components while ensuring smooth performance would be greatly appreciated!

Upvotes: 1

Views: 56

Answers (1)

HaxOfficial
HaxOfficial

Reputation: 130

Unfortunately, the SpeechRecognizer class doesn't have a property to listen continuously. This is why, when you play a video, you may notice issues with the play/pause functionality. The SpeechRecognizer stops listening for commands because it triggers the onEndOfSpeech() event, causing it to stop listening, and the video continues to play. If you restart the SpeechRecognizer, the video will pause again, and the SpeechRecognizer will start listening for commands, but only for a few minutes before stopping again.

To answer your question: Yes, you can achieve continuous listening, but not with SpeechRecognizer. For this functionality, I recommend using a continuous listening library like the Vosk library.

If you need help with this, feel free to ask. I've used this library before and can guide you through it.

For Source : Click Here

Upvotes: 0

Related Questions