Google Cloud Text to Speech INVALID API KEY - google-cloud-platform

I followed this page:
https://cloud.google.com/text-to-speech/docs/quickstart-protocol
I generated an access token with:
gcloud auth application-default print-access-token
and upon entering this:
curl -H "Authorization: Bearer "$(my_token_is_in_here) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1/text:synthesize" > synthesize-text.txt
I got this:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 605 0 297 100 308 297 308 0:00:01 --:--:-- 0:00:01 3517
Buth then I opened up synthesize-text.txt and found
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
Clearly gcloud is giving me a token, why doesnt text-to-speech recognize it?

[SOLVED]
1) I went to APIs and Services in the 'hamburger' drop down
2) I went to 'credentials' submenu in left column
3) I did 'create credentials' and selected API key
then in my request I formulated as
Curl -H "X-Goog-Api-Key: my-newly-created-API-key" -H "Content-Type: application/json; charset=utf-8" --data "{'input':{'text':'Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets.'},'voice':{'languageCode':'en-gb','name':'en-GB-Standard-A','ssmlGender':'FEMALE'},'audioConfig':{'audioEncoding':'MP3'}}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > synthesize-text.txt
now it works.
So it seems the use of 'Authorization Bearer' with the service account key does not work.
I am using Windows 10.

Like Fredrik has said in his comment, there is an error in Google's Docs and it should be: -H "Authorization: Bearer $(my_token_is_in_here)" (" at the end, not after Bearer)

Related

Reset password by using cURL restAPIs in wso2 IS

In wso2-IS 5.11, trying Update Password Operation through cURL restAPI command.
I got reset password mail notification for below curl request,
$ curl -X POST -k -H "Authorization: Basic YWRxxxx=" -H "Content-Type: application/json" -d '{"user": {"username": "John","realm": "PRIMARY"},"properties": []}' "https://localhost:9445/api/identity/recovery/v0.9/recover-password?type=email&notify=true"
but instead of reset the password in reset-password-window , I need to pass the reset password values through cURL same like this, but this also requires Confirmation keycode with validity period and this is availlable in IDN_RecoveryDataTable as per this doc, so where this "IDN recovery data table" find out.? and shall I use same operation? or need to try some different use cases like , active and inactive user via cURL RestAPI ,and 3rd case Invalid password.
It seems you are following the blog [1] and referring to ii) Update Password step.
IDN_RECOVERY_DATA is a table of the identity database where WSO2IS stores information about the recovery flow. But you don't have to worry about the data stored in the database.
If you are just trying to change the password of a user without sending an email, you can use SCIM APIs.
Following is an example to update the password of a user when the existing password is provided.
curl -X PATCH 'https://localhost:9443/scim2/Me' \
-H 'accept: application/scim+json' \
-H 'Content-Type: application/scim+json' \
-H 'Authorization: Basic {base64(username:currentPassword)}' \
-d '{ "schemas": [ "urn:ietf:params:scim:api:messages:2.0:PatchOp" ], "Operations": [ { "op": "replace", "value": { "password": "newPassword" } } ]}'
If you want to send an email and void WSO2 UIs for creating the new password, you can change the email template to redirect the user to your UI once the user clicks the link in the email. Then use the confirmation code included in that link to invoke the password set-password API. The document [2] has information on the APIs related to the account recovery, available in WSO2 Identity Server 5.11.0.
For locking or disabling a user, you can use the SCIM APIs to patch the relevant user attributes.
[1] https://medium.com/#isurakarunaratne/password-recovery-wso2-identity-server-b80abe2bcc61
[2] https://docs.wso2.com/display/IS511/apidocs/account-recovery/

Google Cloud Speech API longrunningrecognize only returns name

I'm trying to convert over an hour audio data to text using Google Cloud Speech API, and I'm using API explorer since it's easy.
The request looks like this.
POST https://speech.googleapis.com/v1/speech:longrunningrecognize?key={YOUR_API_KEY}
{
"audio": {
"uri": "gs://data/audio.flac"
},
"config": {
"encoding": "FLAC",
"languageCode": "en-US"
}
}
The response look like this.
200
Show headers
{
"name": "`numbers`"
}
How come it is only returning the name, and not returning the text of the audio?
Just had the same problem.
Found the answer on https://cloud.google.com/speech/docs/async-recognize
If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:
{
"name": "5543203840552489181"
}
where name is the name of the long running operation created for the request.
Wait approximately 30 seconds for processing to complete. To retrieve the result of the operation, make a GET request:
GET https://speech.googleapis.com/v1/operations/YOUR_OPERATION_NAME?key=YOUR_API_KEY
Got my results with:
curl -s -k -H "Content-Type: application/json" \
-H "Authorization: Bearer {access_token}" \
https://speech.googleapis.com/v1/operations/{name}

Google cloudstorage returns 404 Not Found when trying to delete from bucket

