Advertisement
Guest User

help

a guest
May 24th, 2013
8,421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. Path path = Paths.get("out.flac");
  2.        byte[] data = Files.readAllBytes(path);
  3.        
  4.        String request = "https://www.google.com/"+
  5.                 "speech-api/v1/recognize?"+
  6.                 "xjerr=1&client=speech2text&lang=en-US&maxresults=10";
  7.        URL url = new URL(request);
  8.        HttpURLConnection connection = (HttpURLConnection) url.openConnection();          
  9.        connection.setDoOutput(true);
  10.        connection.setDoInput(true);
  11.        connection.setInstanceFollowRedirects(false);
  12.        connection.setRequestMethod("POST");
  13.        connection.setRequestProperty("Content-Type", "audio/x-flac; rate=16000");
  14.        connection.setRequestProperty("User-Agent", "speech2text");
  15.        connection.setConnectTimeout(60000);
  16.        connection.setUseCaches (false);
  17.        
  18.        DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
  19.        wr.writeBytes(new String(data));
  20.        wr.flush();
  21.        wr.close();
  22.        connection.disconnect();
  23.        
  24.        System.out.println("Done");
  25.        
  26.        BufferedReader in = new BufferedReader(
  27.                new InputStreamReader(
  28.                connection.getInputStream()));
  29.         String decodedString;
  30.         while ((decodedString = in.readLine()) != null) {
  31.         System.out.println(decodedString);
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement