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