Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty response #6

Closed
mudler opened this issue May 23, 2014 · 24 comments
Closed

Empty response #6

mudler opened this issue May 23, 2014 · 24 comments

Comments

@mudler
Copy link

mudler commented May 23, 2014

Hello everyone,
today google (at least for me) it's not giving any result:

curl -X POST \          
--data-binary good-morning-google.flac \
--header 'Content-Type: audio/x-flac; rate=44100;' \
'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=<KEY>'

it just returns []

it's the same for you ?

the flac in the test was in the same dir, also changing files, empty results are given (with both my personal api key and chromium one)

@ghost
Copy link

ghost commented May 24, 2014

I got exactly the same. Tried nearly everything. Do you have any solution to this?

@mudler
Copy link
Author

mudler commented May 24, 2014

Thanks for the answer, i started to think that was a problem affecting only me. However i couldn't find nothing, at least it doesn't seem an api related error. But seems Mike google its changing his apis those days

@mudler
Copy link
Author

mudler commented May 24, 2014

@markussomething
Well, made some progress:

this seems working for me

curl -X POST --data-binary @good-morning-google.flac \
--header 'Content-Type: audio/x-flac; rate=44100;' \
'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=<API KEY>&client=chromium&maxresults=6&pfilter=2'
{"result":[]}
{"result":[{"alternative":[{"transcript":"good morning Google how are you feeling today","confidence":0.97335243}],"final":true}],"result_index":0}

pfilter, seems to un-filter the second answer

@ghost
Copy link

ghost commented May 25, 2014

unfortunately not working for me :/ still got an empty result. I'm doing nearly the same as you with the same file. the only thing i could think of is that its related to the api key. Have you generated on on your own or are you using one you found here?

@mudler
Copy link
Author

mudler commented May 25, 2014

for me it's working with both, try the exact command as mine, maybe
are the two answers causing the problem, let me know.

@ghost
Copy link

ghost commented May 29, 2014

mh...I downloaded the "good-morning-google.flac" from this repository and exactly copied your command (just inserted my API key). Still an empty result. I guess I have to find a different solution for speech recognition. But thanks four your effort :)

@abbas133
Copy link

i am having the same issue, getting an empty response from google. " {"result":[]} "
i m uploading PCM (wav) file, 16k bitrate, single channel,..please somebody help me out.
the file is being record in my java app and then the app itself is uploading it to the url.

@gillesdemey
Copy link
Owner

I can confirm that the API endpoint is still working.

curl -X POST \
--data-binary @'audio/hello (16bit PCM).wav' \
--header 'Content-Type: audio/l16; rate=16000;' \
'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=<your key>'

Be sure to

  • Set the correct sample rate in your headers
  • Ignore the first response, it's always empty

Let me know if you're still experiencing any issues.

@abbas133
Copy link

@gillesdemey thanks for your quick reply.
i figured it out. i was writing data byte by byte instead of whole file.
sorry for bothering you.
thanks a lot. you helped me a lot. not only by answering this question, but by providing such a useful information, thanks a lot. thanks a ton.

@wildroo
Copy link

wildroo commented Jun 12, 2014

Working java code:

//libs to import
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * Send post to google
 */
private void sendPost() throws Exception {
    String USER_AGENT = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2",
    url = "https://www.google.com/speech-api/v2/recognize?output=json&lang=ru-RU&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw&client=chromium&maxresults=6&pfilter=2";

    URL obj = new URL(url);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    // add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Content-Type", "audio/l16; rate=16000");
    con.setRequestProperty("AcceptEncoding", "gzip,deflate,sdch");

    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.write(Files.readAllBytes(Paths
            .get("C:\\tmp\\test_sounds\\1_16000.wav")));
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'POST' request to URL : " + url);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(new InputStreamReader(
            con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    // print result
    System.out.println(response.toString());

}

@Skylion007
Copy link

@fatdh Working Java Library: https://github.com/The-Shadow/java-speech-api

@Babelfish112
Copy link

Hi Github, new user here!

I am having the same problem as everyone else, and I can't get v2 working whatever I try from the posts above.

I had a program working perfectly with the following code:

arecord -D plughw:0,0 -q -f cd -t wav -d 2 -r 16000 | flac - -f --best --sample-rate 16000 -s -o mic.flac;
wget -q -U "Mozilla/5.0" --post-file mic.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 > stt.txt

...and then the speech was output into the stt.txt file.

I am using a Raspberry Pi (Debian) and would appreciate any help on how to get v2 working.

Thanks.

@abbas133
Copy link

@Babelfish112

Hello there !

If you are using same link as you've written in you query, then that link is for Google Speech API V1, whch is not available now, you have to use link for V2.

find the details in comment of @gillesdemey .

@Babelfish112
Copy link

@abbas133

Thanks for your response.

I've finally managed to get a reply by just experimenting with the curl command :)
It's a shame that the requests are limited, and it seems like the link is down to request an increased quota for the Speech API.

@marplx
Copy link

marplx commented Oct 16, 2014

I never saw a RESTful API returning two responses.
This is how you deal with responses in Java Android (Apache HttpClient):

InputStream inputStream = response.getEntity().getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();
String stringReadLine = null;
while ((stringReadLine = bufferedreader.readLine()) != null) {
    stringBuilder.append(stringReadLine + "\n");
}
// Google is weird.    
String result = stringBuilder.toString().replace("{"result":[]}\n","");
JSONObject json = JSONObject(result);

This code does not work without the comment. ;)

@afkatja
Copy link

afkatja commented Nov 21, 2014

Cannot get the API key to work, the response is always that the key in invalid... I have generated a public API key via google developer console to no avail... Any ideas?

@samogot
Copy link

samogot commented Jul 6, 2015

