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).

!7

/*
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"
*/
p-tt {
  // make speech to recognize
  S originalText = "Hello Ice Cube";
  File mp3File = william_silent(originalText);

  print("Calling wit.ai with " + toK(mp3File.length()) + " K mp3...");
  
  S token = witAIToken();
  URL url = new URL("https://api.wit.ai/speech?v=20160526");
  URLConnection con = url.openConnection();
  con.setRequestProperty("Authorization", "Bearer " + token);
  con.setRequestProperty("Content-Type", "audio/mpeg3");
  
  con.setDoOutput(true);

  OutputStream out = con.getOutputStream();
  file2stream(mp3File, out);
  out.flush();

  S contents = loadPage(con, url);
  out.close();
  print("JSON:");
  print(contents);
  S text = getString(jsonDecodeMap(contents), "_text");
  
  print("ORIGINAL TEXT:   " + originalText);
  print("RECOGNIZED TEXT: " + text);
  print();
  print(match(originalText, text) ? "FULL MATCH!" : "Not a full match.");
}

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: 587 / 633
Version history: 2 change(s)
Referenced in: [show references]