I am trying to delete a file (video) from Google Cloud Storage via the cloudstorage api but although the file exists I'm getting the following error:
cloudstorage.delete('/catchamove-video/products/6411421952770048.mp4')
*** NotFoundError: Expect status [204] from Google Storage. But got status 404.
Path: '/catchamove-video/products/6411421952770048.mp4'.
Request headers: None.
Response headers: {'transfer-encoding': 'chunked', 'date': 'Sun, 07 May 2017 12:31:47 GMT', 'server': 'Development/2.0'}.
Body: ''.
Extra info: None.
Both the bucket and file are present on the console.
I am facing the same problem: getting 404 when delete a folder via REST API.
After some tests, I figured out how delete folder of GCP storage -
Have to delete all files (objects) in the folder, files in sub-folders and sub-folders and folder. Be noticed that when deleting empty folder, you may still get "404 Not Found"(normally gets 204), just ignore it and the empty folder will be actually deleted.
Examples:
curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2Fsub-folder%2Ffile1
curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2Fsub-folder%2Ffile2
curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2Fsub-folder%2F #May get 204 or 404 response code
curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2F #May get 204 or 404 response code
NOTE: "%2F" in the URL is actually "/" character

google speech api Invalid recognition

I am trying to follow the example on google speech api found here
https://cloud.google.com/speech/docs/getting-started
1) I created the follow json request file
{
'config': {
'encoding':'FLAC',
'sampleRate': 16000,
'languageCode': 'en-US'
},
'audio': {
'uri':'gs://cloud-samples-tests/speech/brooklyn.flac'
}
}
2) Authenticate to my service account
gcloud auth activate-service-account --key-file=service-account-key-file
3) Obtain my authorization token successfully
gcloud auth print-access-token
access_token
4) Then use the following curl command
curl -s -k -H "Content-Type: application/json" \
-H "Authorization: Bearer access_token" \
https://speech.googleapis.com/v1beta1/speech:syncrecognize \
-d #sync-request.json
But I keep getting the following response
{
"error": {
"code": 400,
"message": "Invalid recognition 'config': bad encoding..",
"status": "INVALID_ARGUMENT"
}
}
Do I need access permissions for the uri gs://cloud-samples-tests/speech/brooklyn.flac? Is that what the problem is?
Thanks in advance..
In my opinion, it is a file format issue.
You have to send WAV file instead of FLAC ...
[ FLAC and MP3 format are not supported <=> need a file conversion (representing cost) on the server sideĀ ]
Convert your audio file to WAV (using ffmpeg or avconv), then retry.
You may also take a look here (to see a working example)
For me, the solution was to remove the space between "-d #",
so change "-d #sync-request.json" to "-d#sync-request.json".
I got help here: https://groups.google.com/forum/#!topic/cloud-speech-discuss/bL_N5aJDG5A. Apparently the file was being read and processed, but the parms were going to the "curl.exe" instead of being passed to the URL.
I understand this is quite late for an answer. However, it might help others so putting in your error.
The config that you are passing is actually incorrect. The attributes should be like:
{
"config": {
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"languageCode": "en-US",
"maxAlternatives": 1,
"profanityFilter": true,
"enableWordTimeOffsets": false
},
"uri": {
"content":"<your uri>"
}
}

How to register REST client in WSO2 API Manager

I've been looking through the doc of wso2 apim.
https://docs.wso2.com/display/AM1100/apidocs/store/index.html#guide
And found the curl request:
curl -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -d #payload.json http://localhost:9763/client-registration/v0.9/register
With payload:
{
"callbackUrl": "www.google.lk",
"clientName": "rest_api_store",
"tokenScope": "Production",
"owner": "admin",
"grantType": "password refresh_token",
"saasApp": true
}
But I got and 403 error response.
As expected I should get the correct response payload like:
{
"callBackURL": "www.google.lk",
"jsonString":
"{
\"username\":\"admin\",
\"redirect_uris\":\"www.google.lk\",
\"tokenScope\":[Ljava.lang.String;#3a73796a,
\"client_name\":\"admin_rest_api_store\",
\"grant_types\":\"authorization_code password refresh_token iwa:ntlm
urn:ietf:params:oauth:grant-type:saml2-bearer client_credentialsimplicit\"
}",
"clientName": null,
"clientId": "HfEl1jJPdg5tbtrxhAwybN05QGoa",
"clientSecret": "l6c0aoLcWR3fwezHhc7XoGOht5Aa"
}
I have not idea what's going on, I just followed the doc above and without any changes.
Will be appreciated if anyone can help.
Thanks.
Looks like your DCR call is being blocked by some security filter. May be because you're reaching a wrong endpoint.
I believe you're using APIM 2.0.0. If yes, your DCR url should be this. (note version v0.10)
http://localhost:9763/client-registration/v0.10/register
Try and see if this solves your issue.
Update: Looks like this URL is wrong on 2.0.0 docs. I'll reach WSO2 Docs team to fix it.