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

26
LINES

< > BotCompany Repo | #1017980 // witAI_recognizeAudio

JavaX fragment (include)

1  
sS witAI_recognizeAudio(File audioFile, S mimeType) {
2  
  ret witAI_recognizeAudio(audioFile, mimeType, 'english);
3  
}
4  
5  
sS witAI_recognizeAudio(File audioFile, S mimeType, S language) ctex {
6  
  if (audioFile.length() == 0) fail("No file: " + audioFile);
7  
  print("Calling wit.ai with " + toK(audioFile.length()) + " K " + mimeType + "...");
8  
  long time = sysNow();
9  
  
10  
  S token = witAITokenForLanguage(language);
11  
  URL url = new URL("https://api.wit.ai/speech?v=20160526");
12  
  URLConnection con = url.openConnection();
13  
  con.setRequestProperty("Authorization", "Bearer " + token);
14  
  con.setRequestProperty("Content-Type", mimeType);
15  
  
16  
  con.setDoOutput(true);
17  
  OutputStream out = con.getOutputStream();
18  
  file2stream(audioFile, out);
19  
  out.flush();
20  
21  
  S json = loadPage(con, url);
22  
  print(json);
23  
  out.close();
24  
  done2_always("wit.ai", time);
25  
  ret getString(jsonDecodeMap(json), "_text");
26  
}

Author comment

Began life as a copy of #1007049

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017980
Snippet name: witAI_recognizeAudio
Eternal ID of this version: #1017980/6
Text MD5: e4edfc49a70865cd5912f11ee56e9d2f
Author: stefan
Category: javax / speech recognition
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-07 23:14:51
Source code size: 911 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 431 / 463
Version history: 5 change(s)
Referenced in: [show references]