积分 748
金钱 635
威望 0
贡献 0
HASS币 0
高级会员
积分 748
金钱 635
HASS币 0
第一次发帖,之前一直想整个TTS,没有小爱,用N1蓝牙一直不成功,放弃!
逛论坛发现L大的Tasker TTS 就用了,使用还可以,附上链接 :HA【node-red】【tts到手机】【tasker】https://bbs.hassbian.com/thread-6482-1-1.html
但是L大给的流里面不能动态发送文字,所以改造了一下:注册流程不变,改了调用的方法
第一次修改,提取tts播放内容:
第二次修改,读取MQTT,用来播放:
使用总结:
1.因为我是在android手机上使用IP摄像头,所以吧Tasker装到同一个手机,一直通电,不进行其他操作,一般情况下不会出现TTS掉线,如果嫌手机音量小,可以接一个音响,我就是这样用的。
2.TTS播放长段文字有时会有卡顿,好像是网络原因
3.因为我设置的只有当mqtt值改变的时候才会触发,所以可以在每次播放的时候加上时间,比如:7点40分 ,为你播报天气情况。。。
第一个流程:
[{"id":"f4f8bfb7.be636","type":"tab","label":"客厅tts","disabled":false,"info":""},{"id":"64c13bd3.51dc54","type":"debug","z":"f4f8bfb7.be636","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":300,"wires":[]},{"id":"47325cac.93ee94","type":"inject","z":"f4f8bfb7.be636","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":300,"wires":[["b41cf66a.f57558"]]},{"id":"ad63a31d.56765","type":"function","z":"f4f8bfb7.be636","name":"赋值","func":"\nmsg.login=\"\";\nmsg.pass=\"\";\nmsg.tts='{%22tts%22:'+msg.say+'}';\n\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":300,"wires":[["18b2893a.ca3737"]]},{"id":"18b2893a.ca3737","type":"http request","z":"f4f8bfb7.be636","name":"tts请求","method":"GET","ret":"obj","paytoqs":false,"url":"http://thacthab.herokuapp.com/broadcast?login={{{login}}}&pass={{{pass}}}&title=tts&message={{{tts}}}","tls":"","proxy":"","authType":"","x":830,"y":300,"wires":[["64c13bd3.51dc54"]]},{"id":"a84a2038.ec8f2","type":"function","z":"f4f8bfb7.be636","name":"urlcode","func":"\n url = encodeURIComponent(msg.say);\n url = url.replace(/\\%3A/g, \":\");\n url = url.replace(/\\%2F/g, \"/\");\n url = url.replace(/\\%3F/g, \"?\");\n url = url.replace(/\\%3D/g, \"=\");\n url = url.replace(/\\%26/g, \"&\");\n \n msg.say=url;\n\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":300,"wires":[["ad63a31d.56765"]]},{"id":"b41cf66a.f57558","type":"function","z":"f4f8bfb7.be636","name":"tts播放内容","func":"msg.say='测试,tts卡顿';\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":300,"wires":[["a84a2038.ec8f2"]]}]
第二个流程:
[{"id":"f9de09c9.877ff8","type":"tab","label":"tts语音播放","disabled":false,"info":""},{"id":"9e330785.275718","type":"server-state-changed","z":"f9de09c9.877ff8","name":"判断tts字段","server":"3faf1792.372d58","version":1,"entityidfilter":"sensor.ttslangdu","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"unknown","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":110,"y":260,"wires":[[],["c2d32b9d.722bd8"]]},{"id":"8af19c79.7deab","type":"debug","z":"f9de09c9.877ff8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1090,"y":260,"wires":[]},{"id":"89f05615.a28098","type":"function","z":"f9de09c9.877ff8","name":"赋值","func":"\nmsg.login=\"\";\nmsg.pass=\"\";\nmsg.tts='{%22tts%22:'+msg.say+'}';\n\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":260,"wires":[["85b9040c.378a48"]]},{"id":"85b9040c.378a48","type":"http request","z":"f9de09c9.877ff8","name":"tts请求","method":"GET","ret":"obj","paytoqs":false,"url":"http://thacthab.herokuapp.com/broadcast?login={{{login}}}&pass={{{pass}}}&title=tts&message={{{tts}}}","tls":"","proxy":"","authType":"","x":750,"y":260,"wires":[["8bd10889.750c58"]]},{"id":"c2d32b9d.722bd8","type":"function","z":"f9de09c9.877ff8","name":"urlcode","func":"\n url = encodeURIComponent(msg.payload);\n url = url.replace(/\\%3A/g, \":\");\n url = url.replace(/\\%2F/g, \"/\");\n url = url.replace(/\\%3F/g, \"?\");\n url = url.replace(/\\%3D/g, \"=\");\n url = url.replace(/\\%26/g, \"&\");\n \n msg.say=url;\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":260,"wires":[["89f05615.a28098"]]},{"id":"8bd10889.750c58","type":"switch","z":"f9de09c9.877ff8","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"str"},{"t":"neq","v":"200","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":260,"wires":[["8af19c79.7deab"],["443221ff.405b6"]]},{"id":"443221ff.405b6","type":"api-current-state","z":"f9de09c9.877ff8","name":"","server":"3faf1792.372d58","version":1,"outputs":2,"halt_if":"unknown","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"sensor.ttslangdu","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":370,"y":500,"wires":[["c2d32b9d.722bd8"],[]]},{"id":"8d574148.bf3ff","type":"mqtt out","z":"f9de09c9.877ff8","name":"","topic":"/node-red/ttslangdu","qos":"","retain":"","broker":"5ff51f1b.76027","x":510,"y":140,"wires":[]},{"id":"e603bc75.8cab2","type":"inject","z":"f9de09c9.877ff8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":140,"wires":[["4f5925fc.5db81c"]]},{"id":"4f5925fc.5db81c","type":"function","z":"f9de09c9.877ff8","name":"测试","func":"var tts={\"tts\":\"20点为你播报天气,当前天气,多云,空气指数,53,风速,4.68千米每小时,风向,西风, 紫外强度, \"}\nmsg.payload = tts;\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":140,"wires":[["8d574148.bf3ff"]]},{"id":"3faf1792.372d58","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true},{"id":"5ff51f1b.76027","type":"mqtt-broker","z":"","name":"n1","broker":"127.0.0.1","port":"1883","clientid":"123456","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
这是我用彩云天气流程播放内容的处理:
var now = new Date();
var hour = now.getHours();
var minu = now.getMinutes();
var tts={"tts":""+`${hour}`+"点"+`${minu}`+"分为你播报天气,当前天气,"+`${msg.skycon}`+",空气指数,"+`${msg.aqi}`+","+`${msg.winddirection}`+","+`${msg.windspeed}`+"千米每小时"+",未来半个小时下雨概率,"+`${msg.payload.probability_30}`+","+`${msg.all.result.forecast_keypoint}`}
msg.payload = tts;
return msg;
你可以在ha中设置播放内容:
- platform: mqtt
name: "ttslangdu"
state_topic: "/node-red/ttslangdu"
value_template: '{{ value_json.tts }}'
或者: