Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1009223 // Chrome Speech Recognition Test [WORKS]

JavaX source code [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Libraryless. Click here for Pure Java version (4357L/32K/91K).

1  
!7
2  
3  
p {
4  
  if (isMainProgram()) serveHttpAndOpenBrowser();
5  
}
6  
7  
html {
8  
  ret h3("Chrome Speech Recognition Test")
9  
    + loadJQuery()
10  
    + hdiv("Results come here", id := 'results, style := "margin: 10px")
11  
  + hjavascript([[
12  
    var recognition = new webkitSpeechRecognition();
13  
    recognition.lang = "en-US";
14  
    
15  
    recognition.onerror = function(event) { 
16  
      console.log('Speech recognition error detected: ' + event.error);
17  
      console.log('Additional information: ' + event.message);
18  
      $("#results").html("Error.");
19  
      started = false; $("#btn").html("Start recognition");
20  
    }
21  
    
22  
    recognition.onresult = function(event) { 
23  
      var result = event.results[0];
24  
      var transcript = result[0].transcript;
25  
      $("#results").html("Transcript: " + transcript);
26  
      started = false; $("#btn").html("Start recognition");
27  
    }
28  
    
29  
    var started = false;
30  
    
31  
    function startOrStop() {
32  
      if (started) {
33  
        recognition.stop();
34  
        started = false; $("#btn").html("Start recognition");
35  
      } else {
36  
        recognition.start();
37  
        started = true; $("#btn").html("Stop recognition");
38  
      }
39  
    }
40  
  ]])
41  
    + tag('button, "Start recognition", onclick := "startOrStop()", type := 'button, id := 'btn);
42  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009223
Snippet name: Chrome Speech Recognition Test [WORKS]
Eternal ID of this version: #1009223/15
Text MD5: 549828d3d2cd5933d7ef3384a3275ca7
Transpilation MD5: 9176d0be1683f8c83789561853ab2b09
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-24 18:23:44
Source code size: 1287 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 490 / 4135
Version history: 14 change(s)
Referenced in: [show references]