156 lines
8.7 KiB
Markdown
156 lines
8.7 KiB
Markdown
# YX_Voice 架构文档
|
|||
|
|
|
||
|
|
## 1. 概述
|
||
|
|
|
||
|
|
YX_Voice 是车载语音助手服务模块,作为第三方语音助手(同行者TXZ)与车载各功能模块之间的桥梁,负责语音指令的分发、处理以及车辆状态的同步。
|
||
|
|
|
||
|
|
| 项目信息 | 说明 |
|
||
|
|
|----------|------|
|
||
|
|
| 包名 | `com.yaxon.voice` |
|
||
|
|
| 应用类型 | Android System Application |
|
||
|
|
| 进程类型 | 系统持久化进程 (`persistent=true`) |
|
||
|
|
| 共享UID | `android.uid.system` |
|
||
|
|
|
||
|
|
## 2. 整体架构
|
||
|
|
|
||
|
|
```
|
||
|
|
┌─────────────────────────────────────────────────────────────────────┐
|
||
|
|
│ YX_Voice 架构图 │
|
||
|
|
├─────────────────────────────────────────────────────────────────────┤
|
||
|
|
│ │
|
||
|
|
│ ┌──────────────┐ TXZ协议 ┌──────────────────────────────┐ │
|
||
|
|
│ │ TXZ语音 │◄────────────►│ VoiceService │ │
|
||
|
|
│ │ 助手模块 │ │ (服务入口 & TXZ连接管理) │ │
|
||
|
|
│ └──────────────┘ └──────────────┬───────────────┘ │
|
||
|
|
│ │ │
|
||
|
|
│ ┌──────────────────────────┼────────────────┐ │
|
||
|
|
│ │ │ │ │
|
||
|
|
│ ▼ ▼ ▼ │
|
||
|
|
│ ┌──────────────────────┐ ┌──────────────────────┐ ┌──────────┐│
|
||
|
|
│ │ ProtocolManager │ │ VoiceManager │ │ Helpers ││
|
||
|
|
│ │ (协议分发管理) │ │ (核心状态管理) │ │ (辅助类) ││
|
||
|
|
│ └──────────┬───────────┘ └──────────┬───────────┘ └──────────┘│
|
||
|
|
│ │ │ │
|
||
|
|
│ ▼ ▼ │
|
||
|
|
│ ┌──────────────────────────────────────────────────────────────┐ │
|
||
|
|
│ │ Protocol Implementations │ │
|
||
|
|
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌────────┐ │ │
|
||
|
|
│ │ │ Voice │ │ Air │ │ Setting │ │ Media │ │ Car │ │ │
|
||
|
|
│ │ │Protocol │ │Protocol │ │Protocol │ │Protocol │ │Control │ │ │
|
||
|
|
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └────────┘ │ │
|
||
|
|
│ └──────────────────────────────────────────────────────────────┘ │
|
||
|
|
│ │
|
||
|
|
│ ┌──────────────────────────────────────────────────────────────┐ │
|
||
|
|
│ │ IPC Communication Layer │ │
|
||
|
|
│ │ YxIPC (跨进程通信框架) │ │
|
||
|
|
│ └──────────────────────────┬───────────────────────────────────┘ │
|
||
|
|
│ │ │
|
||
|
|
│ ┌───────────────────────┼───────────────────────┐ │
|
||
|
|
│ ▼ ▼ ▼ │
|
||
|
|
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
|
||
|
|
│ │ 音乐 │ │ 设置 │ │ 空调 │ │
|
||
|
|
│ │ 模块 │ │ 模块 │ │ 模块 │ │
|
||
|
|
│ └─────────┘ └─────────┘ └─────────┘ │
|
||
|
|
│ │
|
||
|
|
└─────────────────────────────────────────────────────────────────────┘
|
||
|
|
```
|
||
|
|
|
||
|
|
## 3. 模块分层
|
||
|
|
|
||
|
|
| 层级 | 模块 | 职责 |
|
||
|
|
|------|------|------|
|
||
|
|
| 应用层 | VoiceService | 服务入口、生命周期管理 |
|
||
|
|
| 核心层 | ProtocolManager, VoiceManager | 协议分发、状态管理 |
|
||
|
|
| 协议层 | BaseProtocol及子类 | 具体协议解析与执行 |
|
||
|
|
| 辅助层 | Helpers, Receivers, Observers | 状态监听、辅助功能 |
|
||
|
|
| 通信层 | YxIPC, TxzProtocolManager | 跨进程通信 |
|
||
|
|
|
||
|
|
## 4. 核心模块
|
||
|
|
|
||
|
|
| 模块 | 职责 | 设计模式 |
|
||
|
|
|------|------|----------|
|
||
|
|
| VoiceService | 与TXZ语音助手建立连接、接收并分发语音指令 | - |
|
||
|
|
| ProtocolManager | 实现IPC消息监听接口、将消息分发给协议处理器 | 单例模式 |
|
||
|
|
| YxProtocolHandler | 维护包名到协议逻辑类的映射、在后台线程处理协议分发 | - |
|
||
|
|
| VoiceManager | 管理TXZ绑定状态、AVM/DVR前台状态、注册车辆状态回调 | 单例模式 |
|
||
|
|
| VoiceEventHelper | 封装所有语音控制操作、与各模块进行IPC通信 | - |
|
||
|
|
|
||
|
|
## 5. 通信架构
|
||
|
|
|
||
|
|
### 5.1 协议处理流程
|
||
|
|
|
||
|
|
```
|
||
|
|
TXZ语音指令
|
||
|
|
│
|
||
|
|
▼
|
||
|
|
TxzProtocolManager.setDefaultHandler()
|
||
|
|
│
|
||
|
|
├── 解析 commandType (协议名称)
|
||
|
|
├── 解析 Bundle 参数
|
||
|
|
├── 转换为JSON格式
|
||
|
|
│
|
||
|
|
▼
|
||
|
|
ProtocolManager.onResponse()
|
||
|
|
│
|
||
|
|
▼
|
||
|
|
YxProtocolHandler.onHandleProtocol()
|
||
|
|
│
|
||
|
|
▼
|
||
|
|
具体Protocol实现类.onProtocolLogic()
|
||
|
|
```
|
||
|
|
|
||
|
|
### 5.2 IPC通信
|
||
|
|
|
||
|
|
```
|
||
|
|
┌─────────────────┐ YxIPC ┌─────────────────┐
|
||
|
|
│ YX_Voice │◄──────────────►│ YX_Music │
|
||
|
|
│ (Server) │ │ (Client) │
|
||
|
|
└────────┬────────┘ └─────────────────┘
|
||
|
|
│
|
||
|
|
│ YxIPC
|
||
|
|
▼
|
||
|
|
┌─────────────────┐
|
||
|
|
│ YX_Setting │
|
||
|
|
└─────────────────┘
|
||
|
|
```
|
||
|
|
|
||
|
|
### 5.3 TXZ协议通信
|
||
|
|
|
||
|
|
```
|
||
|
|
┌─────────────────┐ TxzProtocolManager ┌─────────────────┐
|
||
|
|
│ YX_Voice │◄─────────────────────►│ TXZ语音助手 │
|
||
|
|
│ (ConnectionService) │ (AIDL Service) │
|
||
|
|
└─────────────────┘ └─────────────────┘
|
||
|
|
```
|
||
|
|
|
||
|
|
## 6. 模块依赖
|
||
|
|
|
||
|
|
```
|
||
|
|
YX_Voice
|
||
|
|
├── YX_IPC_SDK (IPC通信)
|
||
|
|
├── YX_Lib_CommonBase (公共基础库)
|
||
|
|
├── YX_AutoMotiveSDK (车载SDK)
|
||
|
|
├── library-release-0127.aar (TXZ协议库)
|
||
|
|
├── tools.jar (工具库)
|
||
|
|
├── framework_classes.jar (系统框架)
|
||
|
|
└── serial-0.1.6_classes.jar (串口库)
|
||
|
|
```
|
||
|
|
|
||
|
|
## 7. 包名依赖
|
||
|
|
|
||
|
|
| 包名 | 说明 |
|
||
|
|
|------|------|
|
||
|
|
| com.txzing.voiceassistant | TXZ语音助手 |
|
||
|
|
| com.yaxon.music | 音乐模块 |
|
||
|
|
| com.yaxon.radio | 收音机模块 |
|
||
|
|
| com.yaxon.hvac | 空调模块 |
|
||
|
|
| com.yaxon.bluetooth | 蓝牙模块 |
|
||
|
|
| com.yaxon.setting | 设置模块 |
|
||
|
|
| com.yaxon.carcontrol | 车辆控制模块 |
|
||
|
|
| com.yaxon.avm | 360环视模块 |
|
||
|
|
| com.yaxon.dvr | 行车记录仪模块 |
|
||
|
|
| com.android.systemui | 系统UI |
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
*文档整理日期: 2026-05-27*
|