face-recognition.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // ==UserScript==
  2. // @name 面部识别
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 利用面部识别,检查嘴部开合,控制语音输入开关
  6. // @author You
  7. // @match http://127.0.0.1:17860/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=0.1
  9. // @grant none
  10. // ==/UserScript==
  11. if (navigator != null && (window.location.toString().toUpperCase().indexOf("HTTPS") > -1 || window.location.toString().toUpperCase().indexOf("127") > -1)) {
  12. } else {
  13. alert("当前连接不安全,无法访问媒体")
  14. }
  15. // constrains = {
  16. // video: true,
  17. // audio: true
  18. // }
  19. tab_index = app.plugins.push({ icon: "face-recognition", url: "static/mp/index.html" })
  20. // navigator.mediaDevices.getUserMedia(constrains)
  21. // .then(stream => {
  22. // console.log(tab_index)
  23. // setTimeout(() => app.tab = tab_index + 2)
  24. // })
  25. let 上次闭嘴时间 = -1
  26. // app.语音 = true
  27. window.addEventListener('message', function (e) {
  28. if (e.data.from == '面部识别') {
  29. let 张嘴幅度 = e.data.data
  30. // console.log(e.data.data)
  31. if (app.sst_started) {
  32. if (张嘴幅度 < 0.1) {
  33. if (上次闭嘴时间 != -1) {
  34. if (Date.now() - 上次闭嘴时间 > 1000) {
  35. 上次闭嘴时间 = -1
  36. stop_listen()
  37. return
  38. }
  39. } else {
  40. 上次闭嘴时间 = Date.now()
  41. return
  42. }
  43. } else {
  44. 上次闭嘴时间 = -1
  45. return
  46. }
  47. }
  48. if (!app.sst_started && !app.loading) {
  49. if (张嘴幅度 > 0.2) {
  50. listen()
  51. 上次闭嘴时间 = -1
  52. }
  53. }
  54. }
  55. });
粤ICP备19079148号