4ddecb7c301756e8cf2139240b7e5ee00adce386
问题: - TTS 返回 16000 Hz 音频,但 Context 使用 44100 Hz - 播放速度快 2.75 倍(44100/16000) - 不同采样率的音频播放速度不正确 解决方案: - 集成 gomplerate 库(纯 Go,零依赖) - 自动检测音频采样率并重采样到 44100 Hz - 支持任意采样率的音频文件正常播放 技术实现: - resampler.go: 封装 gomplerate,实现流式重采样 - play.go: WAV/MP3 播放自动重采样 - loop.go: BGM 循环播放支持重采样 测试: - 所有单元测试通过(6/6) - 支持采样率自动转换(如 16000 Hz → 44100 Hz) 依赖: - github.com/zeozeozeo/gomplerate v0.0.0
边缘盒子
topic 中的 location 指景区编码, point 指景区内具体点位
1. 接收启动
Topic: server/${location}/${point}/play
Payload:
{
// 设备超时时长(s)
"timeout": 30,
// 是否需要整体电源控制
"power": true,
// 游戏中背景音乐(支持 file:// 本地文件地址、 http(s):// 远程文件地址)
"bgm": "",
// 整体设备音量(0-1)
"volume": 0.5,
// 屏幕默认打印(设备待机时展示文本)
"default-print": "",
// 文本转语音整体控制
"tts": {
// 开始播报语音
"start": "",
// 超时自动停止时播报语音
"timeout": "",
// 结束播报语音
"end": "",
// 终止播报语音
"stop": "",
// 固定节点播报语音
"timer": [
{
// 时间节点(s)
"time": 10,
// 语音文字
"value": ""
},
...
]
},
// 屏幕打印控制
"print": [
{
// 时间节点(s)
"time": 10,
// 展示文字
"text": "",
// 持续时长(s)
"duration": 10
},
...
],
// 根据具体游戏特定
"game": {}
}
例: 入口欢迎播报
{
"volume": 1,
"tts": {
"start": "欢迎前来挑战!"
}
}
2. 事件反馈
状态变更
Topic: device/${location}/${point}/status
Payload:
0
0 待机; 1 使用中; -1 状态异常
3. 接收指令
终止
Topic: server/${location}/${point}/command
Payload:
stop
终止后台
Topic: server/${location}/${point}/command
Payload:
stop-bg
查询状态
Topic: server/${location}/${point}/command
Payload:
status
设备接收到该指令会立即向
device/${location}/${point}/status发送一次当前状态
4. 待机执行
Topic: server/${location}/${point}/wait
Payload:
{
// 执行的时间区间(需要系统配置正确时区)
"cron": "17:20-21:35 1-5 * *",
// 执行项
"items": [
{
// 执行的时间区间
"cron": "17:20-21:35 1-5 * *",
// 间隔时间(s), 类型>2时, 该项无效, default 0
"interval": 0,
// 持续时长(s), 待机任务执行时持续的时长。为 0 表示 音频、视频、TTS 按播放时长,继电器、网页、投影仪、激光秀持续整个时间段。 default 0
"duration": 0,
// 事件类型(0: 音频; 1: 视频; 2: TTS; 3: 继电器; 4: 网页; 5: 投影仪; 6: 激光秀;) default 0
"type": 2,
// Game 指令执行时是否暂停。default false
"pause": true,
// 待机任务执行时,是否锁定设备。default false
"lock": false,
// 事件数据(TTS为文字, 继电器为端口号,激光秀为节目名,投影仪忽略该参数, 其他都为地址链接。支持 file:// 本地文件地址、 http(s):// 远程文件地址)
"data": "",
},
...
]
}
同一个类型的待机任务只能有一个,当有新的任务到达时会覆盖之前的任务
配置时区
sudo timedatectl set-timezone Asia/Shanghai
Cron Format
The format consists of four fields separated by whitespace:
time dow dom month
Where:
time: Time range in 24-hour format (HH:MM[:SS]-HH:MM[:SS]) or * for all day. Seconds are optional.dow: Day of week (0-6, where 0=Sunday)dom: Day of month (1-31)month: Month (1-12)
Multiple rules can be combined using semicolons (;).
Each field (except time) supports:
- Single values: "5"
- Lists: "1,3,5"
- Ranges: "1-5"
- Asterisk: "*" for any/all values
Description