MiGPT Xiaomi Voice Assistant Deployment
Deploy mi-gpt v4.2.0+ on a Xiaomi smart speaker to replace the built-in AI with a custom LLM assistant.
Prerequisites
- - Node.js >= 18
- Xiaomi account with a supported smart speaker
- An OpenAI-compatible LLM API (DashScope, DeepSeek, OpenRouter, etc.)
Quick Start
1. Initialize project
CODEBLOCK0
Create package.json:
CODEBLOCK1
CODEBLOCK2
2. Create files
app.js:
CODEBLOCK3
.env:
CODEBLOCK4
.migpt.js — See references/config-template.md for full template with comments.
3. Find your device's MIoT commands
Different speaker models use different MIoT siid/aiid values. Look up your model in mi-gpt issues or the MIoT spec.
Common values:
| Model | ttsCommand | wakeUpCommand | streamResponse |
|---|
| X08E (Redmi 8寸) | [7, 3] | [7, 1] | false |
| LX04 |
[5, 1] | [5, 3] | true |
| L05C | [5, 1] | [5, 3] | true |
| LX06 | [5, 1] | [5, 3] | true |
| L09A | [5, 1] | [5, 3] | true |
4. Run
CODEBLOCK5
Critical Issues & Fixes
Issue 1: MiNA TTS returns success but no audio (X08E and some models)
Symptom: mina.play({tts: '...'}) returns true but speaker stays silent.
Cause: Some models (notably X08E) don't support MiNA's ubus mibrain/text_to_speech. They require MIoT's doAction.
Fix: Ensure ttsCommand is set correctly. MiGPT will use MIoT doAction(siid, aiid, text) when ttsCommand is configured.
Issue 2: MIoT login triggers security verification every time
Symptom: securityStatus: 16 on every startup, even after completing SMS verification multiple times.
Root cause: mi-service-lite generates a random deviceId on every startup → Xiaomi treats each login as a new device → perpetual verification loop.
Fix: See references/miot-auth-bypass.md for the browser cookie injection method.
Issue 3: streamResponse causes hang on some models
Symptom: MiGPT says "让我想想" then freezes.
Cause: streamResponse: true polls MiNA.getStatus() for playback state. On models where MiNA doesn't control the speaker (e.g., X08E), status always returns "paused", causing the poll loop to malfunction.
Fix: Set streamResponse: false. If you also need keepAlive (continuous conversation) mode, patch enterKeepAlive() in node_modules/mi-gpt/dist/index.js to remove the streamResponse check. See references/patches.md.
Issue 4: Native 小爱 AI races with custom AI
Symptom: Both 小爱 and your custom AI respond to the same query ("split personality").
Mitigations (pick one or combine):
- 1. Set
onAIAsking: ["嗯"] — immediately interrupts 小爱 with a short TTS - Disable voice reply in 小爱 App (device settings → 语音回复 → off)
- Use 全量接管模式:
callAIKeywords: [""] — responds to all queries
Issue 5: Wake word misrecognition
Symptom: 小爱's ASR mishears custom keywords (e.g., "花卷卷" → "花姐姐").
Fix: Add common misrecognition variants to callAIKeywords and wakeUpKeywords.
LLM Model Selection
For voice assistants, latency > intelligence. Test your API endpoint:
CODEBLOCK6
Target: < 3 seconds for acceptable voice experience. Total end-to-end latency ≈ LLM time + 3-4s (polling + MIoT overhead).
Reference Files
- -
references/config-template.md — Full .migpt.js configuration template with all options explained - INLINECODE27 — Browser cookie injection to bypass MIoT security verification
- INLINECODE28 — Required code patches for mi-gpt and mi-service-lite
- INLINECODE29 — End-to-end latency breakdown and optimization tips
MiGPT 小米语音助手部署
在小米智能音箱上部署 mi-gpt v4.2.0+,用自定义 LLM 助手替换内置 AI。
前置条件
- - Node.js >= 18
- 拥有支持的小米智能音箱的小米账号
- 兼容 OpenAI 的 LLM API(DashScope、DeepSeek、OpenRouter 等)
快速开始
1. 初始化项目
bash
mkdir -p ~/projects/mi-gpt && cd ~/projects/mi-gpt
创建 package.json:
json
{
type: module,
dependencies: { dotenv: ^17.0.0, mi-gpt: ^4.2.0 }
}
bash
npm install
2. 创建文件
app.js:
js
import dotenv/config;
import config from ./.migpt.js;
import { MiGPT } from mi-gpt;
const client = MiGPT.create(config);
await client.start();
.env:
bash
OPENAI_MODEL=your-model
OPENAIAPIKEY=sk-xxx
OPENAIBASEURL=https://your-api-endpoint/v1
.migpt.js — 完整带注释模板请参见 references/config-template.md。
3. 查找设备的 MIoT 指令
不同音箱型号使用不同的 MIoT siid/aiid 值。请在 mi-gpt issues 或 MIoT 规范 中查找您的型号。
常见值:
| 型号 | ttsCommand | wakeUpCommand | streamResponse |
|---|
| X08E(Redmi 8寸) | [7, 3] | [7, 1] | false |
| LX04 |
[5, 1] | [5, 3] | true |
| L05C | [5, 1] | [5, 3] | true |
| LX06 | [5, 1] | [5, 3] | true |
| L09A | [5, 1] | [5, 3] | true |
4. 运行
bash
nohup node app.js > migpt.log 2>&1 &
关键问题及修复
问题 1:MiNA TTS 返回成功但无音频(X08E 及部分型号)
症状:mina.play({tts: ...}) 返回 true,但音箱静默无声。
原因:部分型号(尤其是 X08E)不支持 MiNA 的 ubus mibrain/texttospeech,需要使用 MIoT 的 doAction。
修复:确保正确设置 ttsCommand。配置 ttsCommand 后,MiGPT 将使用 MIoT doAction(siid, aiid, text)。
问题 2:MIoT 登录每次触发安全验证
症状:每次启动时出现 securityStatus: 16,即使多次完成短信验证。
根本原因:mi-service-lite 每次启动生成随机 deviceId → 小米将每次登录视为新设备 → 永久验证循环。
修复:参见 references/miot-auth-bypass.md 中的浏览器 Cookie 注入方法。
问题 3:streamResponse 导致部分型号卡死
症状:MiGPT 说让我想想后卡住。
原因:streamResponse: true 轮询 MiNA.getStatus() 获取播放状态。在 MiNA 无法控制音箱的型号上(如 X08E),状态始终返回 paused,导致轮询循环异常。
修复:设置 streamResponse: false。如果还需要 keepAlive(连续对话)模式,请修改 node_modules/mi-gpt/dist/index.js 中的 enterKeepAlive() 函数,移除 streamResponse 检查。详见 references/patches.md。
问题 4:原生小爱 AI 与自定义 AI 冲突
症状:小爱和自定义 AI 同时响应同一查询(人格分裂)。
缓解措施(任选或组合使用):
- 1. 设置 onAIAsking: [嗯] — 立即用短 TTS 打断小爱
- 在小爱 App 中关闭语音回复(设备设置 → 语音回复 → 关闭)
- 使用全量接管模式:callAIKeywords: [] — 响应所有查询
问题 5:唤醒词识别错误
症状:小爱的 ASR 误识别自定义关键词(例如花卷卷→花姐姐)。
修复:将常见误识别变体添加到 callAIKeywords 和 wakeUpKeywords。
LLM 模型选择
对于语音助手,延迟比智能更重要。测试您的 API 端点:
bash
time curl -s --max-time 15 YOURBASEURL/chat/completions \
-H Authorization: Bearer YOUR_KEY \
-H Content-Type: application/json \
-d {model:MODEL,messages:[{role:user,content:一句话回答:今天星期几}],max_tokens:30}
目标:< 3 秒以获得可接受的语音体验。总端到端延迟 ≈ LLM 时间 + 3-4 秒(轮询 + MIoT 开销)。
参考文件
- - references/config-template.md — 完整的 .migpt.js 配置模板,包含所有选项说明
- references/miot-auth-bypass.md — 浏览器 Cookie 注入以绕过 MIoT 安全验证
- references/patches.md — mi-gpt 和 mi-service-lite 所需的代码补丁
- references/latency-analysis.md — 端到端延迟分解及优化建议