Alex Chihaia
Alex Chihaia

Reputation: 155

How can I use Google Cloud speech API from Android?

I have a college project and I'm developing an Android Application that acts like a translator. For normal text translation I'm using Google Cloud Translation API and I saw they have an option to translate text via speech using Google Cloud speech API. Problem is I don't have a starting point, and I didn't understand how can I use it.

So, is there an example of how can I use Google Cloud speech API from my Android application?

Upvotes: 3

Views: 15687

Answers (3)

raf
raf

Reputation: 13

There are some key differences between Android Speech API and Google Cloud Speech API though. While the Android Speech API is free, it is limited to short phrases and is unable to process audio from files. Each speech recognition also starts and ends with a distinctive beep so the user is aware that the microphone is in listening mode - kind of a Google way to prevent writing a spoofing app, when the speech recognizer runs in the background and sends the transcript to the backend server. These limitations are lifted for Google Cloud Speech, but the integration with Android is almost non-existent. While there is an Android demo project, adapting it to yours won't be easy and one will face multiple challenges and error resolutions. And here is what Google states on their website:

Note: Cloud Java client libraries do not currently support Android.

Upvotes: 0

Josh
Josh

Reputation: 6373

Yes it is possible, I have done it, based on Googles "speech" example inside "android-docs-samples-master" (google and download those samples). Things you need to know:

  1. You will need to setup a free Google Cloud account, and activate billing. BILLING? WTF DO I NEED TO PAY? Hold on!!! keep reading my answer!!
  2. The first 60min of speech recognition time of EVERY month are FREE.
  3. Setting up billing and obtaining the PREF_ACCESS_TOKEN_VALUE value you need to add to your SpeechRecognizer class requires patience, remember. You also need to obtain an authentication json from google and add it to the "res -> raw" folder of you project.
  4. The speech demo is not well suited for fast consecutive ASR requests, as shutting down the speech recognition service takes 2-6 seconds (I am working on this).

UPDATE: If you got this working, you might have noticed that the 3rd or 4th time you do ASR, it fails. This is because the sample code is not designed to close and open the entire ASR recognizer properly. I got it working, if you need help on a specific error let me know. This is a summarized guide, if you need more details on a particular step let me know.

Upvotes: 0

Nikolay Shmyrev
Nikolay Shmyrev

Reputation: 25220

Android runs Java examples just fine. You can find them on github.

You can also use Android Speech API, it is free, unlike Google Cloud Speech API.

Upvotes: 3

Related Questions