2

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?

Alex Chihaia
  • 145
  • 2
  • 4
  • 19

3 Answers3

3

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.

Community
  • 1
  • 1
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • Hi Nikolay, do you know if the Android and Google Cloud APIs use the same server/technology? ie do they perform the same? – ishido Feb 01 '17 at 07:55
  • they don't perform the same. google speech api is far superior. that's why it is't free (for commercial purposes at least). –  Oct 08 '18 at 19:40
1

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.

Josh
  • 6,251
  • 2
  • 46
  • 73
  • HI @Josh , I am having issues where it fails after 3rd or 4th try as I can see ASR is taking 6-7 seconds to shut down after each request! Do you have a solution for it ? – SKG Apr 18 '18 at 15:30
  • @SKG Which error does your speech recognition code return? I had such problems too, I can give you some tips depending on your reply... – Josh Apr 19 '18 at 09:08
  • Are you sure that adding that JSON into your project is secure? – frapeti Apr 27 '18 at 14:19
  • @frapeti I think you should not add JSON in prod app. – SKG Jul 17 '18 at 15:34
  • @SKG The question doesn't call for Production grade app security. You can edit my answer to include security measures though. – Josh Jul 18 '18 at 07:55
  • Hi @Josh were you able to shutdown speech recognition service faster? and can provide some sample code to close and open entire ASR recognizer properly? – Zayid Mohammed Sep 05 '19 at 13:50
0

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.

raf
  • 13
  • 4
  • We need more support and tutorials to implement G cloud API and that to use provided examples in our app. – Rifat Jun 28 '19 at 02:27