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

36
LINES

< > BotCompany Repo | #1018150 // Test wit.ai speech recognition with German .mp3 [OK]

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

Download Jar. Libraryless. Click here for Pure Java version (4544L/33K).

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

Author comment

Began life as a copy of #1007044

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018150
Snippet name: Test wit.ai speech recognition with German .mp3 [OK]
Eternal ID of this version: #1018150/11
Text MD5: 216ec6026bfedee74fa5842485481edd
Transpilation MD5: e99c42ee2738cea73b8771070bf04253
Author: stefan
Category: javax / speech recognition
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-04 21:35:04
Source code size: 1231 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 300 / 691
Version history: 10 change(s)
Referenced in: [show references]