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

39
LINES

< > BotCompany Repo | #1007041 // Test wit.ai speech recognition with .wav [WORKS if you have a wit.ai token]

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

Uses 455K of libraries. Click here for Pure Java version (3360L/23K/72K).

1  
!7
2  
3  
/*
4  
curl -XPOST 'https://api.wit.ai/speech?v=20160526'    -i -L    -H "Authorization: Bearer $TOKEN"    -H "Content-Type: audio/wav" --data-binary "@20170226-024709.wav"
5  
*/
6  
p-tt {
7  
  // make speech to recognize
8  
  File wavFile = prepareProgramFile("penguin.wav");
9  
  S originalText = "Hello Penguin";
10  
  if (wavFile.length() == 0) {
11  
    print("Making speech");
12  
    williamSpeaksForSphinx(originalText, wavFile);
13  
  }
14  
    
15  
  print("Calling wit.ai with " + toK(wavFile.length()) + " K wav...");
16  
  
17  
  S token = witAIToken();
18  
  URL url = new URL("https://api.wit.ai/speech?v=20160526");
19  
  URLConnection con = url.openConnection();
20  
  con.setRequestProperty("Authorization", "Bearer " + token);
21  
  con.setRequestProperty("Content-Type", "audio/wav");
22  
  
23  
  con.setDoOutput(true);
24  
25  
  OutputStream out = con.getOutputStream();
26  
  file2stream(wavFile, out);
27  
  out.flush();
28  
29  
  S contents = loadPage(con, url);
30  
  out.close();
31  
  print("JSON:");
32  
  print(contents);
33  
  S text = getString(jsonDecodeMap(contents), "_text");
34  
  
35  
  print("ORIGINAL TEXT:   " + originalText);
36  
  print("RECOGNIZED TEXT: " + text);
37  
  print();
38  
  print(match(originalText, text) ? "FULL MATCH!" : "Not a full match.");
39  
}

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: #1007041
Snippet name: Test wit.ai speech recognition with .wav [WORKS if you have a wit.ai token]
Eternal ID of this version: #1007041/9
Text MD5: e53727b7bed8d4579620cc9b5e3263e6
Transpilation MD5: a18d51665c698cc51067d54750662164
Author: stefan
Category: javax / speech recognition
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-26 13:51:49
Source code size: 1212 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 805 / 869
Version history: 8 change(s)
Referenced in: [show references]