Skip to content

Instantly share code, notes, and snippets.

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

Google Speech To Text API

Base URL:
It accepts POST requests with voice file encoded in FLAC format, and query parameters for control.

Query Parameters

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

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

Maximum results to return for utterance


Should contain FLAC formatted voice binary

HTTP Header

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

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


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


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' \


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;' \
Copy link

Hello everybody,

Some time ago I created this shell script which packages everything you need to use the API v2 (record data for a given duration or use a file, specify language, filter out results, etc.):

For more details about the reverse engineering being used, check out this article:


Copy link

rogo21 commented Feb 4, 2016

how to divide audio into frames of 15 sec using java code or command line??

Copy link

ghost commented Jul 21, 2016

Hi, -> 400. That’s an error.
I am in Canada

Copy link

HI, Sending 'POST' request to URL :
Response Code : 200

I am getting above code.. But no output of recorded file to be convert in to text. How do I get that ?

Copy link

IvanZhao commented Sep 5, 2016

Hi everybody,
When I was "POST".
I receive the error message like this:
"code": 403,
"errors": [
"domain": "global",
"message": "Requests from this Android client application are blocked.",
"reason": "forbidden"
"message": "Requests from this Android client application are blocked.",
Dose any buddy knows how to resolve this problem?

Copy link

indrabayu commented Nov 24, 2016

    public static async Task<string> RequestGoogleSpeechAPIAsync(byte[] byteArray) 
        var httpClient = new HttpClient();
        var mediaType = new MediaTypeWithQualityHeaderValue("audio/x-flac");
        var parameter = new NameValueHeaderValue("rate", "16000");

        var url = "";
        var appSettings = ConfigurationManager.AppSettings;
        var apiKey = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw";
        var uri = new Uri(url + apiKey);

        using (MemoryStream ms = new MemoryStream(byteArray, 0, byteArray.Length))
            var param = new StreamContent(ms);
            param.Headers.ContentType = mediaType;

            var result = await httpClient.PostAsync(uri, param);

            var responseFromServer = await result.Content.ReadAsStringAsync();
            var responseArray = responseFromServer.Split('\n');
            var responseJson = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<SpajamHonsen.Models.GoogleSpeechAPIResponseModel.Resuls>(responceArray[1]));

            return responseJson.result[0].alternative[0].transcript;

Copy link

fj4870 commented Dec 1, 2016

Request you to please share speech to text c# code.

Copy link

Nalinh commented Apr 4, 2017

i can't run :(
result is blank, tell me why, plz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment