/* * Copyright 2012 Nexiwave Canada. All rights reserved. * Nexiwave Canada PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class Nexiwave_v2t { public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println("Usage: java " + Nexiwave_v2t.class + " "); System.exit(1); } // Change these: String user = args[0]; String passwd = args[1]; File wavFile = new File(args[2]); // Make the url: String url = "https://api.nexiwave.com/SpeechIndexing/file/storage/"+user+"/recording/?authData.passwd="+passwd+"&response=application/raw-transcript&transcriptFormat=html&auto-redirect=true"; URL u = new URL(url); // Open the connection and prepare to POST HttpURLConnection uc = (HttpURLConnection)u.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); uc.setAllowUserInteraction(false); uc.setConnectTimeout(20 * 60 * 1000); uc.setRequestProperty("content-type", "audio/vnd.wav"); uc.connect(); // Send the audio: OutputStream out = uc.getOutputStream(); int len; byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(wavFile); while((len = fis.read(buf)) >= 0){ out.write(buf, 0, len); } out.close(); fis.close(); // Read Response InputStream in = uc.getInputStream(); BufferedReader r = new BufferedReader(new InputStreamReader(in)); String line; while ((line = r.readLine())!=null) { System.out.print(line); } in.close(); r.close(); uc.disconnect(); } }