『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 7005|回复: 8

[流程系列] tasker TTS 通过MQTT发送播放文字[第一帖,写的不好]

[复制链接]

3

主题

113

帖子

748

积分

高级会员

Rank: 4

积分
748
金钱
635
HASS币
0
发表于 2019-8-28 15:44:40 | 显示全部楼层 |阅读模式
第一次发帖,之前一直想整个TTS,没有小爱,用N1蓝牙一直不成功,放弃!
逛论坛发现L大的Tasker TTS 就用了,使用还可以,附上链接 :HA【node-red】【tts到手机】【tasker】https://bbs.hassbian.com/thread-6482-1-1.html

但是L大给的流里面不能动态发送文字,所以改造了一下:注册流程不变,改了调用的方法
第一次修改,提取tts播放内容:
tts2.png


第二次修改,读取MQTT,用来播放:
tts1.png

使用总结:
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 }}'   


haTTS1.png
或者:
haTTS2.png


回复

使用道具 举报

219

主题

1287

帖子

7947

积分

超级版主

Rank: 8Rank: 8

积分
7947
金钱
6630
HASS币
86

教程狂人论坛风云人物突出贡献

发表于 2019-8-28 17:50:11 | 显示全部楼层
你的tasker不会被后台杀进程吗
回复

使用道具 举报

73

主题

1165

帖子

6651

积分

论坛元老

Rank: 8Rank: 8

积分
6651
金钱
5481
HASS币
30
发表于 2019-8-28 19:24:14 | 显示全部楼层
回复

使用道具 举报

3

主题

113

帖子

748

积分

高级会员

Rank: 4

积分
748
金钱
635
HASS币
0
 楼主| 发表于 2019-8-28 20:33:32 | 显示全部楼层
lidicn 发表于 2019-8-28 17:50
你的tasker不会被后台杀进程吗

不会,这个手机不动,装的IP摄像头,和tasker,放那不动,现在一个多星期,没出现被杀
回复

使用道具 举报

3

主题

113

帖子

748

积分

高级会员

Rank: 4

积分
748
金钱
635
HASS币
0
 楼主| 发表于 2019-8-28 20:35:42 | 显示全部楼层
xuyang 发表于 2019-8-28 19:24
试试这个也能用

多谢,我试试
回复

使用道具 举报

8

主题

2073

帖子

6057

积分

论坛元老

流水无味

Rank: 8Rank: 8

积分
6057
金钱
3984
HASS币
145

灌水之王

发表于 2019-8-29 07:44:35 | 显示全部楼层
旧手机都可以这样处理, 赞个
回复

使用道具 举报

3

主题

113

帖子

748

积分

高级会员

Rank: 4

积分
748
金钱
635
HASS币
0
 楼主| 发表于 2019-8-29 14:34:33 | 显示全部楼层
xieahui 发表于 2019-8-29 07:44
旧手机都可以这样处理, 赞个

旧物利用了
回复

使用道具 举报

6

主题

76

帖子

722

积分

论坛DIY达人

积分
722
金钱
641
HASS币
20
发表于 2019-8-30 11:28:00 | 显示全部楼层
TAKSER设置里,输入朗读,只有停止朗读,请问是这什么呢?
回复

使用道具 举报

3

主题

113

帖子

748

积分

高级会员

Rank: 4

积分
748
金钱
635
HASS币
0
 楼主| 发表于 2019-8-30 16:15:35 | 显示全部楼层
渗透之王 发表于 2019-8-30 11:28
TAKSER设置里,输入朗读,只有停止朗读,请问是这什么呢?

这个就不清楚了,可能是手机不支持吧,我用的3个手机都没有出现这种情况
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-4 16:26 , Processed in 0.057290 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表