本帖最后由 ciasdmxhxjjpd@c 于 2022-4-18 16:38 编辑
===================================================================================
硬件实现,见之前发帖, https://bbs.hassbian.com/thread-16077-1-1.html
固件,https://github.com/schmurtzm/MrDiy-Audio-Notifier, 支持 esp32/8266。
===================================================================================
本贴主要是解决 tts 播报时, 不支持 https 问题。
原因: MrDiy Audio Notifier 在播放时,esp32/8266 不支持 https(内存太小),而我们的homeassisstant 基本都配置成了 https,导致有冲突。
google tts ( 路由器需要全局fq,不是此贴讨论范围), 代替物 baidu tts
# Text to speech
tts:
- platform: google_translate
language: "zh-CN"
cache: true
cache_dir: /config/tts
time_memory: 300
base_url: https://yourdomain:8123
service_name: google_say
开启 cache,每次tts ,会保存到 /config/tts
docker 版,创建 /config/init.sh , 加上执行权限
python -m http.server 8124 -d /config/tts &
/init
docker 启动时,添加 命令 /config/init.sh, 会启动一个 http 的 server,监听8124
解释下流程中重要的部分,nodered 通过
/api/tts_get_url ,获取 tts path 和 url,后,简单处理下,替换 host = yourdomain:8124
log:
==================================================================
MrDIY Notifier - Modified By Schmurtz
==================================================================
Connected to Wifi [192.168.1.225]
Connected to MQTT
[MQTT] media/LWT online
[MQTT] media/SSID NodeMCU-32S-AP
[MQTT] media/IPAddress 192.168.1.225
[MQTT] media/status idle
State changed from: 3 to 4
Requested [media/play] http://192.168.1.2:8124/367f479200d9e0f1f1be0301d3422d84bf147d9b_zh-cn_-_google_translate.mp3
[V][HTTPClient.cpp:245] beginInternal(): url: http://192.168.1.2:8124/367f479200d9e0f1f1be0301d3422d84bf147d9b_zh-cn_-_google_translate.mp3
[D][HTTPClient.cpp:293] beginInternal(): protocol: http, host: 192.168.1.2 port: 8124 url: /367f479200d9e0f1f1be0301d3422d84bf147d9b_zh-cn_-_google_translate.mp3
[D][HTTPClient.cpp:579] sendRequest(): request type: 'GET' redirCount: 0
[D][HTTPClient.cpp:1125] connect(): connected to 192.168.1.2:8124
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: 'HTTP/1.0 200 OK'
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: 'Server: SimpleHTTP/0.6 Python/3.9.7'
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: 'Date: Mon, 18 Apr 2022 06:15:58 GMT'
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: 'Content-type: audio/mpeg'
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: 'Content-Length: 40237'
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: 'Last-Modified: Mon, 18 Apr 2022 06:15:57 GMT'
[V][HTTPClient.cpp:1216] handleHeaderResponse(): RX: ''
[D][HTTPClient.cpp:1257] handleHeaderResponse(): code: 200
[D][HTTPClient.cpp:1260] handleHeaderResponse(): size: 40237
[D][HTTPClient.cpp:603] sendRequest(): sendRequest code=200
[MQTT] media/status playing
Free: 139972 (46980 lost) -----------
Free: 140828 (47836 lost) -----------
Free: 141032 (48040 lost) -----------
Free: 141032 (48040 lost) -----------
Free: 141032 (48040 lost) -----------
Free: 142548 (49556 lost) -----------
Free: 141004 (48036 lost) -----------
Free: 141028 (48036 lost) -----------
Free: 142544 (49552 lost) -----------
Free: 146412 (53420 lost) -----------
[D][WiFiClient.cpp:514] connected(): Disconnected: RES: 0, ERR: 128
[D][HTTPClient.cpp:400] disconnect(): tcp is closed
[D][HTTPClient.cpp:400] disconnect(): tcp is closed
...#Interrupted!
[MQTT] media/status idle
|