Fix echo cancellation android #1176
                
     Closed
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Summary
Fixes the infinite echo loop issue when using SDK
.speak()calls on Android by implementing STT (Speech-to-Text) processing pause during TTS playbook with comprehensive reliability safeguards.Note: This PR addresses the Android implementation only. iOS still needs this solution implemented.
Problem
When using SDK
.speak()calls with phone speaker + phone microphone:session.audio.speak("hello").speak()call → Infinite loopSolution
Instead of trying to disable microphone hardware (which had timing and acoustic coupling issues), this solution pauses STT processing during SDK
.speak()calls:PauseAsrEventArchitecture
SDK .speak() → Mobile AudioManagerModule → Broadcast Intent →
AugmentosService STTControlReceiver → PauseAsrEvent →
SpeechRecSwitchSystem → SpeechRecFramework.pauseAsr()
Files Changed
mobile/android/app/src/main/java/com/mentra/mentra/AudioManagerModule.java: Added STT pause/resume commands with reliability mechanismsandroid_core/app/src/main/java/com/augmentos/augmentos_core/AugmentosService.java: Added STT control BroadcastReceiver with Android 14+ compatibilityEdge Cases Handled
The solution includes comprehensive safeguards for reliability:
Failure Scenarios
playAudio()throws exceptionReliability Mechanisms
playAudio()ensures STT resumes on immediate failuresRECEIVER_NOT_EXPORTEDfor proper BroadcastReceiver registrationTest Plan
.speak()calls no longer create infinite loops.speak()calls don't cause issuesTesting App
This solution can be tested using the MentraOS Echo Test App:
https://github.com/alfonsomorab/MentraOS-Echo-App
The test app demonstrates the echo loop scenario and validates the fix across various edge cases.
Platform Support
Related Issues
Resolves #1036 - SDK .speak() infinite echo loop (Android only)