Feature: Support voice monitoring on Android hosts
The master's voice monitoring menu sends COMMAND_AUDIO; the client opens a ConnAuth sub-connection with TOKEN_AUDIO_START, the server opens CAudioDlg and answers COMMAND_NEXT, then audio flows both ways. The protocol matches the Windows client, so the server needs no changes. The server's ACM format was read from Audio.cpp and AudioDlg.cpp first: WAVE_FORMAT_GSM610, 8000 Hz mono, 65-byte blocks of 320 samples (40 ms), about 1625 B/s. libgsm 1.0.13 (AOSP external/libgsm mirror) is vendored under cpp/gsm and built with -DSASR -DWAV49 so its MS-GSM packing is byte-identical to ACM GSM610. Encode and decode use separate gsm states because frame_index/frame_chain live in the state. Uplink packets are always exactly 1000 bytes: CAudio::PlayBuffer copies 1000 bytes from the buffer start regardless of packet length, so a short packet would over-read. Since 1000 is not a multiple of 65, blocks straddle packets; the stream is continuous and codec state carries over. AudioMonitor.kt owns AudioRecord (8 kHz/16-bit/mono, 320 samples a read) and AudioTrack playback of decoded downlink PCM. RECORD_AUDIO is requested with POST_NOTIFICATIONS before the projection dialog, and CaptureService adds the microphone FGS type only when held, falling back on failure. An 8-second dialog wait or missing microphone reports a tip to the master instead of failing silently. Verified on an Android 15 emulator against the Debug server: dialog opened, uplink started, server receive counter grew at ~1.6 KB/s. Downlink playback was not exercised (the test machine has no recording device); that path is code-reviewed only. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
3ab5154db1
commit
4aedca8ee0
31 files changed
+4979
-22
No files matched your search
@@ -200,6 +200,46 @@ AI 无法「看懂」视频流。把 25fps 的远程画面直接丢给视觉模
|
||||
默认 `bitRate` 是 0(Windows 走 DIFF/RGB565 软编),Android 按改动前的 4000 kbps 回退;
|
||||
主控端在自定义表里给了码率则以它为准。
|
||||
|
||||
### 5.5 语音监听(Android 主机)
|
||||
|
||||
主控端「语音监听」(`IDM_ONLINE_AUDIO` → `COMMAND_AUDIO`)在服务端是 `CAudioDlg`:客户端
|
||||
开子连接后发单字节 `TOKEN_AUDIO_START`,对话框 `OnInitDialog` 回 `COMMAND_NEXT`,随后双向
|
||||
音频。**协议与 Windows 客户端完全相同,服务端零改动**;Android 侧只补了音频编解码与采集。
|
||||
|
||||
音频格式先按服务端实现核实(`client/Audio.cpp` / `server/2015Remote/AudioDlg.cpp`):
|
||||
|
||||
- 服务端 ACM 用 `WAVE_FORMAT_GSM610`:8000 Hz 单声道、`nBlockAlign=65`、
|
||||
`wSamplesPerBlock=320`(40 ms/块)、平均 1625 B/s;
|
||||
- 上行是 `[TOKEN_AUDIO_DATA][1000 字节 GSM 流]`,且**必须是整 1000 字节**:
|
||||
`CAudio::PlayBuffer` 固定从缓冲起点 `memcpy` 1000 字节,短包会越界读;
|
||||
- 1000 不是 65 的整数倍,65 字节块会跨包切开,音频流本身是连续的;
|
||||
- 下行是裸 GSM 流(无 token),服务端按 1000 字节一块发。
|
||||
|
||||
客户端实现(`cpp/AudioHandler.h` + `AudioMonitor.kt`,libgsm 随包编译):
|
||||
|
||||
| 环节 | 做法 |
|
||||
|---|---|
|
||||
| 编解码 | gsm-1.0.13,`-DSASR -DWAV49`(与 AOSP 同参)。WAV49 每块 = 2×160 采样帧:前 32 字节 + 后 33 字节,与 ACM GSM610 完全一致。编码/解码**各用一个 `gsm` 状态**(`frame_index`/`frame_chain` 是状态的一部分) |
|
||||
| 上行 | `AudioRecord`(8 kHz/16bit/单声道) 每 320 采样 → 攒 2 帧成 65 字节 → 攒满 1000 字节发一包(≈615 ms,与 Windows 客户端同延迟) |
|
||||
| 下行 | 按 65 字节块对齐解码成 320 采样 → `AudioTrack` 播放;主控不勾「发送语音」时没有下行 |
|
||||
| 失败回报 | 客户端等 `COMMAND_NEXT` 最多 8 秒(同 Windows);超时或录音不可用时发 `TOKEN_CLIENT_MSG` 给主控,不静默 |
|
||||
|
||||
权限与平台限制:`RECORD_AUDIO` 运行时授权(`MainActivity` 与通知权限合并成一次请求,结果
|
||||
回来后再弹录屏授权,避免两个系统框叠在一起);Android 11+ 后台采集要求前台服务带
|
||||
`microphone` 类型,`CaptureService` 在 `RECORD_AUDIO` 已授权时把它并入
|
||||
`startForeground` 的类型位,失败(例如进程已在后台)回退到原类型,远程控制本身不受影响。
|
||||
麦克风不可用时主控侧只看到「Receive 0 KBytes」,客户端会回一条提示。
|
||||
|
||||
已验证(Android 15 模拟器 + Debug 服务端):主控打开语音监听后对话框正常弹出,客户端
|
||||
`YAMA_AUD` 依次出现 `dialog open (COMMAND_NEXT)` → `audio monitor started` →
|
||||
`first uplink packet sent`,服务端 "Receive N KBytes" 以约 1.6 KB/s 稳定增长(≈1000 字节/
|
||||
615 ms),关闭对话框后子连接与采集线程正常退出。**下行(主控→客户端)播放未实测**:测试机
|
||||
没有可用的录音设备,服务端勾选「Send local audio」后 `GetRecordBuffer` 无数据,客户端解码
|
||||
路径只做了代码核对。
|
||||
|
||||
`COMMAND_AUDIO` 没有对应的 MCP 工具(语音是人在主控端实时听,AI 用不上),所以本项只做到
|
||||
与主控 UI 对齐。
|
||||
|
||||
---
|
||||
|
||||
## 6. 输入注入(Act)
|
||||
|
||||
Reference in new issue
Block a user