Skip to content

[google-cloud-java][Text-to-Speech][Android] want to use api key #3400

@changemyminds

Description

@changemyminds

I use the Text-to-Speech Java Library on my Android app.
I want to use google cloud api-key to use the Text-to-Speech Java Library.

On my android. If I did the following code, it got the error message.

try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { 
}

/* 
error message
java.io.IOException: The Application Default Credentials are not available. 
They are available if running in Google Compute Engine. 
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.
See https://developers.google.com/accounts/docs/application-default-credentials for more information.
*/

So I read the Authentication API Keys document and found API-Key not support Text-to-Speech, so I can't use api-key to Text-to-Speech Java Library.

If I want to use Text-to-Speech by API-Key or Text-to-Speech Java Library on Android. How can I do it ?

The following code is my command line and execute on mac and It work fine and can get the "audioContent". I think I can use http method by java. Is there any other way ?

Curl -H "X-Goog-Api-Key: API_KEY" \
  -H "Content-Type: application/json; charset=utf-8" \
  --data "{
    'input':{
      'text':'Hello I am david, Nice to meet you'
    },
    'voice':{
      'languageCode':'en-gb',
      'name':'en-GB-Standard-A',
      'ssmlGender':'FEMALE'
    },
    'audioConfig':{
      'audioEncoding':'MP3'
    }
  }" "https://texttospeech.googleapis.com/v1beta1/text:synthesize"

Metadata

Metadata

Assignees

Labels

androidapi: texttospeechIssues related to the Text-to-Speech API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions