File size: 2,533 Bytes
f9955c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width" />
    <title>Speech color changer</title>
    <style>
      body {background: white; }
      #view-source {
                position: fixed;
                display: block;
                right: 0;
                bottom: 0;
                margin-right: 40px;
                margin-bottom: 40px;
                z-index: 900;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/jquery/[email protected]/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/sdkcarlos/artyom.js@master/build/artyom.window.min.js"></script>
    <script>
      window.artyom = window.artyom || new Artyom();
    </script>
  </head>
  <body>
    <h1>Speech recognition</h1>
    <div><p>Recognizing text: <span id='recognized-text'></span></p></div>
    <div><label>Captured text<br><textarea rows=10 cols=40 id='listening-text'></textarea></h5></div>
    <div><input name="accepts" type = "checkbox"> listenining</div>
    <div id='commands-container'></div>
    <script>    
    artyom.addCommands([
        {
          description:"It will save the text it recognizes.",
          indexes: ["*"],
          smart:true,
          action : function(i, wildcard, sentence){            
            if(wildcard.includes("stop listening")){
              $('[name="accepts"]').prop('checked', false);
              console.log("Stop listening checked")
            }
            if($('[name="accepts"]').prop('checked') == true) {
              var sel = $('#listening-text');                     
              sel.html(sel.html()+'\n'+wildcard);              
            }
            if(wildcard.includes("start listening")){
              $('[name="accepts"]').prop('checked', true);
              console.log("Start listening checked")
            }            
          }
      },
    ]);
    artyom.redirectRecognizedTextOutput(function(text, isFinal){
        var sel = $('#recognized-text');
        if(isFinal){
            sel.html('');
        }else{
            sel.html(text);
        }
    });
    function startArtyom() {
        artyom.initialize({
            lang:'en-US',
            debug:true,
            continuous:true,
            listen:true,
            executionKeyword:'now'
        });
    }
    $(window).on("load", function(){            
        startArtyom();
    });
    </script>
  </body>
</html>