README.md
1setup:
2
3(If a log error "VisualQueryDetector is only available if multiple detectors are allowed" , set target_sdk_version: "10000" in Android.bp for now.)
41. Set the KEYPHRASE constant in SampleVoiceInteractionService.java to something the device's
5 default assistant supports.
62. m -j SampleVoiceInteractor
74. adb root; adb remount
85. adb push development/samples/VoiceInteractionService/com.example.android.voiceinteractor.xml /system/etc/permissions/com.example.android.voiceinteractor.xml
96. adb shell mkdir /system/priv-app/SampleVoiceInteractor
107. adb push out/target/product/$TARGET_PRODUCT/system/priv-app/SampleVoiceInteractor/SampleVoiceInteractor.apk /system/priv-app/SampleVoiceInteractor/
118. adb reboot
129. Go to the sample app info/settings.
1310. Tap on Permissions and grant Mic access.
1411. Reboot.
1512. Set the "Digital assistant app" to "Sample Voice Interactor" in the Android settings
1613. Check for this in the logs to make sure it worked:
17 com.example.android.voiceinteractor I/VIS: onAvailabilityChanged: 2
1814. If it didn't, check if the pregrant worked:
19 adb shell dumpsys package com.example.android.voiceinteractor | grep CAPTURE_AUDIO_HOTWORD
20
21Iterating:
22* adb install like usual
23* If syncing changes to the system image, either first copy the permissions file into
24 out/target/product/system/etc/permissions/ or push it again after syncing. Sometimes you might
25 need to uninstall the app (go to the sample app info/settings -> 3 dots menu -> uninstall
26 updates).
27
28to test:
291. Say "1,2,Ok Poodle,3,4.."
302. Check the logs for the app and wait till it finishes recording.
313. Either check the logs for the sampled bytes to match, e.g. "sample=[95, 2, 97, ...]" should
32 appear twice; or open the sample app activity and click the button to play back the recorded
33 audio.
34Tap directRecord to simulate the non-DSP case (must be done after a dsp trigger since it
35 reuses the previous data).
36
37Debugging:
38* Set DEBUG to true in AlwaysOnHotwordDetector
39* uncomment LOG_NDEBUG lines at the top in AudioFlinger.cpp, Threads.cpp, Tracks.cpp,
40 AudioPolicyInterfaceImpl.cpp, AudioPolicyService.cpp
41* Use this logcat filter:
42 com.example.android.voiceinteractor|AlwaysOnHotword|SoundTrigger|RecordingActivityMonitor|soundtrigger|AudioPolicyManager|AudioFlinger|AudioPolicyIntefaceImpl|AudioPolicyService|VIS|SHotwordDetectionSrvc|Hotword-AudioUtils
43
44Collecting trace events: \
45Trace events are used throughout the test app to measure the time it takes to read the AudioRecord
46data in both the VoiceInteractionService and the trusted HotwordDetectionService. This section can
47be used as a guide to collect and observe this trace data.
48
49* Trace events:
50 * 'VIS.onDetected' and 'HDS.onDetected'
51 * 'VIS.createAudioRecord' and 'HDS.createAudioRecord'
52 * 'VIS.startRecording' and 'HDS.startRecording'
53 * 'AudioUtils.read' and 'AudioRecord.read'
54 * 'AudioUtils.bytesRead'
55 * Counter trace value increasing as the AudioUtils.read call progresses. This value is reset after each new call.
56
57* How to capture a trace:
58 * Follow this guide or a similar one: https://developer.android.com/topic/performance/tracing/on-device
59 * Open https://perfetto.dev/#/running.md and upload a trace report
60 * Search for the events manually or run the below example SQL query to pull out the events.
61
62* Perfetto trace SQL query
63 * How to run a SQL query: https://perfetto.dev/docs/quickstart/trace-analysis
64 * Covers both command line and HTML implementations
65```
66WITH
67 audio_events AS (
68 SELECT
69 ts,
70 (dur / 1000000) as dur_ms,
71 name
72 FROM
73 slice
74 WHERE
75 (name LIKE "%AudioUtils.read%"
76 OR name LIKE "%AudioRecord.read%"
77 OR name LIKE "%onDetected%"
78 OR name LIKE "%startRecording%"
79 OR name LIKE "%createAudioRecord%")
80 ),
81 audio_counters AS (
82 SELECT ts, name, value
83 FROM counter
84 INNER JOIN track ON counter.track_id = track.id
85 WHERE name LIKE "%AudioUtils.bytesRead%"
86 )
87SELECT ts, 'event' as type, name, dur_ms as value
88FROM audio_events
89UNION ALL
90SELECT ts, 'counter' as type, name, value
91FROM audio_counters
92ORDER BY ts
93```