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

35
LINES

< > BotCompany Repo | #1007044 // Test wit.ai speech recognition with .mp3 [WORKS with token]

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

Uses 206K of libraries. Click here for Pure Java version (3218L/22K/69K).

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  
  S originalText = "Hello Ice Cube";
9  
  File mp3File = william_silent(originalText);
10  
11  
  print("Calling wit.ai with " + toK(mp3File.length()) + " K mp3...");
12  
  
13  
  S token = witAIToken();
14  
  URL url = new URL("https://api.wit.ai/speech?v=20160526");
15  
  URLConnection con = url.openConnection();
16  
  con.setRequestProperty("Authorization", "Bearer " + token);
17  
  con.setRequestProperty("Content-Type", "audio/mpeg3");
18  
  
19  
  con.setDoOutput(true);
20  
21  
  OutputStream out = con.getOutputStream();
22  
  file2stream(mp3File, out);
23  
  out.flush();
24  
25  
  S contents = loadPage(con, url);
26  
  out.close();
27  
  print("JSON:");
28  
  print(contents);
29  
  S text = getString(jsonDecodeMap(contents), "_text");
30  
  
31  
  print("ORIGINAL TEXT:   " + originalText);
32  
  print("RECOGNIZED TEXT: " + text);
33  
  print();
34  
  print(match(originalText, text) ? "FULL MATCH!" : "Not a full match.");
35  
}

Author comment

Began life as a copy of #1007041

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: #1007044
Snippet name: Test wit.ai speech recognition with .mp3 [WORKS with token]
Eternal ID of this version: #1007044/3
Text MD5: ec5253bdcd8b47714cffea59a3b38254
Transpilation MD5: 388be579d1a1848ea239b36636e538ab
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 14:14:32
Source code size: 1088 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 588 / 634
Version history: 2 change(s)
Referenced in: [show references]