[Feature] 支持安卓端语音输入功能
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 395
- Avg merge
- 21h 48m
- Merged PRs (30d)
- 776
Description
## 使用场景
Android 用户希望在远程会话输入框中通过说话快速输入消息,并将识别结果插入当前草稿后发送。
## 当前问题
当前仓库已经具备:
- `@cindy/voice-input-core` 语音听写状态机;
- Mobile 侧 ASR、草稿投影和语音交互逻辑;
- iOS `AVAudioEngine` 实时 PCM 录音实现;
- Android 麦克风权限配置。
但 `xdt-mobile-realtime-audio` 仅支持 Apple 平台,Android 没有原生实时 PCM 录音实现,因此 Android 无法真正开始语音输入。
## 期望方案
1. 为 `xdt-mobile-realtime-audio` 增加 Android 原生实现,提供与 iOS 一致的 `start`、`stop`、`prewarm`、`onAudioChunk` 和 `onAudioError` 接口。
2. 使用 Android 原生录音能力持续输出 PCM16 音频块,默认支持 16 kHz 采样率。
3. 将 Expo module 配置扩展为 Android,并处理麦克风权限、前后台切换、录音中断和资源释放。
4. 复用现有 `mobileRealtimeAudio`、`mobileVoiceController` 与 `voice-input-core`,避免新增另一套语音状态机。
5. 在 Android 真机上验证录音、停止、ASR 转写、权限拒绝、后台切换和异常恢复。
6. 在 Android 原生能力未就绪的安装包中继续隐藏语音入口。
## 已考虑的替代方案
直接使用文件录音只能得到完整音频文件,无法满足当前控制器所需的实时 PCM 分片输入;除非 `expo-audio` 能提供稳定的实时 PCM 流,否则仍需要 Android 原生 `AudioRecord` 或等价实现。
## 验收标准
- Android 真机可以完成语音输入并将转写文本写入草稿。
- 支持开始、停止、取消、权限拒绝和录音中断。
- 新建会话与已有会话行为一致。
- iOS 现有功能不回归。
- 无原生录音能力的构建仍不会显示语音入口。
Contributor guide
Research direction
Start by reading the existing xdt-mobile-realtime-audio iOS implementation and the mobileRealtimeAudio, mobileVoiceController, and voice-input-core entry points. Use Android AudioRecord as the reference for realtime PCM16 chunks, then verify permission handling, interruptions, lifecycle changes, and cleanup on a physical Android device. Done means transcription reaches the draft, unsupported builds hide the entry point, and iOS behavior is unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, react-native, typescript
- Domain
- audio-video-rtc, mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100