Libraryless. Click here for Pure Java version (6236L/42K).
sclass StreamingWitAIUploader { S mimeType = "audio/mpeg3"; S language = "english"; URL url; URLConnection con; OutputStream out; long bytesSent; void start ctex { print("Initiating wit.ai call"); S token = witAITokenForLanguage(language); url = new URL("https://api.wit.ai/speech?v=20160526"); con = url.openConnection(); con.setRequestProperty("Authorization", "Bearer " + token); con.setRequestProperty("Content-Type", mimeType); con.setDoOutput(true); out = con.getOutputStream(); } void sendData(byte[] data) ctex { out.write(data); bytesSent += l(data); } S get() ctex { if (out == null) null; printWithMilliseconds("Sent " + nBytes(bytesSent) + " to wit.ai"); out.flush(); S json = loadPage(con, url); S text = getString(jsonDecodeMap(json), "_text"); printWithMilliseconds("wit.ai responded: " + text); if (eq(text, "hallo")) { text = ""; print("WIT.AI WORKAROUND"); } dispose out; ret text; } void cleanMeUp { dispose out; } }
Began life as a copy of #1017980
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1026973 |
| Snippet name: | StreamingWitAIUploader |
| Eternal ID of this version: | #1026973/11 |
| Text MD5: | ab8e3ff2d296a6fe75dffafa27c5cf5a |
| Transpilation MD5: | 265dac5cb296c8dfaec7368791ba7c88 |
| 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-15 14:12:54 |
| Source code size: | 1117 bytes / 44 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 580 / 1020 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |