Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Speech To Text API

Google Speech To Text API

Base URL: https://www.google.com/speech-api/v1/recognize
It accepts POST requests with voice file encoded in FLAC format, and query parameters for control.

Query Parameters

client
The client's name you're connecting from. For spoofing purposes, let's use chromium

lang
Speech language, for example, ar-QA for Qatari Arabic, or en-US for U.S. English

maxresults
Maximum results to return for utterance

POST

body
Should contain FLAC formatted voice binary

HTTP Header

Content-Type
Should be audio/x-flac; rate=16000;, where MIME and sample rate of the FLAC file is included

User-Agent
Can be the client's user agent string, for spoofing purposes, we'll use Chrome's

Examples

These examples assume you have a voice file encoded in FLAC called alsalam-alikum.flac.

wget

This will save JSON response in a file called recognized.json

wget --post-file='alsalam-alikum.flac' \
--user-agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7' \
--header='Content-Type: audio/x-flac; rate=16000;' \
-O 'recognized.json' \
'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=ar-QA&maxresults=10'

curl

curl -X POST \
--data-binary @alsalam-alikum.flac \
--user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7' \
--header 'Content-Type: audio/x-flac; rate=16000;' \
'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=ar-QA&maxresults=10'
@taf2

This comment has been minimized.

Show comment
Hide comment
@taf2

taf2 Mar 30, 2013

API might have changed

<HTML>
<HEAD>
<TITLE>Recognition failed: NO_MATCH</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Recognition failed: NO_MATCH</H1>
<H2>Error 400</H2>
</BODY>
</HTML>

taf2 commented Mar 30, 2013

API might have changed

<HTML>
<HEAD>
<TITLE>Recognition failed: NO_MATCH</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Recognition failed: NO_MATCH</H1>
<H2>Error 400</H2>
</BODY>
</HTML>
@firekinger

This comment has been minimized.

Show comment
Hide comment
@firekinger

firekinger Apr 25, 2013

<HEAD>
<TITLE>HTTP method GET is not supported by this URL</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>HTTP method GET is not supported by this URL</H1>
<H2>Error 405</H2>
</BODY>
</HTML>

firekinger commented Apr 25, 2013

<HEAD>
<TITLE>HTTP method GET is not supported by this URL</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>HTTP method GET is not supported by this URL</H1>
<H2>Error 405</H2>
</BODY>
</HTML>
@rgtk

This comment has been minimized.

Show comment
Hide comment
@rgtk

rgtk May 8, 2013

wget -q -U "Mozilla/5.0" --post-file /message.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=pl-pl&client=chromium"

This should work.

rgtk commented May 8, 2013

wget -q -U "Mozilla/5.0" --post-file /message.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=pl-pl&client=chromium"

This should work.

@ewoudenberg

This comment has been minimized.

Show comment
Hide comment
@ewoudenberg

ewoudenberg Jun 7, 2013

In Python:

$ cat speech.py
import urllib2
url = "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US"
audio = open('rainspain.flac','rb').read()
headers={'Content-Type': 'audio/x-flac; rate=16000', 'User-Agent':'Mozilla/5.0'}
request = urllib2.Request(url, data=audio, headers=headers)
response = urllib2.urlopen(request)
print response.read()

$ python speech.py
{"status":0,"id":"57d2d1a7e7f1fa12d200026dde946c34-1","hypotheses":[{"utterance":"the rain in Spain falls mainly on the plains","confidence":0.8385102}]}

ewoudenberg commented Jun 7, 2013

In Python:

$ cat speech.py
import urllib2
url = "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US"
audio = open('rainspain.flac','rb').read()
headers={'Content-Type': 'audio/x-flac; rate=16000', 'User-Agent':'Mozilla/5.0'}
request = urllib2.Request(url, data=audio, headers=headers)
response = urllib2.urlopen(request)
print response.read()

$ python speech.py
{"status":0,"id":"57d2d1a7e7f1fa12d200026dde946c34-1","hypotheses":[{"utterance":"the rain in Spain falls mainly on the plains","confidence":0.8385102}]}

@kindziora

This comment has been minimized.

Show comment
Hide comment
@kindziora

kindziora Jul 5, 2013

google does not return anything... no result, has somebody an idea why?

kindziora commented Jul 5, 2013

google does not return anything... no result, has somebody an idea why?

@mikepultz

This comment has been minimized.

Show comment
Hide comment

mikepultz commented Jul 11, 2013

@selvakumar1989

This comment has been minimized.

Show comment
Hide comment
@selvakumar1989

selvakumar1989 Jul 24, 2013

Any one can tell how to implement this using javascript(Ajax post)

selvakumar1989 commented Jul 24, 2013

Any one can tell how to implement this using javascript(Ajax post)

@flux3000

This comment has been minimized.

Show comment
Hide comment
@flux3000

flux3000 Aug 8, 2013

Note that the API only accepts audio files of 15 seconds or less.

flux3000 commented Aug 8, 2013

Note that the API only accepts audio files of 15 seconds or less.

@AvatarDa

This comment has been minimized.

Show comment
Hide comment
@AvatarDa

AvatarDa Aug 28, 2013

use java or jsp

<%@ page import="java.io.BufferedInputStream"%>
<%@ page import="java.io.BufferedOutputStream"%>
<%@ page import="java.io.ByteArrayOutputStream"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.net.HttpURLConnection"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.Proxy"%>
<%@ page import="java.net.InetSocketAddress"%>

<%@ page import="javaFlacEncoder.FLACEncoder"%>
<%@ page import="javaFlacEncoder.FLACFileOutputStream"%>
<%@ page import="javaFlacEncoder.FLAC_FileEncoder"%>
<%@ page import="javaFlacEncoder.StreamConfiguration"%>

<%@ page import="org.apache.http.client.HttpClient"%>
<%@ page import="org.apache.http.client.methods.HttpPost"%>
<%@ page import="org.apache.http.entity.mime.MultipartEntity"%>
<%@ page import="org.apache.http.entity.mime.content.ContentBody"%>
<%@ page import="org.apache.http.entity.mime.content.FileBody"%>
<%@ page import="org.apache.commons.httpclient.params.HttpClientParams"%>
<%@ page import="org.apache.http.impl.client.DefaultHttpClient"%>
<%@ page import="org.apache.http.params.CoreProtocolPNames"%>
<%@ page import="org.apache.http.HttpVersion"%>
<%@ page import="org.apache.http.HttpResponse"%>
<%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
<%@ page import="org.apache.http.conn.params.ConnRoutePNames"%>
<%@ page import="org.apache.http.HttpHost"%>

<%@ page import="javax.sound.sampled.AudioFormat"%>
<%@ page import="javax.sound.sampled.AudioInputStream"%>
<%@ page import="javax.sound.sampled.AudioSystem"%>
<%@ page import="java.nio.ByteBuffer"%>
<%@ page import="java.nio.ByteOrder"%>

<%@ page import="java.net.URLConnection"%>

<%@ page import="java.util.Date"%>

<% String SPEECH_TEXT_TO_SERVICE = "https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
//"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE23b0826200ff4f2adcaa9e1d9ac4180a";

      String strUrl = (request.getParameter("urls")+"" != null)?request.getParameter("urls")+"":SPEECH_TEXT_TO_SERVICE;
      //SPEECH_TEXT_TO_SERVICE;
      //
      String USER_AGENT =  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) " + "Gecko/20100101 Firefox/11.0";

      URL url = new URL(strUrl);          
      Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.29", 3128));
      HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
      connection.setRequestMethod("GET");
      connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36");

      out.println(new Date().toString().substring(11,20).replaceAll("IST 2013 ","")+" =====> Starting downloading <br>");
      connection.connect();
      for (int i=0;connection.getHeaderField(i) != null;i++)
      { 
         //out.println(connection.getContentType());
      }
    Long time = connection.getDate();
    InputStream inputStream = connection.getInputStream();
      File input = new File(time+"_input.wav");

      FileOutputStream f = new FileOutputStream(input);
    OutputStream outputStream = f;
      int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = inputStream.read(bytes)) != -1) 
    {
        outputStream.write(bytes, 0, read);
    }
    outputStream.close();
    AudioInputStream audioInputStream1 = AudioSystem.getAudioInputStream(input);
    AudioFormat audioFormat1 = audioInputStream1.getFormat();
    int sampleRate =(int) audioFormat1.getSampleRate();

    out.println(new Date().toString().substring(11,20)+" =====> Create file <br>");
    File output = new File(time+"output.flac");          
      out.println(new Date().toString().substring(11,20)+" =====> FLAC Convert Start <br>");

        StreamConfiguration streamConfiguration = new StreamConfiguration();
    streamConfiguration.setSampleRate(sampleRate);
    streamConfiguration.setBitsPerSample(16);
    streamConfiguration.setChannelCount(1);

    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(input);
    AudioFormat format = audioInputStream.getFormat();

    int frameSize = format.getFrameSize();

    FLACEncoder flacEncoder = new FLACEncoder();
    FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(output);

    flacEncoder.setStreamConfiguration(streamConfiguration);
    flacEncoder.setOutputStream(flacOutputStream);

    flacEncoder.openFLACStream();

    int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
    byte[] samplesIn = new byte[frameSize];

      int x = 0;

        while (audioInputStream.read(samplesIn, 0, frameSize) != -1) {
            if (frameSize != 1) 
            {
                ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                bb.order(ByteOrder.LITTLE_ENDIAN);
                short shortVal = bb.getShort();
                sampleData[x] = shortVal;
            } else {
                sampleData[x] = samplesIn[0];
            }

            x++;
        }

    flacEncoder.addSamples(sampleData, x);
    flacEncoder.encodeSamples(x, false);
    flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

    audioInputStream.close();
    flacOutputStream.close();
    out.println(new Date().toString().substring(11,20)+" =====> Convet End <br>");
    out.println(new Date().toString().substring(11,20)+" =====> Send google api Start <br>");

    StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=10");

// sb.append("&lang=en");
sb.append("&pfilter=0");
// sb.append("&maxresults=2");
URL url1 = new URL(sb.toString());
URLConnection urlConn = url1.openConnection(proxy);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
OutputStream outputStream1 = urlConn.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(output);
byte[] buffer = new byte[1024];
while ((fileInputStream.read(buffer, 0, 256)) != -1)
{
outputStream1.write(buffer, 0, 256);
outputStream1.flush();
}
fileInputStream.close();
outputStream1.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response2 = br.readLine();
br.close();

    input.delete();
    output.delete();
      out.println(new Date().toString().substring(11,20)+" =====> receive google api result <br>");
      String resp[] = response2.split("utterance");
      for(int k=0;k<resp.length;k++)
      { resp[k]=resp[k].replaceAll("\":\"","").replace("\"},{\"","").replace("\"}]}","");
        if (k==1)
        {
            String temp[] =resp[k].split("\",\"confidence\":");
            out.println("<br> Confidence :<b> "+temp[1].replace("},{\"","")+"</b>");
            out.println("<br>"+k+" . "+temp[0]+"<br>");
        }
        else if(k==resp.length-1)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }
        else if(k!=0)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }

    }
    //out.println(response2+"<br>");
      out.println(sampleRate+"<br>");

%>

AvatarDa commented Aug 28, 2013

use java or jsp

<%@ page import="java.io.BufferedInputStream"%>
<%@ page import="java.io.BufferedOutputStream"%>
<%@ page import="java.io.ByteArrayOutputStream"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.net.HttpURLConnection"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.Proxy"%>
<%@ page import="java.net.InetSocketAddress"%>

<%@ page import="javaFlacEncoder.FLACEncoder"%>
<%@ page import="javaFlacEncoder.FLACFileOutputStream"%>
<%@ page import="javaFlacEncoder.FLAC_FileEncoder"%>
<%@ page import="javaFlacEncoder.StreamConfiguration"%>

<%@ page import="org.apache.http.client.HttpClient"%>
<%@ page import="org.apache.http.client.methods.HttpPost"%>
<%@ page import="org.apache.http.entity.mime.MultipartEntity"%>
<%@ page import="org.apache.http.entity.mime.content.ContentBody"%>
<%@ page import="org.apache.http.entity.mime.content.FileBody"%>
<%@ page import="org.apache.commons.httpclient.params.HttpClientParams"%>
<%@ page import="org.apache.http.impl.client.DefaultHttpClient"%>
<%@ page import="org.apache.http.params.CoreProtocolPNames"%>
<%@ page import="org.apache.http.HttpVersion"%>
<%@ page import="org.apache.http.HttpResponse"%>
<%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
<%@ page import="org.apache.http.conn.params.ConnRoutePNames"%>
<%@ page import="org.apache.http.HttpHost"%>

<%@ page import="javax.sound.sampled.AudioFormat"%>
<%@ page import="javax.sound.sampled.AudioInputStream"%>
<%@ page import="javax.sound.sampled.AudioSystem"%>
<%@ page import="java.nio.ByteBuffer"%>
<%@ page import="java.nio.ByteOrder"%>

<%@ page import="java.net.URLConnection"%>

<%@ page import="java.util.Date"%>

<% String SPEECH_TEXT_TO_SERVICE = "https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
//"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE23b0826200ff4f2adcaa9e1d9ac4180a";

      String strUrl = (request.getParameter("urls")+"" != null)?request.getParameter("urls")+"":SPEECH_TEXT_TO_SERVICE;
      //SPEECH_TEXT_TO_SERVICE;
      //
      String USER_AGENT =  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) " + "Gecko/20100101 Firefox/11.0";

      URL url = new URL(strUrl);          
      Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.29", 3128));
      HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
      connection.setRequestMethod("GET");
      connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36");

      out.println(new Date().toString().substring(11,20).replaceAll("IST 2013 ","")+" =====> Starting downloading <br>");
      connection.connect();
      for (int i=0;connection.getHeaderField(i) != null;i++)
      { 
         //out.println(connection.getContentType());
      }
    Long time = connection.getDate();
    InputStream inputStream = connection.getInputStream();
      File input = new File(time+"_input.wav");

      FileOutputStream f = new FileOutputStream(input);
    OutputStream outputStream = f;
      int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = inputStream.read(bytes)) != -1) 
    {
        outputStream.write(bytes, 0, read);
    }
    outputStream.close();
    AudioInputStream audioInputStream1 = AudioSystem.getAudioInputStream(input);
    AudioFormat audioFormat1 = audioInputStream1.getFormat();
    int sampleRate =(int) audioFormat1.getSampleRate();

    out.println(new Date().toString().substring(11,20)+" =====> Create file <br>");
    File output = new File(time+"output.flac");          
      out.println(new Date().toString().substring(11,20)+" =====> FLAC Convert Start <br>");

        StreamConfiguration streamConfiguration = new StreamConfiguration();
    streamConfiguration.setSampleRate(sampleRate);
    streamConfiguration.setBitsPerSample(16);
    streamConfiguration.setChannelCount(1);

    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(input);
    AudioFormat format = audioInputStream.getFormat();

    int frameSize = format.getFrameSize();

    FLACEncoder flacEncoder = new FLACEncoder();
    FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(output);

    flacEncoder.setStreamConfiguration(streamConfiguration);
    flacEncoder.setOutputStream(flacOutputStream);

    flacEncoder.openFLACStream();

    int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
    byte[] samplesIn = new byte[frameSize];

      int x = 0;

        while (audioInputStream.read(samplesIn, 0, frameSize) != -1) {
            if (frameSize != 1) 
            {
                ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                bb.order(ByteOrder.LITTLE_ENDIAN);
                short shortVal = bb.getShort();
                sampleData[x] = shortVal;
            } else {
                sampleData[x] = samplesIn[0];
            }

            x++;
        }

    flacEncoder.addSamples(sampleData, x);
    flacEncoder.encodeSamples(x, false);
    flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

    audioInputStream.close();
    flacOutputStream.close();
    out.println(new Date().toString().substring(11,20)+" =====> Convet End <br>");
    out.println(new Date().toString().substring(11,20)+" =====> Send google api Start <br>");

    StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=10");

// sb.append("&lang=en");
sb.append("&pfilter=0");
// sb.append("&maxresults=2");
URL url1 = new URL(sb.toString());
URLConnection urlConn = url1.openConnection(proxy);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
OutputStream outputStream1 = urlConn.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(output);
byte[] buffer = new byte[1024];
while ((fileInputStream.read(buffer, 0, 256)) != -1)
{
outputStream1.write(buffer, 0, 256);
outputStream1.flush();
}
fileInputStream.close();
outputStream1.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response2 = br.readLine();
br.close();

    input.delete();
    output.delete();
      out.println(new Date().toString().substring(11,20)+" =====> receive google api result <br>");
      String resp[] = response2.split("utterance");
      for(int k=0;k<resp.length;k++)
      { resp[k]=resp[k].replaceAll("\":\"","").replace("\"},{\"","").replace("\"}]}","");
        if (k==1)
        {
            String temp[] =resp[k].split("\",\"confidence\":");
            out.println("<br> Confidence :<b> "+temp[1].replace("},{\"","")+"</b>");
            out.println("<br>"+k+" . "+temp[0]+"<br>");
        }
        else if(k==resp.length-1)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }
        else if(k!=0)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }

    }
    //out.println(response2+"<br>");
      out.println(sampleRate+"<br>");

%>

@AvatarDa

This comment has been minimized.

Show comment
Hide comment
@AvatarDa

AvatarDa Aug 28, 2013

use java or jsp

<%@ page import="java.io.BufferedInputStream"%>
<%@ page import="java.io.BufferedOutputStream"%>
<%@ page import="java.io.ByteArrayOutputStream"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.net.HttpURLConnection"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.Proxy"%>
<%@ page import="java.net.InetSocketAddress"%>

<%@ page import="javaFlacEncoder.FLACEncoder"%>
<%@ page import="javaFlacEncoder.FLACFileOutputStream"%>
<%@ page import="javaFlacEncoder.FLAC_FileEncoder"%>
<%@ page import="javaFlacEncoder.StreamConfiguration"%>

<%@ page import="org.apache.http.client.HttpClient"%>
<%@ page import="org.apache.http.client.methods.HttpPost"%>
<%@ page import="org.apache.http.entity.mime.MultipartEntity"%>
<%@ page import="org.apache.http.entity.mime.content.ContentBody"%>
<%@ page import="org.apache.http.entity.mime.content.FileBody"%>
<%@ page import="org.apache.commons.httpclient.params.HttpClientParams"%>
<%@ page import="org.apache.http.impl.client.DefaultHttpClient"%>
<%@ page import="org.apache.http.params.CoreProtocolPNames"%>
<%@ page import="org.apache.http.HttpVersion"%>
<%@ page import="org.apache.http.HttpResponse"%>
<%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
<%@ page import="org.apache.http.conn.params.ConnRoutePNames"%>
<%@ page import="org.apache.http.HttpHost"%>

<%@ page import="javax.sound.sampled.AudioFormat"%>
<%@ page import="javax.sound.sampled.AudioInputStream"%>
<%@ page import="javax.sound.sampled.AudioSystem"%>
<%@ page import="java.nio.ByteBuffer"%>
<%@ page import="java.nio.ByteOrder"%>

<%@ page import="java.net.URLConnection"%>

<%@ page import="java.util.Date"%>

<% String SPEECH_TEXT_TO_SERVICE = "https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
//"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE23b0826200ff4f2adcaa9e1d9ac4180a";

      String strUrl = (request.getParameter("urls")+"" != null)?request.getParameter("urls")+"":SPEECH_TEXT_TO_SERVICE;
      //SPEECH_TEXT_TO_SERVICE;
      //
      String USER_AGENT =  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) " + "Gecko/20100101 Firefox/11.0";

      URL url = new URL(strUrl);          
      Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.29", 3128));
      HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
      connection.setRequestMethod("GET");
      connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36");

      out.println(new Date().toString().substring(11,20).replaceAll("IST 2013 ","")+" =====> Starting downloading <br>");
      connection.connect();
      for (int i=0;connection.getHeaderField(i) != null;i++)
      { 
         //out.println(connection.getContentType());
      }
    Long time = connection.getDate();
    InputStream inputStream = connection.getInputStream();
      File input = new File(time+"_input.wav");

      FileOutputStream f = new FileOutputStream(input);
    OutputStream outputStream = f;
      int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = inputStream.read(bytes)) != -1) 
    {
        outputStream.write(bytes, 0, read);
    }
    outputStream.close();
    AudioInputStream audioInputStream1 = AudioSystem.getAudioInputStream(input);
    AudioFormat audioFormat1 = audioInputStream1.getFormat();
    int sampleRate =(int) audioFormat1.getSampleRate();

    out.println(new Date().toString().substring(11,20)+" =====> Create file <br>");
    File output = new File(time+"output.flac");          
      out.println(new Date().toString().substring(11,20)+" =====> FLAC Convert Start <br>");

        StreamConfiguration streamConfiguration = new StreamConfiguration();
    streamConfiguration.setSampleRate(sampleRate);
    streamConfiguration.setBitsPerSample(16);
    streamConfiguration.setChannelCount(1);

    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(input);
    AudioFormat format = audioInputStream.getFormat();

    int frameSize = format.getFrameSize();

    FLACEncoder flacEncoder = new FLACEncoder();
    FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(output);

    flacEncoder.setStreamConfiguration(streamConfiguration);
    flacEncoder.setOutputStream(flacOutputStream);

    flacEncoder.openFLACStream();

    int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
    byte[] samplesIn = new byte[frameSize];

      int x = 0;

        while (audioInputStream.read(samplesIn, 0, frameSize) != -1) {
            if (frameSize != 1) 
            {
                ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                bb.order(ByteOrder.LITTLE_ENDIAN);
                short shortVal = bb.getShort();
                sampleData[x] = shortVal;
            } else {
                sampleData[x] = samplesIn[0];
            }

            x++;
        }

    flacEncoder.addSamples(sampleData, x);
    flacEncoder.encodeSamples(x, false);
    flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

    audioInputStream.close();
    flacOutputStream.close();
    out.println(new Date().toString().substring(11,20)+" =====> Convet End <br>");
    out.println(new Date().toString().substring(11,20)+" =====> Send google api Start <br>");

    StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=10");

// sb.append("&lang=en");
sb.append("&pfilter=0");
// sb.append("&maxresults=2");
URL url1 = new URL(sb.toString());
URLConnection urlConn = url1.openConnection(proxy);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
OutputStream outputStream1 = urlConn.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(output);
byte[] buffer = new byte[1024];
while ((fileInputStream.read(buffer, 0, 256)) != -1)
{
outputStream1.write(buffer, 0, 256);
outputStream1.flush();
}
fileInputStream.close();
outputStream1.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response2 = br.readLine();
br.close();

    input.delete();
    output.delete();
      out.println(new Date().toString().substring(11,20)+" =====> receive google api result <br>");
      String resp[] = response2.split("utterance");
      for(int k=0;k<resp.length;k++)
      { resp[k]=resp[k].replaceAll("\":\"","").replace("\"},{\"","").replace("\"}]}","");
        if (k==1)
        {
            String temp[] =resp[k].split("\",\"confidence\":");
            out.println("<br> Confidence :<b> "+temp[1].replace("},{\"","")+"</b>");
            out.println("<br>"+k+" . "+temp[0]+"<br>");
        }
        else if(k==resp.length-1)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }
        else if(k!=0)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }

    }
    //out.println(response2+"<br>");
      out.println(sampleRate+"<br>");

%>

AvatarDa commented Aug 28, 2013

use java or jsp

<%@ page import="java.io.BufferedInputStream"%>
<%@ page import="java.io.BufferedOutputStream"%>
<%@ page import="java.io.ByteArrayOutputStream"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.*"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.net.HttpURLConnection"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.Proxy"%>
<%@ page import="java.net.InetSocketAddress"%>

<%@ page import="javaFlacEncoder.FLACEncoder"%>
<%@ page import="javaFlacEncoder.FLACFileOutputStream"%>
<%@ page import="javaFlacEncoder.FLAC_FileEncoder"%>
<%@ page import="javaFlacEncoder.StreamConfiguration"%>

<%@ page import="org.apache.http.client.HttpClient"%>
<%@ page import="org.apache.http.client.methods.HttpPost"%>
<%@ page import="org.apache.http.entity.mime.MultipartEntity"%>
<%@ page import="org.apache.http.entity.mime.content.ContentBody"%>
<%@ page import="org.apache.http.entity.mime.content.FileBody"%>
<%@ page import="org.apache.commons.httpclient.params.HttpClientParams"%>
<%@ page import="org.apache.http.impl.client.DefaultHttpClient"%>
<%@ page import="org.apache.http.params.CoreProtocolPNames"%>
<%@ page import="org.apache.http.HttpVersion"%>
<%@ page import="org.apache.http.HttpResponse"%>
<%@ page import="org.apache.commons.httpclient.methods.PostMethod"%>
<%@ page import="org.apache.http.conn.params.ConnRoutePNames"%>
<%@ page import="org.apache.http.HttpHost"%>

<%@ page import="javax.sound.sampled.AudioFormat"%>
<%@ page import="javax.sound.sampled.AudioInputStream"%>
<%@ page import="javax.sound.sampled.AudioSystem"%>
<%@ page import="java.nio.ByteBuffer"%>
<%@ page import="java.nio.ByteOrder"%>

<%@ page import="java.net.URLConnection"%>

<%@ page import="java.util.Date"%>

<% String SPEECH_TEXT_TO_SERVICE = "https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
//"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE23b0826200ff4f2adcaa9e1d9ac4180a";

      String strUrl = (request.getParameter("urls")+"" != null)?request.getParameter("urls")+"":SPEECH_TEXT_TO_SERVICE;
      //SPEECH_TEXT_TO_SERVICE;
      //
      String USER_AGENT =  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) " + "Gecko/20100101 Firefox/11.0";

      URL url = new URL(strUrl);          
      Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.29", 3128));
      HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
      connection.setRequestMethod("GET");
      connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36");

      out.println(new Date().toString().substring(11,20).replaceAll("IST 2013 ","")+" =====> Starting downloading <br>");
      connection.connect();
      for (int i=0;connection.getHeaderField(i) != null;i++)
      { 
         //out.println(connection.getContentType());
      }
    Long time = connection.getDate();
    InputStream inputStream = connection.getInputStream();
      File input = new File(time+"_input.wav");

      FileOutputStream f = new FileOutputStream(input);
    OutputStream outputStream = f;
      int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = inputStream.read(bytes)) != -1) 
    {
        outputStream.write(bytes, 0, read);
    }
    outputStream.close();
    AudioInputStream audioInputStream1 = AudioSystem.getAudioInputStream(input);
    AudioFormat audioFormat1 = audioInputStream1.getFormat();
    int sampleRate =(int) audioFormat1.getSampleRate();

    out.println(new Date().toString().substring(11,20)+" =====> Create file <br>");
    File output = new File(time+"output.flac");          
      out.println(new Date().toString().substring(11,20)+" =====> FLAC Convert Start <br>");

        StreamConfiguration streamConfiguration = new StreamConfiguration();
    streamConfiguration.setSampleRate(sampleRate);
    streamConfiguration.setBitsPerSample(16);
    streamConfiguration.setChannelCount(1);

    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(input);
    AudioFormat format = audioInputStream.getFormat();

    int frameSize = format.getFrameSize();

    FLACEncoder flacEncoder = new FLACEncoder();
    FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(output);

    flacEncoder.setStreamConfiguration(streamConfiguration);
    flacEncoder.setOutputStream(flacOutputStream);

    flacEncoder.openFLACStream();

    int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
    byte[] samplesIn = new byte[frameSize];

      int x = 0;

        while (audioInputStream.read(samplesIn, 0, frameSize) != -1) {
            if (frameSize != 1) 
            {
                ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                bb.order(ByteOrder.LITTLE_ENDIAN);
                short shortVal = bb.getShort();
                sampleData[x] = shortVal;
            } else {
                sampleData[x] = samplesIn[0];
            }

            x++;
        }

    flacEncoder.addSamples(sampleData, x);
    flacEncoder.encodeSamples(x, false);
    flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

    audioInputStream.close();
    flacOutputStream.close();
    out.println(new Date().toString().substring(11,20)+" =====> Convet End <br>");
    out.println(new Date().toString().substring(11,20)+" =====> Send google api Start <br>");

    StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=10");

// sb.append("&lang=en");
sb.append("&pfilter=0");
// sb.append("&maxresults=2");
URL url1 = new URL(sb.toString());
URLConnection urlConn = url1.openConnection(proxy);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
OutputStream outputStream1 = urlConn.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(output);
byte[] buffer = new byte[1024];
while ((fileInputStream.read(buffer, 0, 256)) != -1)
{
outputStream1.write(buffer, 0, 256);
outputStream1.flush();
}
fileInputStream.close();
outputStream1.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response2 = br.readLine();
br.close();

    input.delete();
    output.delete();
      out.println(new Date().toString().substring(11,20)+" =====> receive google api result <br>");
      String resp[] = response2.split("utterance");
      for(int k=0;k<resp.length;k++)
      { resp[k]=resp[k].replaceAll("\":\"","").replace("\"},{\"","").replace("\"}]}","");
        if (k==1)
        {
            String temp[] =resp[k].split("\",\"confidence\":");
            out.println("<br> Confidence :<b> "+temp[1].replace("},{\"","")+"</b>");
            out.println("<br>"+k+" . "+temp[0]+"<br>");
        }
        else if(k==resp.length-1)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }
        else if(k!=0)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }

    }
    //out.println(response2+"<br>");
      out.println(sampleRate+"<br>");

%>

@AvatarDa

This comment has been minimized.

Show comment
Hide comment
@AvatarDa

AvatarDa Aug 28, 2013

<%@ page import="java.io.File"%>
<%@ page import="java.io.InputStream"%>
<%@ page import="java.io.OutputStream"%>
<%@ page import="java.io.BufferedReader"%>
<%@ page import="java.io.InputStreamReader"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.net.HttpURLConnection"%>

<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLConnection"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.Proxy"%>
<%@ page import="java.net.InetSocketAddress"%>

<%@ page import="javaFlacEncoder.FLACEncoder"%>
<%@ page import="javaFlacEncoder.FLACFileOutputStream"%>
<%@ page import="javaFlacEncoder.FLAC_FileEncoder"%>
<%@ page import="javaFlacEncoder.StreamConfiguration"%>

<%@ page import="javax.sound.sampled.AudioFormat"%>
<%@ page import="javax.sound.sampled.AudioInputStream"%>
<%@ page import="javax.sound.sampled.AudioSystem"%>

<%@ page import="java.nio.ByteBuffer"%>
<%@ page import="java.nio.ByteOrder"%>

<%@ page import="java.util.Date"%>

<%

      String SPEECH_TEXT_TO_SERVICE = "https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE23b0826200ff4f2adcaa9e1d9ac4180a";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/REc17df0c2d73720fbc55cf6c28f584fca";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
      //"http://rajesh-zu273:8080/audiotest/speach.wav";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE45b081bfe0f00a3cddac4c27512d0159";
      //
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE5c752448b7498b68125e33cdf9c971dd";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE26ecb20f15953f6177fda582f9a32aa4";
      //"https://api.twilio.com/2010-04-01/Accounts/ACda006002ebc844b68606b05be0df5e4c/Recordings/REfda7271ce5acc220258dcc1f48d210c2";
      //"http://www5.online-convert.com/download-file/c700fea6cbfc16e7b2172c7f89602a62/converted-b2773e34.wav";
      //"http://www5.online-convert.com/download-file/353123ab67c2ec6659f3722230df2713/converted-fa81c0f8.wav";
      //"http://www19.online-convert.com/download-file/7466a3c51f7c5875e01335a3d5212b7f/converted-6b28c038.wav";
      String strUrl = (request.getParameter("url")+"" != null)?request.getParameter("url")+"":SPEECH_TEXT_TO_SERVICE;

      String USER_AGENT =  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) " + "Gecko/20100101 Firefox/11.0";

      URL url = new URL(strUrl);          
      Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.29", 3128));
      HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
      connection.setRequestMethod("GET");
      connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36");

      out.println(new Date().toString().substring(11,20).replaceAll("IST 2013 ","")+" =====> Starting downloading <br>");
      connection.connect();

    Long time = connection.getDate();
    InputStream inputStream = connection.getInputStream();
      File input = new File(time+"_input.wav");

      FileOutputStream f = new FileOutputStream(input);
    OutputStream outputStream = f;
      int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = inputStream.read(bytes)) != -1) 
    {
        outputStream.write(bytes, 0, read);
    }
    outputStream.close();



    AudioInputStream audioInputStream1 = AudioSystem.getAudioInputStream(input);
    AudioFormat audioFormat1 = audioInputStream1.getFormat();
    int sampleRate =(int) audioFormat1.getSampleRate();

    out.println(new Date().toString().substring(11,20)+" =====> Create file <br>");
    File output = new File(time+"output.flac");  


    //FLAC Convert Start

      out.println(new Date().toString().substring(11,20)+" =====> FLAC Convert Start <br>");

    StreamConfiguration streamConfiguration = new StreamConfiguration();
    streamConfiguration.setSampleRate(sampleRate);
    streamConfiguration.setBitsPerSample(16);
    streamConfiguration.setChannelCount(1);

    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(input);
    AudioFormat format = audioInputStream.getFormat();

    int frameSize = format.getFrameSize();

    FLACEncoder flacEncoder = new FLACEncoder();
    FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(output);

    flacEncoder.setStreamConfiguration(streamConfiguration);
    flacEncoder.setOutputStream(flacOutputStream);

    flacEncoder.openFLACStream();

    int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
    byte[] samplesIn = new byte[frameSize];

      int x = 0;
    while (audioInputStream.read(samplesIn, 0, frameSize) != -1) 
    {
            if (frameSize != 1) 
            {
                ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                bb.order(ByteOrder.LITTLE_ENDIAN);
                short shortVal = bb.getShort();
                sampleData[x] = shortVal;
            }
            else
            {
                sampleData[x] = samplesIn[0];
            }
            x++;
        }

    flacEncoder.addSamples(sampleData, x);
    flacEncoder.encodeSamples(x, false);
    flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

    audioInputStream.close();
    flacOutputStream.close();

    //FLAC Convert Start
    out.println(new Date().toString().substring(11,20)+" =====> Convet End <br>");

    out.println(new Date().toString().substring(11,20)+" =====> Send google api Start <br>");


    StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=10");

// sb.append("&lang=en");
sb.append("&pfilter=0");
// sb.append("&maxresults=2");
URL url1 = new URL(sb.toString());
URLConnection urlConn = url1.openConnection(proxy);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
OutputStream outputStream1 = urlConn.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(output);
byte[] buffer = new byte[1024];
while ((fileInputStream.read(buffer, 0, 256)) != -1)
{
outputStream1.write(buffer, 0, 256);
outputStream1.flush();
}
fileInputStream.close();
outputStream1.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response2 = br.readLine();
br.close();

    input.delete();
    output.delete();
      out.println(new Date().toString().substring(11,20)+" =====> receive google api result <br>");
      String resp[] = response2.split("utterance");
      for(int k=0;k<resp.length;k++)
      { resp[k]=resp[k].replaceAll("\":\"","").replace("\"},{\"","").replace("\"}]}","");
        if (k==1)
        {
            String temp[] =resp[k].split("\",\"confidence\":");
            out.println("<br> Confidence :<b> "+temp[1].replace("},{\"","")+"</b>");
            out.println("<br>"+k+" . "+temp[0]+"<br>");
        }
        else if(k==resp.length-1)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }
        else if(k!=0)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }

    }
    //out.println(response2+"<br>");
      out.println(sampleRate+"<br>");

%>

AvatarDa commented Aug 28, 2013

<%@ page import="java.io.File"%>
<%@ page import="java.io.InputStream"%>
<%@ page import="java.io.OutputStream"%>
<%@ page import="java.io.BufferedReader"%>
<%@ page import="java.io.InputStreamReader"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.net.HttpURLConnection"%>

<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLConnection"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.Proxy"%>
<%@ page import="java.net.InetSocketAddress"%>

<%@ page import="javaFlacEncoder.FLACEncoder"%>
<%@ page import="javaFlacEncoder.FLACFileOutputStream"%>
<%@ page import="javaFlacEncoder.FLAC_FileEncoder"%>
<%@ page import="javaFlacEncoder.StreamConfiguration"%>

<%@ page import="javax.sound.sampled.AudioFormat"%>
<%@ page import="javax.sound.sampled.AudioInputStream"%>
<%@ page import="javax.sound.sampled.AudioSystem"%>

<%@ page import="java.nio.ByteBuffer"%>
<%@ page import="java.nio.ByteOrder"%>

<%@ page import="java.util.Date"%>

<%

      String SPEECH_TEXT_TO_SERVICE = "https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE23b0826200ff4f2adcaa9e1d9ac4180a";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/REc17df0c2d73720fbc55cf6c28f584fca";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE8a3e55ab37113780ca65f1e02fa1ad11";
      //"http://rajesh-zu273:8080/audiotest/speach.wav";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE45b081bfe0f00a3cddac4c27512d0159";
      //
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE5c752448b7498b68125e33cdf9c971dd";
      //"https://api.twilio.com/2010-04-01/Accounts/AC9d34d1192faffb0989f0227e5768d24d/Recordings/RE26ecb20f15953f6177fda582f9a32aa4";
      //"https://api.twilio.com/2010-04-01/Accounts/ACda006002ebc844b68606b05be0df5e4c/Recordings/REfda7271ce5acc220258dcc1f48d210c2";
      //"http://www5.online-convert.com/download-file/c700fea6cbfc16e7b2172c7f89602a62/converted-b2773e34.wav";
      //"http://www5.online-convert.com/download-file/353123ab67c2ec6659f3722230df2713/converted-fa81c0f8.wav";
      //"http://www19.online-convert.com/download-file/7466a3c51f7c5875e01335a3d5212b7f/converted-6b28c038.wav";
      String strUrl = (request.getParameter("url")+"" != null)?request.getParameter("url")+"":SPEECH_TEXT_TO_SERVICE;

      String USER_AGENT =  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) " + "Gecko/20100101 Firefox/11.0";

      URL url = new URL(strUrl);          
      Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.53.29", 3128));
      HttpURLConnection connection=(HttpURLConnection) url.openConnection(proxy);
      connection.setRequestMethod("GET");
      connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.70 Safari/537.36");

      out.println(new Date().toString().substring(11,20).replaceAll("IST 2013 ","")+" =====> Starting downloading <br>");
      connection.connect();

    Long time = connection.getDate();
    InputStream inputStream = connection.getInputStream();
      File input = new File(time+"_input.wav");

      FileOutputStream f = new FileOutputStream(input);
    OutputStream outputStream = f;
      int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = inputStream.read(bytes)) != -1) 
    {
        outputStream.write(bytes, 0, read);
    }
    outputStream.close();



    AudioInputStream audioInputStream1 = AudioSystem.getAudioInputStream(input);
    AudioFormat audioFormat1 = audioInputStream1.getFormat();
    int sampleRate =(int) audioFormat1.getSampleRate();

    out.println(new Date().toString().substring(11,20)+" =====> Create file <br>");
    File output = new File(time+"output.flac");  


    //FLAC Convert Start

      out.println(new Date().toString().substring(11,20)+" =====> FLAC Convert Start <br>");

    StreamConfiguration streamConfiguration = new StreamConfiguration();
    streamConfiguration.setSampleRate(sampleRate);
    streamConfiguration.setBitsPerSample(16);
    streamConfiguration.setChannelCount(1);

    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(input);
    AudioFormat format = audioInputStream.getFormat();

    int frameSize = format.getFrameSize();

    FLACEncoder flacEncoder = new FLACEncoder();
    FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(output);

    flacEncoder.setStreamConfiguration(streamConfiguration);
    flacEncoder.setOutputStream(flacOutputStream);

    flacEncoder.openFLACStream();

    int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
    byte[] samplesIn = new byte[frameSize];

      int x = 0;
    while (audioInputStream.read(samplesIn, 0, frameSize) != -1) 
    {
            if (frameSize != 1) 
            {
                ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                bb.order(ByteOrder.LITTLE_ENDIAN);
                short shortVal = bb.getShort();
                sampleData[x] = shortVal;
            }
            else
            {
                sampleData[x] = samplesIn[0];
            }
            x++;
        }

    flacEncoder.addSamples(sampleData, x);
    flacEncoder.encodeSamples(x, false);
    flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

    audioInputStream.close();
    flacOutputStream.close();

    //FLAC Convert Start
    out.println(new Date().toString().substring(11,20)+" =====> Convet End <br>");

    out.println(new Date().toString().substring(11,20)+" =====> Send google api Start <br>");


    StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=10");

// sb.append("&lang=en");
sb.append("&pfilter=0");
// sb.append("&maxresults=2");
URL url1 = new URL(sb.toString());
URLConnection urlConn = url1.openConnection(proxy);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
OutputStream outputStream1 = urlConn.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(output);
byte[] buffer = new byte[1024];
while ((fileInputStream.read(buffer, 0, 256)) != -1)
{
outputStream1.write(buffer, 0, 256);
outputStream1.flush();
}
fileInputStream.close();
outputStream1.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response2 = br.readLine();
br.close();

    input.delete();
    output.delete();
      out.println(new Date().toString().substring(11,20)+" =====> receive google api result <br>");
      String resp[] = response2.split("utterance");
      for(int k=0;k<resp.length;k++)
      { resp[k]=resp[k].replaceAll("\":\"","").replace("\"},{\"","").replace("\"}]}","");
        if (k==1)
        {
            String temp[] =resp[k].split("\",\"confidence\":");
            out.println("<br> Confidence :<b> "+temp[1].replace("},{\"","")+"</b>");
            out.println("<br>"+k+" . "+temp[0]+"<br>");
        }
        else if(k==resp.length-1)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }
        else if(k!=0)
        {
            out.println(k+" . "+resp[k]+"<br>");
        }

    }
    //out.println(response2+"<br>");
      out.println(sampleRate+"<br>");

%>

@AvatarDa

This comment has been minimized.

Show comment
Hide comment
@AvatarDa

AvatarDa commented Sep 3, 2013

@kumachan2013

This comment has been minimized.

Show comment
Hide comment
@kumachan2013

kumachan2013 Sep 3, 2013

Flux3000 mentioned above that "Note that the API only accepts audio files of 15 seconds or less." Is there any way to make it longer? I would like to convert longer audio files to text like 2 or 3 minutes. Has anyone tried it yet?

kumachan2013 commented Sep 3, 2013

Flux3000 mentioned above that "Note that the API only accepts audio files of 15 seconds or less." Is there any way to make it longer? I would like to convert longer audio files to text like 2 or 3 minutes. Has anyone tried it yet?

@titanioverde

This comment has been minimized.

Show comment
Hide comment
@titanioverde

titanioverde Oct 10, 2013

Just tested from Python, with @ewoudenberg wonderfully simple script.
Still working. Perfectly when audio is clear enough.

I guess @kumachan2013 already found a solution. The first workaround I can think about is to split the audio on every pause (commas and periods). If there's an easy way to detect a pause in your audio, that is. ^_^u

titanioverde commented Oct 10, 2013

Just tested from Python, with @ewoudenberg wonderfully simple script.
Still working. Perfectly when audio is clear enough.

I guess @kumachan2013 already found a solution. The first workaround I can think about is to split the audio on every pause (commas and periods). If there's an easy way to detect a pause in your audio, that is. ^_^u

@zjh1943

This comment has been minimized.

Show comment
Hide comment
@zjh1943

zjh1943 Dec 18, 2013

i have tried the command below:

curl -v -X POST \
--data-binary @speech.flac \
--user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7' \
--header 'Content-Type: audio/x-flac; rate=8000;' \
'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=zh-CN&maxresults=10' 

It never works but return as below:

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 500 (Server Error)!!1</title>
  <style>
   ...
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>500.</b> <ins>That’s an error.</ins>
  <p>The server encountered an error and could not complete your request.<p>If the problem persists, please <A HREF="http://www.google.com/support/">report</A> your problem and mention this error message and the query that caused it.  <ins>That’s all we know.</ins>

does anyone have the same problem?

zjh1943 commented Dec 18, 2013

i have tried the command below:

curl -v -X POST \
--data-binary @speech.flac \
--user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7' \
--header 'Content-Type: audio/x-flac; rate=8000;' \
'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=zh-CN&maxresults=10' 

It never works but return as below:

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 500 (Server Error)!!1</title>
  <style>
   ...
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>500.</b> <ins>That’s an error.</ins>
  <p>The server encountered an error and could not complete your request.<p>If the problem persists, please <A HREF="http://www.google.com/support/">report</A> your problem and mention this error message and the query that caused it.  <ins>That’s all we know.</ins>

does anyone have the same problem?

@imskull

This comment has been minimized.

Show comment
Hide comment
@imskull

imskull Dec 26, 2013

@zjh1943, I had encountered the same error when I set incorrect sample rate, I found this notice:
** Your sample rate must match your file- if it doesn’t, you’ll either get nothing returned, or you’ll get a really bad transcription. **
at http://mikepultz.com/2013/07/google-speech-api-full-duplex-php-version/, so check your sample rate.

imskull commented Dec 26, 2013

@zjh1943, I had encountered the same error when I set incorrect sample rate, I found this notice:
** Your sample rate must match your file- if it doesn’t, you’ll either get nothing returned, or you’ll get a really bad transcription. **
at http://mikepultz.com/2013/07/google-speech-api-full-duplex-php-version/, so check your sample rate.

@gillesdemey

This comment has been minimized.

Show comment
Hide comment
@gillesdemey

gillesdemey Feb 23, 2014

Google has a second version of their API available, I've posted some research and examples in a seperate repository. https://github.com/gillesdemey/google-speech-v2

gillesdemey commented Feb 23, 2014

Google has a second version of their API available, I've posted some research and examples in a seperate repository. https://github.com/gillesdemey/google-speech-v2

@shobhitsingh

This comment has been minimized.

Show comment
Hide comment
@shobhitsingh

shobhitsingh Mar 11, 2014

I have tried both first and second versions of the API. They are too slow. Don't know how the speech demo is so fast (https://www.google.com/intl/en/chrome/demos/speech.html).
Even spoofing doesn't seems to work.
Has anyone got it work close to the Chrome demo.

shobhitsingh commented Mar 11, 2014

I have tried both first and second versions of the API. They are too slow. Don't know how the speech demo is so fast (https://www.google.com/intl/en/chrome/demos/speech.html).
Even spoofing doesn't seems to work.
Has anyone got it work close to the Chrome demo.

@rowntreerob

This comment has been minimized.

Show comment
Hide comment
@rowntreerob

rowntreerob Mar 20, 2014

im showing a rate limit of 50 per day @ https://console.developers.google.com/ for the speech-api/v2 mention by @gillesdemey . There does not appear to be any way to up the increase the limit or to pay for an increased limit.

any advice? I have an app ready for beta making extensive use of V2 speech-api.

rowntreerob commented Mar 20, 2014

im showing a rate limit of 50 per day @ https://console.developers.google.com/ for the speech-api/v2 mention by @gillesdemey . There does not appear to be any way to up the increase the limit or to pay for an increased limit.

any advice? I have an app ready for beta making extensive use of V2 speech-api.

@achilez

This comment has been minimized.

Show comment
Hide comment
@achilez

achilez Apr 1, 2014

another award winning piece from Google

achilez commented Apr 1, 2014

another award winning piece from Google

@fritz-fritz

This comment has been minimized.

Show comment
Hide comment
@fritz-fritz

fritz-fritz Apr 17, 2014

any way to have google detect the language instead of specifying?

fritz-fritz commented Apr 17, 2014

any way to have google detect the language instead of specifying?

@zakimak9

This comment has been minimized.

Show comment
Hide comment
@zakimak9

zakimak9 Apr 22, 2014

The version 1 does not seem to work and returns HTTP 500 error code. The version 2 executes but sends back an empty response. Like this:
{ "result": [ ] }

zakimak9 commented Apr 22, 2014

The version 1 does not seem to work and returns HTTP 500 error code. The version 2 executes but sends back an empty response. Like this:
{ "result": [ ] }

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli Apr 25, 2014

It used to work for a longer audio file but now it only works for a smaller then 100kb file or 15 seconds.
Does someone has a way to sent longer files like 30 seconds ?
For now the only way I'm thinking of is to split the audio file but there must be another way because in the chrome browser it works for a longer audio.

orelisraeli commented Apr 25, 2014

It used to work for a longer audio file but now it only works for a smaller then 100kb file or 15 seconds.
Does someone has a way to sent longer files like 30 seconds ?
For now the only way I'm thinking of is to split the audio file but there must be another way because in the chrome browser it works for a longer audio.

@loureiromahia

This comment has been minimized.

Show comment
Hide comment
@loureiromahia

loureiromahia May 7, 2014

Alotaiba:
I don't know what is happening, but since yesterday API is not working for me: I sent this request:

wget -q0 --post-file "$1" --header 'Content-type: audio/x-flac; rate=8000' "$URL" > result.json

where URL="https://www.google.com/speech-api/v1/recognize?lang=es_ES.utf8&client=chromium" (for spanish)
or URL="https://www.google.com/speech-api/v1/recognize?lang=en_US.utf8&client=chromium" (for english)

" $1" is a speech file in .flac format.

SINCE YESTERDAY I ALWAYS GET "400 BAD REQUEST".

WHAT HAS BEEN CHANGED???
PLEASE ANSWER ME; IT IS URGENT, as i am using this API for a project in my University and within this month i have to deliver it...

THANKS IN ADVANCE
M.Loureiro

loureiromahia commented May 7, 2014

Alotaiba:
I don't know what is happening, but since yesterday API is not working for me: I sent this request:

wget -q0 --post-file "$1" --header 'Content-type: audio/x-flac; rate=8000' "$URL" > result.json

where URL="https://www.google.com/speech-api/v1/recognize?lang=es_ES.utf8&client=chromium" (for spanish)
or URL="https://www.google.com/speech-api/v1/recognize?lang=en_US.utf8&client=chromium" (for english)

" $1" is a speech file in .flac format.

SINCE YESTERDAY I ALWAYS GET "400 BAD REQUEST".

WHAT HAS BEEN CHANGED???
PLEASE ANSWER ME; IT IS URGENT, as i am using this API for a project in my University and within this month i have to deliver it...

THANKS IN ADVANCE
M.Loureiro

@code5381

This comment has been minimized.

Show comment
Hide comment
@code5381

code5381 May 7, 2014

loureiromahia, You have to change the URL.

  1. host : https://www.google.com/speech-api/v2/recognize
  2. encoding
    FLAC
    Flac file; 44100Hz 32bit float, exported with Audacity. Check the audio folder in this repository for some hilarious examples.
    Channels : 2
    Sample Rate : 44100
    Precision : 32-bit
    Sample Encoding: 32-bit Float

16-bit PCM
The following audio options are confirmed working for 16-bit PCM sample encoding:
Channels : 1
Sample Rate : 16000
Precision : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

  1. key
    AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

For example(AS3)

.
.
.
var PATH:String = "https://www.google.com/speech-api/v2/recognize?output=json&lang=en_US&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4";
var urlRequest:URLRequest = new URLRequest(PATH);
var urlLoader:URLLoader = new URLLoader();
urlRequest.contentType = "audio/x-flac; rate=44100";
//urlRequest.contentType = "audio/l16; rate=16000";
urlRequest.data = flacData;
urlRequest.method = URLRequestMethod.POST;
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.addEventListener(ErrorEvent.ERROR, urlLoader_error);
urlLoader.load(urlRequest);
.
.
.

http://storyjava.tistory.com/ (Korean)
https://github.com/gillesdemey/google-speech-v2

Good luck!

code5381 commented May 7, 2014

loureiromahia, You have to change the URL.

  1. host : https://www.google.com/speech-api/v2/recognize
  2. encoding
    FLAC
    Flac file; 44100Hz 32bit float, exported with Audacity. Check the audio folder in this repository for some hilarious examples.
    Channels : 2
    Sample Rate : 44100
    Precision : 32-bit
    Sample Encoding: 32-bit Float

16-bit PCM
The following audio options are confirmed working for 16-bit PCM sample encoding:
Channels : 1
Sample Rate : 16000
Precision : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

  1. key
    AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

For example(AS3)

.
.
.
var PATH:String = "https://www.google.com/speech-api/v2/recognize?output=json&lang=en_US&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4";
var urlRequest:URLRequest = new URLRequest(PATH);
var urlLoader:URLLoader = new URLLoader();
urlRequest.contentType = "audio/x-flac; rate=44100";
//urlRequest.contentType = "audio/l16; rate=16000";
urlRequest.data = flacData;
urlRequest.method = URLRequestMethod.POST;
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.addEventListener(ErrorEvent.ERROR, urlLoader_error);
urlLoader.load(urlRequest);
.
.
.

http://storyjava.tistory.com/ (Korean)
https://github.com/gillesdemey/google-speech-v2

Good luck!

@loureiromahia

This comment has been minimized.

Show comment
Hide comment
@loureiromahia

loureiromahia May 7, 2014

Thanks a lot for your quick answer. I will try with the v2 API, following your recommendations. I will let you know.

Regards:
M.Loureiro

loureiromahia commented May 7, 2014

Thanks a lot for your quick answer. I will try with the v2 API, following your recommendations. I will let you know.

Regards:
M.Loureiro

@loureiromahia

This comment has been minimized.

Show comment
Hide comment
@loureiromahia

loureiromahia May 7, 2014

Anyhow, can you confirm that this is going to work??:

wget -q0 --post-file "$1" --header 'Content-type: audio/x-flac; rate=16000' "$URL" > result.json

where URL="https://www.google.com/speech-api/v1/recognize?lang=es_ES.utf8&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4" (for spanish)
or URL="https://www.google.com/speech-api/v1/recognize?lang=en_US.utf8&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4" (for english)

" $1" is a speech file in .flac format.
Or do i have to do something different?...

Thanks:
M.LOUREIRO

loureiromahia commented May 7, 2014

Anyhow, can you confirm that this is going to work??:

wget -q0 --post-file "$1" --header 'Content-type: audio/x-flac; rate=16000' "$URL" > result.json

where URL="https://www.google.com/speech-api/v1/recognize?lang=es_ES.utf8&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4" (for spanish)
or URL="https://www.google.com/speech-api/v1/recognize?lang=en_US.utf8&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4" (for english)

" $1" is a speech file in .flac format.
Or do i have to do something different?...

Thanks:
M.LOUREIRO

@code5381

This comment has been minimized.

Show comment
Hide comment
@code5381

code5381 May 7, 2014

  1. Check the URL again.

    not v1 but v2.

    my code in JSP is...

StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v2/recognize?");
sb.append("output=json");
sb.append("&lang=en-US");
sb.append("&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4");

  1. Check the rate.

    You have to set the rate to be equal to the rate of the FLAC file's rate.

    "Content-Type", "audio/x-flac; rate={ *** FLAC file's rate *** }"

It should be work if you keep the rules. :)

code5381 commented May 7, 2014

  1. Check the URL again.

    not v1 but v2.

    my code in JSP is...

StringBuilder sb = new StringBuilder("https://www.google.com/speech-api/v2/recognize?");
sb.append("output=json");
sb.append("&lang=en-US");
sb.append("&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4");

  1. Check the rate.

    You have to set the rate to be equal to the rate of the FLAC file's rate.

    "Content-Type", "audio/x-flac; rate={ *** FLAC file's rate *** }"

It should be work if you keep the rules. :)

@loureiromahia

This comment has been minimized.

Show comment
Hide comment
@loureiromahia

loureiromahia May 7, 2014

Hello, code5381:

IT IS WORKING:

{"result":[]}
{"result":[{"alternative":[{"transcript":"Hola OpenDomo","confidence":0.95670336
},{"transcript":"holaaa OpenDomo"},{"transcript":"Olga OpenDomo"},{"transcript":
"Hola a OpenDomo"},{"transcript":"hola a OpenDomo"}],"final":true}],"result_inde
x":0}

But it creates to me a file like this:
recognize?output=json&lang=es_ES&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

For me, it is more or less OK, but there are some points that may help me:

1.Now it returns to me several alternatives...In my case,the first one is the valid one... Is it posible to change the bahavior to return only 1st alternative as before??

  1. The answer time seems to be much longer than before ...may be that this is due to this deeper analisys..isn't it? ...Is it posible to improve the speed? Take into account that i am working in areal time product which it is always listening, and when detects voice , makes simething.... I am working in OpenDomo_VR project (you can get some info in github looking for OpenDomo_VR)....
  2. Is it posible to specify an output file instead of that starnge file name: recognize?output=json&lang=es_ES&key=AIza****???

Thanks in advance:
M.Loureiro

loureiromahia commented May 7, 2014

Hello, code5381:

IT IS WORKING:

{"result":[]}
{"result":[{"alternative":[{"transcript":"Hola OpenDomo","confidence":0.95670336
},{"transcript":"holaaa OpenDomo"},{"transcript":"Olga OpenDomo"},{"transcript":
"Hola a OpenDomo"},{"transcript":"hola a OpenDomo"}],"final":true}],"result_inde
x":0}

But it creates to me a file like this:
recognize?output=json&lang=es_ES&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

For me, it is more or less OK, but there are some points that may help me:

1.Now it returns to me several alternatives...In my case,the first one is the valid one... Is it posible to change the bahavior to return only 1st alternative as before??

  1. The answer time seems to be much longer than before ...may be that this is due to this deeper analisys..isn't it? ...Is it posible to improve the speed? Take into account that i am working in areal time product which it is always listening, and when detects voice , makes simething.... I am working in OpenDomo_VR project (you can get some info in github looking for OpenDomo_VR)....
  2. Is it posible to specify an output file instead of that starnge file name: recognize?output=json&lang=es_ES&key=AIza****???

Thanks in advance:
M.Loureiro

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

Hi, I am having same issue as previous poster. My code was running perfectly, until last night.

I have now updated the URL to v2 as per previous suggestion but am still getting same response. The connection attempts, is apparently connected but then retrys and I get no response back....

size=321kB time=5.02 bitrate= 524.6kbits/s
video:0kB audio:313kB global headers:0kB muxing overhead 2.573212%
Processing...
--2014-05-07 10:12:13-- https://www.google.com/speech-api/v2/recognize?lang=en-us&client=chromium
Resolving www.google.com (www.google.com)... 173.194.41.178, 173.194.41.180, 173.194.41.179, ...
Connecting to www.google.com (www.google.com)|173.194.41.178|:443... connected.
Retrying.

--2014-05-07 10:12:20-- (try: 2) https://www.google.com/speech-api/v2/recognize?lang=en-us&client=chromium

..then I get nothing further. Have tried http / https for both v1 and v2 versions of URL. Have also tried on 2 diffrent machines from 2 different locations so do not believe I have hit the daily request limit.

All input greatfully received!

D.

davejavu1969 commented May 7, 2014

Hi, I am having same issue as previous poster. My code was running perfectly, until last night.

I have now updated the URL to v2 as per previous suggestion but am still getting same response. The connection attempts, is apparently connected but then retrys and I get no response back....

size=321kB time=5.02 bitrate= 524.6kbits/s
video:0kB audio:313kB global headers:0kB muxing overhead 2.573212%
Processing...
--2014-05-07 10:12:13-- https://www.google.com/speech-api/v2/recognize?lang=en-us&client=chromium
Resolving www.google.com (www.google.com)... 173.194.41.178, 173.194.41.180, 173.194.41.179, ...
Connecting to www.google.com (www.google.com)|173.194.41.178|:443... connected.
Retrying.

--2014-05-07 10:12:20-- (try: 2) https://www.google.com/speech-api/v2/recognize?lang=en-us&client=chromium

..then I get nothing further. Have tried http / https for both v1 and v2 versions of URL. Have also tried on 2 diffrent machines from 2 different locations so do not believe I have hit the daily request limit.

All input greatfully received!

D.

@loureiromahia

This comment has been minimized.

Show comment
Hide comment
@loureiromahia

loureiromahia May 7, 2014

Hello:

I am "the previous poster", maybe i can help you, as i see that you send the request with the "old fashion"...You use client=chromium...You should use the key...this was the solution in my case....

So, i think you should replace:
https://www.google.com/speech-api/v2/recognize?lang=en-us&client=chromium
by:
https://www.google.com/speech-api/v2/recognize?lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

In my case, it is working in this way....

Hope it helps...
M:Loureiro

loureiromahia commented May 7, 2014

Hello:

I am "the previous poster", maybe i can help you, as i see that you send the request with the "old fashion"...You use client=chromium...You should use the key...this was the solution in my case....

So, i think you should replace:
https://www.google.com/speech-api/v2/recognize?lang=en-us&client=chromium
by:
https://www.google.com/speech-api/v2/recognize?lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

In my case, it is working in this way....

Hope it helps...
M:Loureiro

@quyetnv8893

This comment has been minimized.

Show comment
Hide comment
@quyetnv8893

quyetnv8893 May 7, 2014

Hi loureiromahia,
I already do like your comment
"Content-Type", "audio/x-flac; rate=44100"
and the url also is
https://www.google.com/speech-api/v2/recognize?lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4
I just use audio flac file good-morning-google.flac form github https://github.com/gillesdemey/google-speech-v2
But it return me :
{"result":[]}
Can you tell me why?
Thanks a lot!

quyetnv8893 commented May 7, 2014

Hi loureiromahia,
I already do like your comment
"Content-Type", "audio/x-flac; rate=44100"
and the url also is
https://www.google.com/speech-api/v2/recognize?lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4
I just use audio flac file good-morning-google.flac form github https://github.com/gillesdemey/google-speech-v2
But it return me :
{"result":[]}
Can you tell me why?
Thanks a lot!

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

Hi there,

Thanks LOADS for your reply! - I am seriously struggling here atm. That has certainly made some progress, but I think maybe the code I am using cannot understand the response from v2 of the api.

My original POST was....

wget -q -U "Mozilla/5.0" --post-file file.flac --header "Content-Type: audio/x-flac; rate=44100" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium" | cut -d" -f12 >stt.txt

Which worked every time with a word perfect response saved to stt.txt - until last night. Grrr.

Have updated this to....

wget -q -U "Mozilla/5.0" --post-file file.flac --header "Content-Type: audio/x-flac; rate=44100" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4" | cut -d" -f12 >stt.txt

I can now connect to server, and get a reponse - but very very slowly as you also said.

I am writing in Python & the original v1 api call returned a perfect response everytime and was saved in stt.txt which I am then passing to another part of the app.

I now get a 200 OK response from google and I am receiving an approx 100k file back for a 5 second flac file sent to the v2 api and this is written to SDTOUT - but nothing happens next, and nothing is written to stt.txt.

Was the original response a from v1 in json format?

I had one response where I said 'testing' repeatedly for five seconds, and stt.txt contained just the word 'final' ?! all other tests have produced nothing written to the text file.

All help gratefully received! - I has a fully working app ready for a project demo next week, until last night, so this is extremely frustrating to say the least.

Many thanks,

D.

davejavu1969 commented May 7, 2014

Hi there,

Thanks LOADS for your reply! - I am seriously struggling here atm. That has certainly made some progress, but I think maybe the code I am using cannot understand the response from v2 of the api.

My original POST was....

wget -q -U "Mozilla/5.0" --post-file file.flac --header "Content-Type: audio/x-flac; rate=44100" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium" | cut -d" -f12 >stt.txt

Which worked every time with a word perfect response saved to stt.txt - until last night. Grrr.

Have updated this to....

wget -q -U "Mozilla/5.0" --post-file file.flac --header "Content-Type: audio/x-flac; rate=44100" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4" | cut -d" -f12 >stt.txt

I can now connect to server, and get a reponse - but very very slowly as you also said.

I am writing in Python & the original v1 api call returned a perfect response everytime and was saved in stt.txt which I am then passing to another part of the app.

I now get a 200 OK response from google and I am receiving an approx 100k file back for a 5 second flac file sent to the v2 api and this is written to SDTOUT - but nothing happens next, and nothing is written to stt.txt.

Was the original response a from v1 in json format?

I had one response where I said 'testing' repeatedly for five seconds, and stt.txt contained just the word 'final' ?! all other tests have produced nothing written to the text file.

All help gratefully received! - I has a fully working app ready for a project demo next week, until last night, so this is extremely frustrating to say the least.

Many thanks,

D.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

One other thing to note - does the key we are now all using belong to poster code5381 ? - If so how do you get your own key & is there still the 50 per day request limit. If so, we are going to hit this rather quickly if we are all trying v2 with this key.

davejavu1969 commented May 7, 2014

One other thing to note - does the key we are now all using belong to poster code5381 ? - If so how do you get your own key & is there still the 50 per day request limit. If so, we are going to hit this rather quickly if we are all trying v2 with this key.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

Ignore last question - just found the answer.

davejavu1969 commented May 7, 2014

Ignore last question - just found the answer.

@quyetnv8893

This comment has been minimized.

Show comment
Hide comment
@quyetnv8893

quyetnv8893 May 7, 2014

Hi all,
Could you please tell me, param "key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4"
It is a key for us use it forever or not. If not, i want by it from google, what sould i do?

Thanks all!

quyetnv8893 commented May 7, 2014

Hi all,
Could you please tell me, param "key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4"
It is a key for us use it forever or not. If not, i want by it from google, what sould i do?

Thanks all!

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

Full info including details of key here....

https://github.com/gillesdemey/google-speech-v2

davejavu1969 commented May 7, 2014

Full info including details of key here....

https://github.com/gillesdemey/google-speech-v2

@quyetnv8893

This comment has been minimized.

Show comment
Hide comment
@quyetnv8893

quyetnv8893 May 7, 2014

@davejavu1969
Key was extracted from the Google Hotword chrome extension and is not optional
How I can extract new key?

quyetnv8893 commented May 7, 2014

@davejavu1969
Key was extracted from the Google Hotword chrome extension and is not optional
How I can extract new key?

@loureiromahia

This comment has been minimized.

Show comment
Hide comment
@loureiromahia

loureiromahia May 7, 2014

About the key i dn't know....they gave me in some of the previous posts....

quyetnv8893: I am not an expert on this API...i just started today asking because i was using API V1, and stopped working since yesterday... After several tests it is working for me, taking into account that i have to do several adaptations and at the end, let's say it is working (i said that because i still have to test it in detail....)...
So, unfortunately i cannot help you more: i don't know why it answers you with a blank result...
I just follwed the recomendations provided by code5381...you can see them 5 or 6 posts before....

dejavu1969....You say that you know the answer about thekey policy....Can you tell us...may be we are all using the same key and we shouldn't....

loureiromahia commented May 7, 2014

About the key i dn't know....they gave me in some of the previous posts....

quyetnv8893: I am not an expert on this API...i just started today asking because i was using API V1, and stopped working since yesterday... After several tests it is working for me, taking into account that i have to do several adaptations and at the end, let's say it is working (i said that because i still have to test it in detail....)...
So, unfortunately i cannot help you more: i don't know why it answers you with a blank result...
I just follwed the recomendations provided by code5381...you can see them 5 or 6 posts before....

dejavu1969....You say that you know the answer about thekey policy....Can you tell us...may be we are all using the same key and we shouldn't....

@quyetnv8893

This comment has been minimized.

Show comment
Hide comment
@quyetnv8893

quyetnv8893 May 7, 2014

loureiromhia: I already have a not blank result :D
But, is that key which we are using just only 50 request/day?

quyetnv8893 commented May 7, 2014

loureiromhia: I already have a not blank result :D
But, is that key which we are using just only 50 request/day?

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

I do not know about the key - I only read what was on the link I sent sorry.

"key: AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

(Key was extracted from the Google Hotword chrome extension and is not optional)."

If someone can shed further light on this - it would obviously be appreciated by a lot of people!

davejavu1969 commented May 7, 2014

I do not know about the key - I only read what was on the link I sent sorry.

"key: AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4

(Key was extracted from the Google Hotword chrome extension and is not optional)."

If someone can shed further light on this - it would obviously be appreciated by a lot of people!

@sambalec

This comment has been minimized.

Show comment
Hide comment
@sambalec

sambalec May 7, 2014

I have the same problem ...

sambalec commented May 7, 2014

I have the same problem ...

@dicilorenzo

This comment has been minimized.

Show comment
Hide comment
@dicilorenzo

dicilorenzo May 7, 2014

Using key and the v2 URL voice recognition will work again, there is some changes like the returned json and some feature like bad words filter.

I read on the Chromium developer's community that V1 API could be dismissed server side due a security bug.
https://code.google.com/p/chromium/issues/detail?id=360448

I hope that google is going to release a public version of api and maybe a commercial one for intensive use.

dicilorenzo commented May 7, 2014

Using key and the v2 URL voice recognition will work again, there is some changes like the returned json and some feature like bad words filter.

I read on the Chromium developer's community that V1 API could be dismissed server side due a security bug.
https://code.google.com/p/chromium/issues/detail?id=360448

I hope that google is going to release a public version of api and maybe a commercial one for intensive use.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 7, 2014

Yup - 'there is some changes like the returned json' - and that is a fairly critical change IMHO!

Am currently trying to restructure my code to accept new json layout.

Wish they'd left it alone tbh.

davejavu1969 commented May 7, 2014

Yup - 'there is some changes like the returned json' - and that is a fairly critical change IMHO!

Am currently trying to restructure my code to accept new json layout.

Wish they'd left it alone tbh.

@neo3

This comment has been minimized.

Show comment
Hide comment
@neo3

neo3 May 7, 2014

I also used the API v1 and this afternoon I noticed the problem, I made the changes to the API v2 and be functioning normally, but for how long this key will work.

I tried to see the price to increase the quota API v2, but do not have permission to view the form of the request.

neo3 commented May 7, 2014

I also used the API v1 and this afternoon I noticed the problem, I made the changes to the API v2 and be functioning normally, but for how long this key will work.

I tried to see the price to increase the quota API v2, but do not have permission to view the form of the request.

@gillesdemey

This comment has been minimized.

Show comment
Hide comment
@gillesdemey

gillesdemey May 7, 2014

Author of the v2 API info here.

As far as I know, the Google Hotword extension uses the same key for all the users that installed it.

A lot of users have been using the key for a while now, and none have reported that the key has hit it's limit yet.

It's not my personal key, it's one that was generated for the Hotword extension specifically.

I'll be posting updates as I discover them on my repository, and don't be afraid to submit additional info or issues.

https://github.com/gillesdemey/google-speech-v2

gillesdemey commented May 7, 2014

Author of the v2 API info here.

As far as I know, the Google Hotword extension uses the same key for all the users that installed it.

A lot of users have been using the key for a while now, and none have reported that the key has hit it's limit yet.

It's not my personal key, it's one that was generated for the Hotword extension specifically.

I'll be posting updates as I discover them on my repository, and don't be afraid to submit additional info or issues.

https://github.com/gillesdemey/google-speech-v2

@neo3

This comment has been minimized.

Show comment
Hide comment
@neo3

neo3 May 8, 2014

One thing I do not understand, if the Google provides free Hotword extension, what is the problem that makes it not want to use the API v1 free? In the program I did for example, I incentive the users to use Google Calendar and create documents in Google Drive.

And if the Google wants that we pay for use of the API, then it that provides a system of purchasing of the key available to everyone.

neo3 commented May 8, 2014

One thing I do not understand, if the Google provides free Hotword extension, what is the problem that makes it not want to use the API v1 free? In the program I did for example, I incentive the users to use Google Calendar and create documents in Google Drive.

And if the Google wants that we pay for use of the API, then it that provides a system of purchasing of the key available to everyone.

@Haodan

This comment has been minimized.

Show comment
Hide comment
@Haodan

Haodan May 8, 2014

I have a question, I was previously using speex codec with linear PCM on iOS using V1 google speech, now since it changes, my previous content-type: x-speex-with-header-byte(following this one: https://github.com/todoroo/iPhone-Speech-To-Text ) does not work any more, I changed the construction of the data not to be compressed, and change the content-type to l16, still it does not work, can anyone point out the audio file you sent is compressed or just flac or pcm without compression ?

Haodan commented May 8, 2014

I have a question, I was previously using speex codec with linear PCM on iOS using V1 google speech, now since it changes, my previous content-type: x-speex-with-header-byte(following this one: https://github.com/todoroo/iPhone-Speech-To-Text ) does not work any more, I changed the construction of the data not to be compressed, and change the content-type to l16, still it does not work, can anyone point out the audio file you sent is compressed or just flac or pcm without compression ?

@sqlogist

This comment has been minimized.

Show comment
Hide comment
@sqlogist

sqlogist May 9, 2014

I am a newbie to the Google speech to text APIs.

In these several days, I had been using the V1 version of these APIs.
As same as some people mentioned above, about 16 hours before, I also met the situation that the V1 became unavailable to use.
But at 8 hours before I tried the V2 then I could get the response.
Strangely enough, I also tried the V1 again, then I found it came back to available to use.
I cannot understand what had been happening to these APIs and what had changed around my situation.
Is it a tentative troubled inside the Google or there is the understandable reason?

Can I continue to use V1?

sqlogist commented May 9, 2014

I am a newbie to the Google speech to text APIs.

In these several days, I had been using the V1 version of these APIs.
As same as some people mentioned above, about 16 hours before, I also met the situation that the V1 became unavailable to use.
But at 8 hours before I tried the V2 then I could get the response.
Strangely enough, I also tried the V1 again, then I found it came back to available to use.
I cannot understand what had been happening to these APIs and what had changed around my situation.
Is it a tentative troubled inside the Google or there is the understandable reason?

Can I continue to use V1?

@dicilorenzo

This comment has been minimized.

Show comment
Hide comment
@dicilorenzo

dicilorenzo May 9, 2014

Sqlogist V1 Api are not working any more, probably was switched off for security reason.

I'm using V2 Api and I didn't notice any usage limitation.

Some of you experienced any kind of limitation? In this case which error is returned?

dicilorenzo commented May 9, 2014

Sqlogist V1 Api are not working any more, probably was switched off for security reason.

I'm using V2 Api and I didn't notice any usage limitation.

Some of you experienced any kind of limitation? In this case which error is returned?

@sqlogist

This comment has been minimized.

Show comment
Hide comment
@sqlogist

sqlogist May 9, 2014

Hi dicilorenzo.

I just tried to use V1 API and it actually works.
I used the code below on 2014-05-08 07:00:00AM(EST).

wget -q -U "Mozilla/5.0" --post-file myFlacFile.flac --header "Content-Type: audio/x-flac; rate=8000" -O - "http://www.google.com/speech-api/v1/recognize?lang=ja&client=chromium" | cut -d" -f12 > stt.txt

This code returns fine result.
So, I think the Google speech to text API V1 is still available.

Certainly, the Google Translate API V1(this is not a speech recognize API) seems be no longer available few years ago.

https://developers.google.com/translate/v2/faq

I wonder that it makes to confuse the understanding about the STT API V1.

If anyone knows the details, please let me know.

sqlogist commented May 9, 2014

Hi dicilorenzo.

I just tried to use V1 API and it actually works.
I used the code below on 2014-05-08 07:00:00AM(EST).

wget -q -U "Mozilla/5.0" --post-file myFlacFile.flac --header "Content-Type: audio/x-flac; rate=8000" -O - "http://www.google.com/speech-api/v1/recognize?lang=ja&client=chromium" | cut -d" -f12 > stt.txt

This code returns fine result.
So, I think the Google speech to text API V1 is still available.

Certainly, the Google Translate API V1(this is not a speech recognize API) seems be no longer available few years ago.

https://developers.google.com/translate/v2/faq

I wonder that it makes to confuse the understanding about the STT API V1.

If anyone knows the details, please let me know.

@neo3

This comment has been minimized.

Show comment
Hide comment
@neo3

neo3 May 9, 2014

True, API v1 is working again.

neo3 commented May 9, 2014

True, API v1 is working again.

@dicilorenzo

This comment has been minimized.

Show comment
Hide comment
@dicilorenzo

dicilorenzo May 9, 2014

Hi sqlogist,

I tried V1 api the result it:
"Your client has issued a malformed or illegal request. Missing parameter: key That’s all we know."

V2 is working without limitations

dicilorenzo commented May 9, 2014

Hi sqlogist,

I tried V1 api the result it:
"Your client has issued a malformed or illegal request. Missing parameter: key That’s all we know."

V2 is working without limitations

@neo3

This comment has been minimized.

Show comment
Hide comment
@neo3

neo3 May 9, 2014

Today the API v1 was working, but blocked again.

neo3 commented May 9, 2014

Today the API v1 was working, but blocked again.

@sqlogist

This comment has been minimized.

Show comment
Hide comment
@sqlogist

sqlogist May 9, 2014

Hi dicilorenzo, neo3 and all.

It seems that now the API V1 become unavailable again.
I found other developers also suffered to this same situation about the API v1 in these few days.

http://stackoverflow.com/questions/23511015/google-speech-api-v1-not-working/23538656#23538656

I guess the availability of the API V1 is often changing hour by hour.
To avoid this unstable behavior we might have to use API V2.

Even though the usage is permitted for only development or hobby, the courtesy limit of the API V2, 50 request per day, is too severe.

We need a work around solution to this problem.

sqlogist commented May 9, 2014

Hi dicilorenzo, neo3 and all.

It seems that now the API V1 become unavailable again.
I found other developers also suffered to this same situation about the API v1 in these few days.

http://stackoverflow.com/questions/23511015/google-speech-api-v1-not-working/23538656#23538656

I guess the availability of the API V1 is often changing hour by hour.
To avoid this unstable behavior we might have to use API V2.

Even though the usage is permitted for only development or hobby, the courtesy limit of the API V2, 50 request per day, is too severe.

We need a work around solution to this problem.

@amd5200

This comment has been minimized.

Show comment
Hide comment
@amd5200

amd5200 May 10, 2014

I'm so sad, my robot used api v1, now it can't chat with me by Chinese :(

amd5200 commented May 10, 2014

I'm so sad, my robot used api v1, now it can't chat with me by Chinese :(

@sqlogist

This comment has been minimized.

Show comment
Hide comment
@sqlogist

sqlogist May 11, 2014

Hi dicilorenzo, neo3, amd5200 and everyone,

I confirmed an interesting test.
I have called the API V2 again and again....

Meanwhile, this testing, I had been checking the value of QUOTA on Google Developer Console.
When I called the API V2 50 times, the value became "100%".

But the 51th test was succeeded with the correct result!
And I continue the testing until it reaches to the 60th test, but every test was succeeded.

Before this experience, I expect it to become unavailable to use API V2 when the value of QUATA reached to 100%.
But It is not true.

I guess we can use the API V2 over 50 times a day.
(It reminds me that dicilorenzo said "V2 is working without limitations" two days ago.)

I hope, it's become an important knowledge to everyone who want to use API V2.

sqlogist commented May 11, 2014

Hi dicilorenzo, neo3, amd5200 and everyone,

I confirmed an interesting test.
I have called the API V2 again and again....

Meanwhile, this testing, I had been checking the value of QUOTA on Google Developer Console.
When I called the API V2 50 times, the value became "100%".

But the 51th test was succeeded with the correct result!
And I continue the testing until it reaches to the 60th test, but every test was succeeded.

Before this experience, I expect it to become unavailable to use API V2 when the value of QUATA reached to 100%.
But It is not true.

I guess we can use the API V2 over 50 times a day.
(It reminds me that dicilorenzo said "V2 is working without limitations" two days ago.)

I hope, it's become an important knowledge to everyone who want to use API V2.

@lux89

This comment has been minimized.

Show comment
Hide comment
@lux89

lux89 May 11, 2014

Hi guys, in need of serious help here.

//code provided by korylprince
import sys
import urllib2
import json

f = open("test.flac")
data = f.read()
f.close()

req = urllib2.Request('https://www.google.com/speech-api/v2/recognize?output=json&lang=en&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4', data=data, headers={'Content-type': 'audio/x-flac; rate=16000'})

try:
ret = urllib2.urlopen(req)
except urllib2.URLError:
print "Error Transcribing Voicemail"

resp = ret.read()
text = json.loads(resp)['hypotheses'][0]['utterance']
print text

This is the code i use in python for speech to text. Unfortunately, i am not able to retrieve the transcription. Perhaps, some one is able to help. thanks alot

lux89 commented May 11, 2014

Hi guys, in need of serious help here.

//code provided by korylprince
import sys
import urllib2
import json

f = open("test.flac")
data = f.read()
f.close()

req = urllib2.Request('https://www.google.com/speech-api/v2/recognize?output=json&lang=en&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4', data=data, headers={'Content-type': 'audio/x-flac; rate=16000'})

try:
ret = urllib2.urlopen(req)
except urllib2.URLError:
print "Error Transcribing Voicemail"

resp = ret.read()
text = json.loads(resp)['hypotheses'][0]['utterance']
print text

This is the code i use in python for speech to text. Unfortunately, i am not able to retrieve the transcription. Perhaps, some one is able to help. thanks alot

@Eybon

This comment has been minimized.

Show comment
Hide comment
@Eybon

Eybon May 11, 2014

Hey guy
Last week, i used google speech api v1 in a script bash and everything worked ....
Now, tons of problems !!
I saw all your post from 4 days, So I go to v2, create an account for use google key like that (http://www.chromium.org/developers/how-tos/api-keys) but i have a probleme, the result is always :

{"result":[]}

I dont understand why .... i just changed url in my script.
here is the code :

arecord -q -f cd -t wav -d 2 -r 44100 | flac --totally-silent - -f --best --sample-rate 16000 -o out.flac;
wget -U "Mozilla/5.0" --post-file out.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v2/recognize?lang=fr&key=mygooglekey" > speech.txt

I saw the same problem for your post but dont saw answer.
I hope you can help me because .... Dont understand god ! ;-)

PS : im french, sorry for my bad english, but if no one understand difference between "lang=fr","lang=fr-FR","lang=fr-fr" because i saw 3 on net ?

Thx

Eybon commented May 11, 2014

Hey guy
Last week, i used google speech api v1 in a script bash and everything worked ....
Now, tons of problems !!
I saw all your post from 4 days, So I go to v2, create an account for use google key like that (http://www.chromium.org/developers/how-tos/api-keys) but i have a probleme, the result is always :

{"result":[]}

I dont understand why .... i just changed url in my script.
here is the code :

arecord -q -f cd -t wav -d 2 -r 44100 | flac --totally-silent - -f --best --sample-rate 16000 -o out.flac;
wget -U "Mozilla/5.0" --post-file out.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v2/recognize?lang=fr&key=mygooglekey" > speech.txt

I saw the same problem for your post but dont saw answer.
I hope you can help me because .... Dont understand god ! ;-)

PS : im french, sorry for my bad english, but if no one understand difference between "lang=fr","lang=fr-FR","lang=fr-fr" because i saw 3 on net ?

Thx

@kaarskop

This comment has been minimized.

Show comment
Hide comment
@kaarskop

kaarskop May 11, 2014

Was having the same issue untill I realised V2 gives back 2 lines instead of 1:
{"result":[]}
{"result":[{"alternative":[{"transcript":"van","confidence":0.88741958},{"transcript":"van jou"},{"transcript":"van je"},{"transcript":"vaughan"},{"transcript":"van dam"}],"final":true}],"result_index":0}

kaarskop commented May 11, 2014

Was having the same issue untill I realised V2 gives back 2 lines instead of 1:
{"result":[]}
{"result":[{"alternative":[{"transcript":"van","confidence":0.88741958},{"transcript":"van jou"},{"transcript":"van je"},{"transcript":"vaughan"},{"transcript":"van dam"}],"final":true}],"result_index":0}

@2128

This comment has been minimized.

Show comment
Hide comment
@2128

2128 May 12, 2014

yes! 2 lines result. what's google doing recently?

2128 commented May 12, 2014

yes! 2 lines result. what's google doing recently?

@tabbakka-developer

This comment has been minimized.

Show comment
Hide comment
@tabbakka-developer

tabbakka-developer May 12, 2014

I'am trying to make it work with c#. And i don't know how to read the second line? Can someone help me with this?

HttpWebRequest request =(HttpWebRequest) HttpWebRequest.Create(PATH);
request.Method = "POST";
byte[] byteArray = File.ReadAllBytes(flacName);
sampleRate = 44100;
request.ContentType = "audio/x-flac; rate=" + sampleRate.ToString();
request.ContentLength = byteArray.Length;
Stream sendStream = request.GetRequestStream();
sendStream.Write(byteArray,0,byteArray.Length);
sendStream.Close();
string responseFromServer;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();
reader.Close();
response.Close();

tabbakka-developer commented May 12, 2014

I'am trying to make it work with c#. And i don't know how to read the second line? Can someone help me with this?

HttpWebRequest request =(HttpWebRequest) HttpWebRequest.Create(PATH);
request.Method = "POST";
byte[] byteArray = File.ReadAllBytes(flacName);
sampleRate = 44100;
request.ContentType = "audio/x-flac; rate=" + sampleRate.ToString();
request.ContentLength = byteArray.Length;
Stream sendStream = request.GetRequestStream();
sendStream.Write(byteArray,0,byteArray.Length);
sendStream.Close();
string responseFromServer;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();
reader.Close();
response.Close();

@bryanrtboy

This comment has been minimized.

Show comment
Hide comment
@bryanrtboy

bryanrtboy May 12, 2014

If you are only getting {"result":[]} you need to properly use ReadToEnd - http://stackoverflow.com/questions/7085785/readtoend-works-readline-doesnt

Now, how do I get the second array named "result" from the json?

bryanrtboy commented May 12, 2014

If you are only getting {"result":[]} you need to properly use ReadToEnd - http://stackoverflow.com/questions/7085785/readtoend-works-readline-doesnt

Now, how do I get the second array named "result" from the json?

@tabbakka-developer

This comment has been minimized.

Show comment
Hide comment
@tabbakka-developer

tabbakka-developer May 13, 2014

I use ReadToEnd, but it doesn't work. I'm getting only first line.

HttpWebResponse response = (HttpWebResponse) request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();

bryanrtboy, i can send you my jSon deserializer, if you need. It's on c#

tabbakka-developer commented May 13, 2014

I use ReadToEnd, but it doesn't work. I'm getting only first line.

HttpWebResponse response = (HttpWebResponse) request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
responseFromServer = reader.ReadToEnd();

bryanrtboy, i can send you my jSon deserializer, if you need. It's on c#

@niluwin

This comment has been minimized.

Show comment
Hide comment
@niluwin

niluwin May 13, 2014

u can use a very basic method like below:
lang_code='en-US'
googl_speech_url = 'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4'
hrs = {"User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7",'Content-type': 'audio/x-flac; rate=16000'}
req = urllib2.Request(googl_speech_url, data=flac_cont, headers=hrs)
p = urllib2.urlopen(req)
print p.read
data= (p.read()).split('transcript":"')[1]
print data.split('"')[0]

niluwin commented May 13, 2014

u can use a very basic method like below:
lang_code='en-US'
googl_speech_url = 'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4'
hrs = {"User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7",'Content-type': 'audio/x-flac; rate=16000'}
req = urllib2.Request(googl_speech_url, data=flac_cont, headers=hrs)
p = urllib2.urlopen(req)
print p.read
data= (p.read()).split('transcript":"')[1]
print data.split('"')[0]

@CHERTS

This comment has been minimized.

Show comment
Hide comment
@CHERTS

CHERTS May 14, 2014

Today there is a problem when trying to recognize issued

Your client does not have permission to get URL /speech-api/v2/recognize?xjerr=1&client=chromium&output=json&lang=ru-RU&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4 from this server. ThatvЂ ™ s all we know.

Only yesterday everything worked.

CHERTS commented May 14, 2014

Today there is a problem when trying to recognize issued

Your client does not have permission to get URL /speech-api/v2/recognize?xjerr=1&client=chromium&output=json&lang=ru-RU&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4 from this server. ThatvЂ ™ s all we know.

Only yesterday everything worked.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

Hi there,

I have been following this thread for the last week or so since the initial change to V2 api. I too had a talking robot that worked perfectly until the upgrade! I made the changes to v2 and added a small python script to parse the new format results.

BUT - this AM (UK time) I am now getting 403 Forbidden when using v2 of the api - is anyone else experiencing this?

In regards to earlier posts - -

@brianrtboy and others, I have a small (very crappy!) script I wrote in Python that takes the mulitple line response from google and extracts the single answer, and writes that over the original .txt file - I can post it here if anyone needs it.

re the key - this is a 'Global' key that GDM extracted - it does not 'belong' to anyone - I have a horrible feeling that this key may have now been blocked, hence the 'forbidden' - anyone else got any thoughts?

I have a demo tomorrow and this is rather critical to it!

davejavu1969 commented May 14, 2014

Hi there,

I have been following this thread for the last week or so since the initial change to V2 api. I too had a talking robot that worked perfectly until the upgrade! I made the changes to v2 and added a small python script to parse the new format results.

BUT - this AM (UK time) I am now getting 403 Forbidden when using v2 of the api - is anyone else experiencing this?

In regards to earlier posts - -

@brianrtboy and others, I have a small (very crappy!) script I wrote in Python that takes the mulitple line response from google and extracts the single answer, and writes that over the original .txt file - I can post it here if anyone needs it.

re the key - this is a 'Global' key that GDM extracted - it does not 'belong' to anyone - I have a horrible feeling that this key may have now been blocked, hence the 'forbidden' - anyone else got any thoughts?

I have a demo tomorrow and this is rather critical to it!

@CHERTS

This comment has been minimized.

Show comment
Hide comment
@CHERTS

CHERTS May 14, 2014

Key AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4 is locked. :(

CHERTS commented May 14, 2014

Key AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4 is locked. :(

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

Are you getting '403 Forbidden' ?

davejavu1969 commented May 14, 2014

Are you getting '403 Forbidden' ?

@CHERTS

This comment has been minimized.

Show comment
Hide comment
@CHERTS

CHERTS commented May 14, 2014

Yes

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

Crap :-( - Me too.

I suspect google have blocked that key then. I have found one of the Google dev guys on Groups and have pinged him a msg, but they are all west coast US and it's 3am there.

davejavu1969 commented May 14, 2014

Crap :-( - Me too.

I suspect google have blocked that key then. I have found one of the Google dev guys on Groups and have pinged him a msg, but they are all west coast US and it's 3am there.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

I have also just used my google account to generate a generic google API server side key for all Google APIs - although Speech API does not appear in Google API list, or developer console anywhere.

Therefore, not surprised to report that this new key also generates the same 403 Forbidden response.

Any one at Google reading this??!

davejavu1969 commented May 14, 2014

I have also just used my google account to generate a generic google API server side key for all Google APIs - although Speech API does not appear in Google API list, or developer console anywhere.

Therefore, not surprised to report that this new key also generates the same 403 Forbidden response.

Any one at Google reading this??!

@ecmnet

This comment has been minimized.

Show comment
Hide comment
@ecmnet

ecmnet May 14, 2014

You have to sign up with the API projects group. However, you then have only about 50+ shots. Afterwards your key will be blocked too :(

ecmnet commented May 14, 2014

You have to sign up with the API projects group. However, you then have only about 50+ shots. Afterwards your key will be blocked too :(

@CHERTS

This comment has been minimized.

Show comment
Hide comment
@CHERTS

CHERTS May 14, 2014

The new version of Google Voice Search Hotword (Beta) 0.1.1.5018_0 using the old API key

audio-input.js
var b = new T("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&app=web-hotword");
chrome && chrome.app && chrome.app.getDetails && chrome.app.getDetails() && X(b, "app", "web-hotword-" + chrome.app.getDetails().version);
X(b, "client", "chrome-hotword");
X(b, "key", "AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4");
var c = {};
c["Content-Type"] = "audio/l16; rate=" + a.Ga;

So put an additional check, which I still can not understand.

CHERTS commented May 14, 2014

The new version of Google Voice Search Hotword (Beta) 0.1.1.5018_0 using the old API key

audio-input.js
var b = new T("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&app=web-hotword");
chrome && chrome.app && chrome.app.getDetails && chrome.app.getDetails() && X(b, "app", "web-hotword-" + chrome.app.getDetails().version);
X(b, "client", "chrome-hotword");
X(b, "key", "AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4");
var c = {};
c["Content-Type"] = "audio/l16; rate=" + a.Ga;

So put an additional check, which I still can not understand.

@kaarskop

This comment has been minimized.

Show comment
Hide comment
@kaarskop

kaarskop May 14, 2014

For now Google doesn't enforce the 50/day limit yet. I am using it for a few days now with well over 50/day requests. I get the feeling they are getting ready to ask money though...

kaarskop commented May 14, 2014

For now Google doesn't enforce the 50/day limit yet. I am using it for a few days now with well over 50/day requests. I get the feeling they are getting ready to ask money though...

@ecmnet

This comment has been minimized.

Show comment
Hide comment
@ecmnet

ecmnet May 14, 2014

mine was blocked after some 100 request...

ecmnet commented May 14, 2014

mine was blocked after some 100 request...

@kaarskop

This comment has been minimized.

Show comment
Hide comment
@kaarskop

kaarskop May 14, 2014

I reached 318 yesterday and not blocked yet. Haven't used it today yet though.

kaarskop commented May 14, 2014

I reached 318 yesterday and not blocked yet. Haven't used it today yet though.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

I have signed up for the Google API projects group - do I have to request a key?

davejavu1969 commented May 14, 2014

I have signed up for the Google API projects group - do I have to request a key?

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 14, 2014

Use this Key : &key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw
It works for now.

orelisraeli commented May 14, 2014

Use this Key : &key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw
It works for now.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

Hi Guys - thanks Orion, I will try that shortly!

kaarskop - I think I am in wrong place, can you post a link plz.

Many thanks.

davejavu1969 commented May 14, 2014

Hi Guys - thanks Orion, I will try that shortly!

kaarskop - I think I am in wrong place, can you post a link plz.

Many thanks.

@SanyaGross

This comment has been minimized.

Show comment
Hide comment
@SanyaGross

SanyaGross May 14, 2014

thanks Orion, how can I get my own key? (Without copy-pasting from this site)

SanyaGross commented May 14, 2014

thanks Orion, how can I get my own key? (Without copy-pasting from this site)

@kaarskop

This comment has been minimized.

Show comment
Hide comment
@kaarskop

kaarskop May 14, 2014

https://console.developers.google.com -> your project -> APIs & auth -> Credentials

Apparently here it's possible as well.

kaarskop commented May 14, 2014

https://console.developers.google.com -> your project -> APIs & auth -> Credentials

Apparently here it's possible as well.

@SanyaGross

This comment has been minimized.

Show comment
Hide comment
@SanyaGross

SanyaGross May 14, 2014

In PHP code I wrote:

I get answer only one string:
{"result":[]}

Why?

SanyaGross commented May 14, 2014

In PHP code I wrote:

I get answer only one string:
{"result":[]}

Why?

@SanyaGross

This comment has been minimized.

Show comment
Hide comment
@SanyaGross

SanyaGross May 14, 2014

kaarskop
I make key:

Key for server applications
API key AIzaSyC53OK59kFcMRMXtxxNujBUHU130A6XvZo
IPs 188...*1
Activation date May 7, 2014 11:52 PM

but my key doesn't work

SanyaGross commented May 14, 2014

kaarskop
I make key:

Key for server applications
API key AIzaSyC53OK59kFcMRMXtxxNujBUHU130A6XvZo
IPs 188...*1
Activation date May 7, 2014 11:52 PM

but my key doesn't work

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

@ Kaarskop...

Yup - that's what I did. Generated a key but still get 403 forbidden error.

davejavu1969 commented May 14, 2014

@ Kaarskop...

Yup - that's what I did. Generated a key but still get 403 forbidden error.

@ecmnet

This comment has been minimized.

Show comment
Hide comment
@ecmnet

ecmnet May 14, 2014

You have to join the API group. Then Speech API will appear on the list of APIs. Switch it on and use your key. But still, it will shut down after more than 50+ requests.

ecmnet commented May 14, 2014

You have to join the API group. Then Speech API will appear on the list of APIs. Switch it on and use your key. But still, it will shut down after more than 50+ requests.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

Could you post a link to join API Group please? - this is what I can't find.

davejavu1969 commented May 14, 2014

Could you post a link to join API Group please? - this is what I can't find.

@SanyaGross

This comment has been minimized.

Show comment
Hide comment
@SanyaGross

SanyaGross May 14, 2014

@ kaarskop

Yes, I did it.
You have to join the API group. Then Speech API will appear on the list of APIs. Switch it on and use your key.

SanyaGross commented May 14, 2014

@ kaarskop

Yes, I did it.
You have to join the API group. Then Speech API will appear on the list of APIs. Switch it on and use your key.

@ecmnet

This comment has been minimized.

Show comment
Hide comment
@ecmnet

ecmnet May 14, 2014

i figured out, that the limit is at 500 request/day.

ecmnet commented May 14, 2014

i figured out, that the limit is at 500 request/day.

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 14, 2014

The only way to get your own key is by using this guide here: http://www.chromium.org/developers/how-tos/api-keys
read it from 7-11.
But in order to make it available you must subscribe the chromium-dev group here : https://groups.google.com/a/chromium.org/forum/?fromgroups#!forum/chromium-dev .
Right now I'm looking for another way hope I'll find something because it's really annoying.

orelisraeli commented May 14, 2014

The only way to get your own key is by using this guide here: http://www.chromium.org/developers/how-tos/api-keys
read it from 7-11.
But in order to make it available you must subscribe the chromium-dev group here : https://groups.google.com/a/chromium.org/forum/?fromgroups#!forum/chromium-dev .
Right now I'm looking for another way hope I'll find something because it's really annoying.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 14, 2014

Many thanks - much appreciated folks. :-)

davejavu1969 commented May 14, 2014

Many thanks - much appreciated folks. :-)

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 14, 2014

Well it's not really a solution because after 500 request you will need to activate another key.
I hope they will release a dev sdk for that or something.

orelisraeli commented May 14, 2014

Well it's not really a solution because after 500 request you will need to activate another key.
I hope they will release a dev sdk for that or something.

@bryanrtboy

This comment has been minimized.

Show comment
Hide comment
@bryanrtboy

bryanrtboy May 14, 2014

@SATANA - you need to use 'using' or it will only read the first line. My C# snippet is this:

            using (HttpWebResponse HWR_Response = (HttpWebResponse)_HWR_SpeechToText.GetResponse ())
                            if (HWR_Response.StatusCode == HttpStatusCode.OK) {
                                    string line;
                                    using (SR_Response = new StreamReader (HWR_Response.GetResponseStream ())) {
                                            line = SR_Response.ReadToEnd ();
                                    }

                                    SR_Response.Close ();

bryanrtboy commented May 14, 2014

@SATANA - you need to use 'using' or it will only read the first line. My C# snippet is this:

            using (HttpWebResponse HWR_Response = (HttpWebResponse)_HWR_SpeechToText.GetResponse ())
                            if (HWR_Response.StatusCode == HttpStatusCode.OK) {
                                    string line;
                                    using (SR_Response = new StreamReader (HWR_Response.GetResponseStream ())) {
                                            line = SR_Response.ReadToEnd ();
                                    }

                                    SR_Response.Close ();
@neo3

This comment has been minimized.

Show comment
Hide comment
@neo3

neo3 May 14, 2014

The key "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" was taken from where? It has usage limit?

neo3 commented May 14, 2014

The key "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" was taken from where? It has usage limit?

@SanyaGross

This comment has been minimized.

Show comment
Hide comment
@SanyaGross

SanyaGross May 15, 2014

@ ORION :
here: http://www.chromium.org/developers/how-tos/api-keys
read it from 7-11.
But I can not understand difference between 8.1 and 8.2. Is this importantly?

SanyaGross commented May 15, 2014

@ ORION :
here: http://www.chromium.org/developers/how-tos/api-keys
read it from 7-11.
But I can not understand difference between 8.1 and 8.2. Is this importantly?

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 15, 2014

SanyaGross - it depends what your application is based on.
Mine is a desktop application so I chose Installed Application > Other.
Then you should make a Browser key because the speech is a web api.
Hope I helped.

orelisraeli commented May 15, 2014

SanyaGross - it depends what your application is based on.
Mine is a desktop application so I chose Installed Application > Other.
Then you should make a Browser key because the speech is a web api.
Hope I helped.

@immran

This comment has been minimized.

Show comment
Hide comment
@immran

immran May 15, 2014

H all,

I have changed my api v1 to v2 now and I'm using the new key AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw but I got the response as empty like {"result":[]}

Any suggestions?

Thanks

immran commented May 15, 2014

H all,

I have changed my api v1 to v2 now and I'm using the new key AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw but I got the response as empty like {"result":[]}

Any suggestions?

Thanks

@Homez386

This comment has been minimized.

Show comment
Hide comment
@Homez386

Homez386 May 15, 2014

ORlON, I can't manage this way, always get 403 with a key generated like this. Maybe I miss something?

Homez386 commented May 15, 2014

ORlON, I can't manage this way, always get 403 with a key generated like this. Maybe I miss something?

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 15, 2014

You must subscribe to the chromium-dev group and ask them to activate your key.

orelisraeli commented May 15, 2014

You must subscribe to the chromium-dev group and ask them to activate your key.

@SanyaGross

This comment has been minimized.

Show comment
Hide comment
@SanyaGross

SanyaGross May 15, 2014

immran

I got answer {"result":[]} from 3G-modem. But from optic-channel - all right.

SanyaGross commented May 15, 2014

immran

I got answer {"result":[]} from 3G-modem. But from optic-channel - all right.

@tabbakka-developer

This comment has been minimized.

Show comment
Hide comment
@tabbakka-developer

tabbakka-developer May 15, 2014

@bryanrtboy it's strange, but i still getting only this {"result":[]}

tabbakka-developer commented May 15, 2014

@bryanrtboy it's strange, but i still getting only this {"result":[]}

@channelz

This comment has been minimized.

Show comment
Hide comment
@channelz

channelz May 15, 2014

What kind of response times are you guys seeing for V2? I used to be under 2 seconds all the time on V1. Now the response times range from 2-9 seconds past couple days (using the same test file). (Mean 3.7) https overhead slowing it down some? Thoughts/suggestions to speed it up?

{"result":[]}
{"result":[{"alternative":[{"transcript":"the wheels on the bus go round and round"}],"final":true}],"result_index":0}

real 0m3.548s
user 0m0.160s
sys 0m0.030s

channelz commented May 15, 2014

What kind of response times are you guys seeing for V2? I used to be under 2 seconds all the time on V1. Now the response times range from 2-9 seconds past couple days (using the same test file). (Mean 3.7) https overhead slowing it down some? Thoughts/suggestions to speed it up?

{"result":[]}
{"result":[{"alternative":[{"transcript":"the wheels on the bus go round and round"}],"final":true}],"result_index":0}

real 0m3.548s
user 0m0.160s
sys 0m0.030s

@sambalec

This comment has been minimized.

Show comment
Hide comment
@sambalec

sambalec May 15, 2014

@orion Hi, many thanks for the new key AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw
How did you extract this key ? Can you explain me :) ? Thanks.

sambalec commented May 15, 2014

@orion Hi, many thanks for the new key AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw
How did you extract this key ? Can you explain me :) ? Thanks.

@littlekill

This comment has been minimized.

Show comment
Hide comment
@littlekill

littlekill May 16, 2014

@channelz Hi, how did you get two lines? I only get one line like {"result":[]}. This is my command in linux.

wget -q -U "Mozilla/5.0" --post-file daveconroy.flac --header "Content-Type: audio/x-flac; rate=44100" -O - "https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=mykey" > result.txt

Can you help me? Thank you.

littlekill commented May 16, 2014

@channelz Hi, how did you get two lines? I only get one line like {"result":[]}. This is my command in linux.

wget -q -U "Mozilla/5.0" --post-file daveconroy.flac --header "Content-Type: audio/x-flac; rate=44100" -O - "https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=mykey" > result.txt

Can you help me? Thank you.

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 16, 2014

Hey @sambalec in order to make your own you should open a new project here: https://console.developers.google.com.
Then use this guide from 7-11 : http://www.chromium.org/developers/how-tos/api-keys.
But you must activate your key by emailing the chromium-dev group or something but I'm not sure they will because the speech api is made for chrome and google doesn't want people to use it.
So I think it doesn't matter because very soon we wont be able to use the speech api unless google will release a SDK for it.
As you can see the securty from V1 to V2 has changed a lot and in V3 I believe we wont be able to use it anymore.
right now I'm trying to find something, hope I will.

orelisraeli commented May 16, 2014

Hey @sambalec in order to make your own you should open a new project here: https://console.developers.google.com.
Then use this guide from 7-11 : http://www.chromium.org/developers/how-tos/api-keys.
But you must activate your key by emailing the chromium-dev group or something but I'm not sure they will because the speech api is made for chrome and google doesn't want people to use it.
So I think it doesn't matter because very soon we wont be able to use the speech api unless google will release a SDK for it.
As you can see the securty from V1 to V2 has changed a lot and in V3 I believe we wont be able to use it anymore.
right now I'm trying to find something, hope I will.

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 16, 2014

Hi, all - been here for a while working through this. So I have joined the chromium group, got my key. The speech API has been added to my list within the console, it was not there before so all appears ok. I have generated a new key and added IP addresses but I am still getting 403 Forbidden. Anyone else getting the same?

davejavu1969 commented May 16, 2014

Hi, all - been here for a while working through this. So I have joined the chromium group, got my key. The speech API has been added to my list within the console, it was not there before so all appears ok. I have generated a new key and added IP addresses but I am still getting 403 Forbidden. Anyone else getting the same?

@mcella

This comment has been minimized.

Show comment
Hide comment
@mcella

mcella commented May 16, 2014

@davejavu1969 same here :-(

@fatdh

This comment has been minimized.

Show comment
Hide comment
@fatdh

fatdh May 16, 2014

@davejavu1969, @mcella
I got the same error, until changed the key for this one AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw
from @orion

fatdh commented May 16, 2014

@davejavu1969, @mcella
I got the same error, until changed the key for this one AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw
from @orion

@davejavu1969

This comment has been minimized.

Show comment
Hide comment
@davejavu1969

davejavu1969 May 16, 2014

Yup - we know that key works, but for how long?! Hence we are trying to establish our own keys.

davejavu1969 commented May 16, 2014

Yup - we know that key works, but for how long?! Hence we are trying to establish our own keys.

@danielmahon

This comment has been minimized.

Show comment
Hide comment
@danielmahon

danielmahon May 16, 2014

I was able to create my own key and use it, but im still getting a {"result":[]} response...

danielmahon commented May 16, 2014

I was able to create my own key and use it, but im still getting a {"result":[]} response...

@Homez386

This comment has been minimized.

Show comment
Hide comment
@Homez386

Homez386 May 17, 2014

ORION, thanks for your reply:

You must subscribe to the chromium-dev group and ask them to activate your key.

I've already subscribed, but do you mean that I must ask for activation thru a personal message in this group (not automatically)?

Homez386 commented May 17, 2014

ORION, thanks for your reply:

You must subscribe to the chromium-dev group and ask them to activate your key.

I've already subscribed, but do you mean that I must ask for activation thru a personal message in this group (not automatically)?

@orelisraeli

This comment has been minimized.

Show comment
Hide comment
@orelisraeli

orelisraeli May 17, 2014

Hey everyone!
Here is my guide for you to make keys for yourselves:
Go to this link : https://cloud.google.com/console and create your own project.
Join this group here : https://groups.google.com/a/chromium.org/forum/?fromgroups#!forum/chromium-dev.
In your project go to APIs & auth > APIs , and activate Speech API (only 50 requests for each key).
Go to Credentials and make your client.
Generate a Browser key.
And your done.
Hope I helped ;)

orelisraeli commented May 17, 2014

Hey everyone!
Here is my guide for you to make keys for yourselves:
Go to this link : https://cloud.google.com/console and create your own project.
Join this group here : https://groups.google.com/a/chromium.org/forum/?fromgroups#!forum/chromium-dev.
In your project go to APIs & auth > APIs , and activate Speech API (only 50 requests for each key).
Go to Credentials and make your client.
Generate a Browser key.
And your done.
Hope I helped ;)

@Homez386

This comment has been minimized.

Show comment
Hide comment
@Homez386

Homez386 May 18, 2014

ORION, thanks! Strange, but yesterday this didn't work, today works with the key generated 15th May. Maybe the browser key doesn't get activated immediately?

Homez386 commented May 18, 2014

ORION, thanks! Strange, but yesterday this didn't work, today works with the key generated 15th May. Maybe the browser key doesn't get activated immediately?

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost May 18, 2014

Hey guys, I'm using this v2 solution, but I feel it can be blocked any time. So is there any other speech to text solution we can try? I know the nuance has a mobile sdk, but the price is way to high. Welcome discussion about other solutions.

ghost commented May 18, 2014

Hey guys, I'm using this v2 solution, but I feel it can be blocked any time. So is there any other speech to text solution we can try? I know the nuance has a mobile sdk, but the price is way to high. Welcome discussion about other solutions.

@NSThread

This comment has been minimized.

Show comment
Hide comment
@NSThread

NSThread May 19, 2014

Can anyone tell me what's the reason of getting "{"result":[]}" as a response? I checked, there is no other line in response.

NSThread commented May 19, 2014

Can anyone tell me what's the reason of getting "{"result":[]}" as a response? I checked, there is no other line in response.

@akifnaeem21

This comment has been minimized.

Show comment
Hide comment
@akifnaeem21

akifnaeem21 May 19, 2014

can any1 please share solution for v2 and json format...coz many of us have very urgent situations.
i am using google speech to text api in my final year project of BS.
and 31may is last date of project submission. every thing was working very fine till 7may.
but after dat google block v1.

code till 7may.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
echo "Recording your Speech (Ctrl+C to Transcribe)"

arecord -D plughw:0,0 -q -f cd -t wav -d 0 -r 16000 | flac - -f --best --sample-rate 16000 -s -o SpeechtoText.flac; 

echo "Converting Speech to Text..."

wget -q -U "Mozilla/5.0" --post-file SpeechtoText.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium" | cut -d" -f12 > SpeechtoText.txt

echo "You Said:"

value=cat SpeechtoText.txt

echo "$value"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

kindly share solutions how us v2 and how to get out from json to text.

waiting ur response eagerly ... :(

akifnaeem21 commented May 19, 2014

can any1 please share solution for v2 and json format...coz many of us have very urgent situations.
i am using google speech to text api in my final year project of BS.
and 31may is last date of project submission. every thing was working very fine till 7may.
but after dat google block v1.

code till 7may.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
echo "Recording your Speech (Ctrl+C to Transcribe)"

arecord -D plughw:0,0 -q -f cd -t wav -d 0 -r 16000 | flac - -f --best --sample-rate 16000 -s -o SpeechtoText.flac; 

echo "Converting Speech to Text..."

wget -q -U "Mozilla/5.0" --post-file SpeechtoText.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium" | cut -d" -f12 > SpeechtoText.txt

echo "You Said:"

value=cat SpeechtoText.txt

echo "$value"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

kindly share solutions how us v2 and how to get out from json to text.

waiting ur response eagerly ... :(

@NSThread

This comment has been minimized.

Show comment
Hide comment
@NSThread

NSThread May 19, 2014

@akifnaeem21,
Check https://github.com/todoroo/iPhone-Speech-To-Text, use "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" as key.
I'm having problem with empty json ({"result":[]}) output. let me know if you succeed.

NSThread commented May 19, 2014

@akifnaeem21,
Check https://github.com/todoroo/iPhone-Speech-To-Text, use "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" as key.
I'm having problem with empty json ({"result":[]}) output. let me know if you succeed.

@akifnaeem21

This comment has been minimized.

Show comment
Hide comment
@akifnaeem21

akifnaeem21 May 19, 2014

@NSThread

having same empty response from google.

akifnaeem21 commented May 19, 2014

@NSThread

having same empty response from google.

@howerson

This comment has been minimized.

Show comment
Hide comment
@howerson

howerson May 20, 2014

I have same problem, I have change to following code, but I failed;

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"good-morning-google" ofType:@"flac"];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    request.defaultResponseEncoding = NSUTF8StringEncoding;

    [request setRequestMethod:@"POST"];

    [request addFile:filePath forKey:@"file"];

    [request addRequestHeader:@"Content-Type" value:@"audio/x-flac; rate=44100"];

    [request setTimeOutSeconds:6];

    [request startSynchronous];

    NSData *responseData = [request responseData];

howerson commented May 20, 2014

I have same problem, I have change to following code, but I failed;

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"good-morning-google" ofType:@"flac"];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    request.defaultResponseEncoding = NSUTF8StringEncoding;

    [request setRequestMethod:@"POST"];

    [request addFile:filePath forKey:@"file"];

    [request addRequestHeader:@"Content-Type" value:@"audio/x-flac; rate=44100"];

    [request setTimeOutSeconds:6];

    [request startSynchronous];

    NSData *responseData = [request responseData];
@Kaspler

This comment has been minimized.

Show comment
Hide comment
@Kaspler

Kaspler May 22, 2014

@akifnaeem21

I'm in same situation as you - need to finish my BS project till the end of May.
I also was working fine with V1 till now... Anyway, now, thanks to this page and all the comments here I managed to make it work with V2.

Here is my C# code (it's just a prototype where I tested, so it's simple):


using System;
using System.IO;
using System.IO.Compression;
using System.Net;


class Program
{
    static void Main(string[] args)
    {
        using (var fileStream = new FileStream(@"C:\LetsArrangeMeeting.flac", FileMode.Open))
        {
            const string requestUrl = "https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=KEY_GOES_HERE&client=chromium&maxresults=6&pfilter=2";
            var request = (HttpWebRequest)WebRequest.Create(requestUrl);
            ConfigureRequest(request);
            var requestStream = request.GetRequestStream();

            CopyStream(fileStream, requestStream);

            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    using (var zippedStream = new GZipStream(responseStream, CompressionMode.Decompress))
                    {