Repository navigation
Conversation
Assist intents (ACTION_ASSIST, ACTION_VOICE_COMMAND from e.g. Bluetooth headsets) now show MainActivity above the lock screen, like the wake word already does. The screen is only turned on for ACTION_ASSIST and the wake word, not for headset buttons, since the phone is usually in a pocket then. A new SttForegroundService of type microphone is started when the activity is resumed after an assist intent, and stops once the STT is not listening anymore. Without it Android silences the microphone as soon as the activity is not visible (locked phone, screen turning off while listening), so the STT only received silence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the process was killed, Android recreates MainActivity with its original launcher intent first, which preloads the Vosk model with tryLoad(null). The assist intent then arrives via onNewIntent while the model is Loading(null), and tryLoad(listener) returned false, so the first headset/assist trigger was ignored. Now the listener is attached to the ongoing loading, and listening starts once it finishes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #228 / #213:
ACTION_VOICE_COMMANDfrom a Bluetooth headset already reaches Dicio, but it only works while the phone is unlocked. With the phone locked, nothing happens, and after a cold start the first button press is ignored.What happens today (from logcat)
A long press on the headset button makes the headset send
AT+BVRA, andHeadsetService.startVoiceRecognitionByHeadsetthen startsMainActivitywithACTION_VOICE_COMMAND. This path is the same whether the phone is locked or not.MainActivityreceives the intent and starts listening, but it does not show above the keyguard (setShowWhenLockedis only used for the wake word). It is stopped about 130 ms later, and AudioFlinger silences the recording (AF::RecordTrack: setSilenced ... (silenced)), so Vosk only receives silence.MainActivitywith its original launcher intent. That preloads the Vosk model withtryLoad(null). The assist intent then arrives throughonNewIntent, while the model is stillLoading(null).tryLoad(listener)returnsfalsein that state, so the press is dropped and a second press is needed.Changes
MainActivity: assist intents (ACTION_ASSIST,ACTION_VOICE_COMMAND) now setsetShowWhenLocked(true), as the wake word already does.setTurnScreenOn(true)is used only forACTION_ASSISTand the wake word. ForACTION_VOICE_COMMAND(headsets) the screen stays off, since the phone is usually in a pocket.SttForegroundService(foregroundServiceType="microphone"). It is started fromMainActivity.onResume()after an assist intent and stops as soon as the STT is no longer listening (at most 60 s). Once the activity is not visible anymore (locked, or the screen turns off while listening), this is what keeps the microphone from being silenced. It is started only while the activity is resumed, because that is when Android 14+ allows starting a microphone foreground service.VoskInputDevice.tryLoad(): if the model isLoadingwithout a listener, the listener is attached, so listening starts once loading finishes.Tested
Android 16 phone with a Bluetooth headset that starts voice recognition via HFP:
:app:testDebugUnitTestpasses.Related, not addressed here
RecognitionServiceused by other apps (Tasker "Get Voice") with the screen off, which is a different code path. The same foreground-service approach could probably be applied toSttService, but I could not test that.🤖 Generated with Claude Code