- 积分
- 746
- 金钱
- 661
- 威望
- 0
- 贡献
- 0
- HASS币
- 10
高级会员
- 积分
- 746
- 金钱
- 661
- HASS币
- 10
|
楼主 |
发表于 2023-8-17 21:42:09
|
显示全部楼层
完整自动延迟控制流程,我的小爱测试语速是2.7。 自己的自行测试哈。流程分享如下。
[{"id":"d746ba0c8e810306","type":"link in","z":"4e296426d7d6e14e","g":"5689692658fb2d11","name":"Txa","links":["19e58efd13944be8","49a1705dbe7f83d1","e6a3c210b4e5209a","9f276073515b2efe","dca74ce884fffdf7","726e5530ec2ca56d"],"x":275,"y":1400,"wires":[["bc8ae7f1f2b64316"]]},{"id":"bc8ae7f1f2b64316","type":"function","z":"4e296426d7d6e14e","g":"5689692658fb2d11","name":"播放时间","func":"\nfunction countChsEng(str) {\n // 匹配任意中文\n const regChinese = /[\\u4E00-\\u9FA5]/g;\n // 匹配任意英文字母\n // const regEnglish = /[a-zA-Z]/g;\n // 匹配任意英文单词\n const regEnglish = /\\b[a-zA-Z]+\\b/g;\n\n let chCount = str.match(regChinese);\n let enCount = str.match(regEnglish);\n let xCount\n\n // match返回数组,length为出现次数\n chCount = chCount === null ? 0 : chCount.length;\n enCount = enCount === null ? 0 : enCount.length;\n xCount = chCount + enCount\n\n return {\n chCount,\n enCount,\n xCount\n };\n}\n\nvar tts = msg.payload.data.value;\n// 每秒3个字\nvar number = countChsEng(tts).xCount / 2.7;\n\nmsg = {};\nmsg.payload = tts;\nmsg.spake_time = number;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":1400,"wires":[["9447cd1b8183cb4b"]]},{"id":"9447cd1b8183cb4b","type":"function","z":"4e296426d7d6e14e","g":"5689692658fb2d11","name":"延迟时间","func":"var current_message_spake_time = msg.spake_time * 1000;\nvar tts = msg.payload;\nmsg = {};\n\n\n// get current time. unit: s\nlet d = new Date();\nlet new_time = d.getTime();\n\n//msg.new_time_type= typeof(new_time);\n\n// get before message end time.\nvar before_end = flow.get(\"before_end\")||0;\n\nif (before_end>0) {\n var x = new_time - before_end\n msg.x_type = typeof (x);\n msg.x = x;\n if (x >= 0) {\n msg.delay = 0;\n msg.start_time = new Date(new_time);\n msg.start_time_type = typeof (msg.start_time);\n } else {\n msg.delay = Math.abs(x);\n msg.start_time = new Date(new_time + msg.delay);\n msg.start_time_type = typeof (msg.start_time);\n }\n} else {\n msg.delay = 0;\n msg.start_time = new Date(new_time);\n}\n\n\n\nmsg.before_end = before_end;\nmsg.new_time = new_time;\nmsg.current_message_spake_time = current_message_spake_time;\n\nmsg.payload = tts\n\nlet start_time = msg.start_time.getTime();\nlet current_message_end_time = new Date(start_time + msg.current_message_spake_time);\nflow.set(\"before_end\", current_message_end_time);\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1400,"wires":[["f2543d4939071f40"]]},{"id":"f2543d4939071f40","type":"delay","z":"4e296426d7d6e14e","g":"5689692658fb2d11","name":"智能延迟","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":680,"y":1400,"wires":[["b8d8987b1e4b518f"]]},{"id":"b8d8987b1e4b518f","type":"function","z":"4e296426d7d6e14e","g":"5689692658fb2d11","name":"tts","func":"let tts_text = msg.payload\nmsg.payload = {\n \"data\": {\n \"value\": tts_text\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":1400,"wires":[["51b3ce1084762bd0"]]},{"id":"51b3ce1084762bd0","type":"api-call-service","z":"4e296426d7d6e14e","g":"5689692658fb2d11","name":"小爱播报","server":"39d63457.baaeac","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_l05b_a8c7_play_text_2"],"data":"{\"value\":\"{{payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"all","x":940,"y":1400,"wires":[["b3924e7e7f1ce96c"]]},{"id":"39d63457.baaeac","type":"server","name":"Home Assistant","addon":true}] |
|