first, empty response is always send. second response is sended only if google can recognise something. this problem may by caused microphone problems or just quiet voice

@amsehili
Copy link

Hello everybody,

  • Make sure to use a valid key and not send over 50 request/day using a free key.
  • Make also sure that you're sending a flac audio file with the right sampling rate in the header.

Some time ago I created this shell script which packages everything you need to use the API (record data for a given duration or use a file, specify language, et.): https://github.com/amsehili/gspeech-rec

For more details about the reverse engineering being used, check out this article: https://aminesehili.wordpress.com/2015/02/08/on-the-use-of-googles-speech-recognition-api-version-2/

Cheers!

@BSalita
Copy link

BSalita commented Dec 16, 2015

I was getting empty responses too. I re-recorded "good-morning-google.flac" from stereo into mono (using Audacity). Now I'm getting correct responses. USE MONO, NOT STEREO. Also, be aware that multiple chunks may be sent. The first chunk is empty, the second may contain a response, depending on the result of the recognition process.

@xiaodao1990
Copy link

thanks @BSalita very much! I got the correct response by your method!

@sunnytambi
Copy link

Thanks @BSalita, your suggestion worked for me too.

@andmerson
Copy link

andmerson commented Apr 3, 2017

Hi there,

I'm also getting returned an empty file. It's clearly writing to the file because if I manually write to the file, it overwrites it with the empty file.

Any suggestions.. I'm very new to this! I'm using bash. Also- if anyone has any python script for Raspberry Pi that would call the Google Speech API- that would be really helpful too!

I don't get any errors. The programs prints "You said:" but nothing after it. And the txt file is empty.

Thank you!

!/bin/bash

echo "recording..press Ctrl+C to stop"
arecord "plughw:1,0" -q -f cd -t wav | ffmpeg -loglevel panic -y -i -- -ar 16000 -acodec flacfile.flac

echo "processing..."
wget -q -U "Mozilla/5.0" --post-file file.flac --header "Context-Type:audio/x-flac; rate=16000" -O -- "http://www.google.com/speech-api/v2/recognize?output=jason&lang=en-us&key=AIzaSyCAHjRsoSSrXLgG4Iov6x_r8jL8rzT--t4" | cut -d " " -f12 > stt.txt

echo -n 'You Said:'
cat stt.txt

rm file.flac > /dev/null 2>&1

@DineshGuptaa
Copy link

DineshGuptaa commented Aug 12, 2017

Hi All,
I am using JARVIS to record '.flac' audio file and send to the google speech recognizer but getting empty response.

I am recoding audio in flac format and sending for to convert into text. Please help me where I am ding wrong. I spend on this 2 days on the same.
Your help is much appreciated.

Thanks in advance.

Here the my code
`
package com.example.speech;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import com.darkprograms.speech.microphone.Microphone;
// Imports the Google Cloud client library
import com.google.cloud.speech.v1.RecognitionAudio;
import com.google.cloud.speech.v1.RecognitionConfig;
import com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding;
import com.google.cloud.speech.v1.RecognizeResponse;
import com.google.cloud.speech.v1.SpeechClient;
import com.google.cloud.speech.v1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1.SpeechRecognitionResult;
import com.google.protobuf.ByteString;

import net.sourceforge.javaflacencoder.FLACFileWriter;

public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
SpeechClient speech = SpeechClient.create();

// Builds the sync recognize request
RecognitionConfig config = RecognitionConfig.newBuilder()
	      .setEncoding(AudioEncoding.FLAC)
	      .setLanguageCode("en-US")
	      .build();

Microphone mic = new Microphone(FLACFileWriter.FLAC);
final String auName = "./resources/testFile.flac";
File file = new File (auName);	//Name your file whatever you want
try {
  mic.captureAudioToFile (file);
} catch (Exception ex) {
  //Microphone not available or some other error.
  System.out.println ("ERROR: Microphone is not availible.");
  ex.printStackTrace ();
}

/* User records the voice here. Microphone starts a separate thread so do whatever you want
 * in the mean time. Show a recording icon or whatever.
 */
try {
  System.out.println ("Recording...");
  Thread.sleep (5000);	//In our case, we'll just wait 5 seconds.
  mic.close ();
} catch (InterruptedException ex) {
  ex.printStackTrace ();
}

mic.close ();		//Ends recording and frees the resources
System.out.println ("Recording stopped.");

Path path = Paths.get(auName);
byte[] data = Files.readAllBytes(path);
System.err.println(data.length);
ByteString audioBytes = ByteString.copyFrom(data);
RecognitionAudio audio = RecognitionAudio.newBuilder()
        .setContent(audioBytes)
        .build();
// Performs speech recognition on the audio file
RecognizeResponse response = speech.recognize(config,audio);
List<SpeechRecognitionResult> results = response.getResultsList();
System.err.println("Alternatives :" + results.size());
for (SpeechRecognitionResult result: results) {
  List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList();
  for (SpeechRecognitionAlternative alternative: alternatives) {
    System.out.printf("Transcription: %s%n", alternative.getTranscript());
  }
}
speech.close();

}
}
`
Here is my pom file

`
4.0.0
GoogleSpeech
GoogleSpeech
0.0.1-SNAPSHOT
Sample Speech
Sample Speech

<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

com.google.cloud google-cloud-speech 0.21.1-alpha net.sourceforge.javaflacencoder java-flac-encoder 0.3.7 org.json json 20150729
<!-- Test dependencies -->
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.google.truth</groupId>
  <artifactId>truth</artifactId>
  <version>0.34</version>
  <scope>test</scope>
</dependency>
maven-assembly-plugin com.example.language.QuickstartSample jar-with-dependencies `

@dineshone
Copy link

I got the same problem. I am sending a flac audio file and all that I am getting is an empty response. I have no idea how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests