Smart voice notification system for Xiaomi speakers, using MiService and Piper TTS.
2.9K
The Voice of Your Code.
你的代码,掷地有声!
通过 Docker 运行的智能语音播报系统,使用 MiService + Piper TTS 实现小米音箱播报任何自定义消息。支持 GitHub Actions 集成、API 调用等多种触发方式。
graph TD
A[External Trigger] -->|Webhook/API| B[Cloudflare Tunnel]
B -->|HTTPS| C[FastAPI Server :2010]
C -->|Generate| D[Piper TTS]
D -->|Save| E[Audio Cache]
C -->|Control| F[MiService]
E -->|HTTP :1810| G[Static Server]
G -->|Download| F
F -->|Play| H[Xiaomi Speaker]
C -->|Fallback| I[Speaker Built-in TTS]
I -->|Play| H
A1[GitHub Actions] -.->|Example| A
A2[Custom Scripts] -.->|Example| A
A3[Other Services] -.->|Example| A
style C fill:#e1f5ff
style D fill:#d4f1d4
style G fill:#fff4e1
style H fill:#ffe1e1
cp .env.example .env
vim .env
# 先在 .env 中设置 MI_USER 和 MI_PASS,然后运行以下命令获取设备列表
docker run --rm --env-file .env palemoky/xiaomi-speaker:latest micli list
从输出中找到你的音箱设备 ID(支持 UUID、数字 DID 或设备名称),填入 .env 文件的 MI_DID 字段。
docker-compose up -d
服务将在以下端口启动:
http://localhost:2010http://localhost:1810curl -X POST http://localhost:2010/webhook/custom \
-H "Content-Type: application/json" \
-H "Speaker-API-Secret: your_api_secret" \
-H "CF-Access-Client-Id: your_cf_client_id" \
-H "CF-Access-Client-Secret: your_cf_client_secret" \
-d '{"message": "测试通知"}'
如果配置正确,音箱应该会播报"测试通知"。
如果遇到 KeyError: 'userId' Login failed 登录错误,请参照 https://github.com/Yonsm/MiService/issues/57#issuecomment-2869640864 获取 userId 和 passToken 并更新到 .env 文件中,配置后重启服务即可。passToken 长期有效,过期后重新获取即可。
在任何脚本中发送语音通知:
#!/bin/bash
# 备份完成后通知
./backup.sh
if [ $? -eq 0 ]; then
curl -X POST http://localhost:2010/webhook/custom \
-H "Content-Type: application/json" \
-H "Speaker-API-Secret: your_api_secret" \
-H "CF-Access-Client-Id: your_cf_client_id" \
-H "CF-Access-Client-Secret: your_cf_client_secret" \
-d '{"message": "备份任务完成"}'
fi
import requests
def send_alert(message):
requests.post(
"http://localhost:2010/webhook/custom",
headers={"Speaker-API-Secret": "your_api_secret"},
params={"cf_client_id": "your_cf_client_id", "cf_client_secret": "your_cf_client_secret"},
json={"message": message}
)
# CPU 使用率过高时告警
if cpu_usage > 90:
send_alert("服务器 CPU 使用率超过 90%")
# 添加到 crontab
0 9 * * * curl -X POST http://localhost:2010/webhook/custom -H "Content-Type: application/json" -H "Speaker-API-Secret: your_api_secret" -H "CF-Access-Client-Id: your_cf_client_id" -H "CF-Access-Client-Secret: your_cf_client_secret" -d '{"message": "早上好,开始新的一天"}'
使用官方 xiaomi-speaker-action 可以更方便地在 GitHub Actions 中发送通知。
如果需要从公网访问服务(例如接收 GitHub webhook),可以使用 Cloudflare Tunnel。
获取 Tunnel Token
xiaomi-speaker)并保存tunnel run --token <EY...>配置 Public Routes
speaker.yourdomain.com)HTTP,URL 填 xiaomi-speaker:2010 (注意这里用容器名)更新 .env 文件
在 .env 文件中添加 Token:
TUNNEL_TOKEN=eyJhIjoi...
启动服务
docker-compose up -d
如果你不想在 Docker 中运行 Tunnel,也可以在宿主机直接安装:
⭐ 如果这个项目对你有帮助,请给个 Star!
Content type
Image
Digest
sha256:aa54a1582…
Size
108.2 MB
Last updated
7 months ago
docker pull palemoky/xiaomi-speaker