IBM Watson text-to-speech curl example not working - ibm-cloud

Here is the command I am using to test the text-to-speech API:
/usr/bin/curl -k -u 'USERNAME':'PASSWORD' -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: audio/wav' \
--data '{"text":"hellow world","voice":"en-US_AllisonVoice"}' \
'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize' > ./public/138106.wav
The command above doesn't seem to generate the desired audio file. I have a bluemix account and the right credentials. An audio file is generated, but it's corrupt.

voice is a URL parameter. The correct curl command looks like this:
/usr/bin/curl -k -u 'USERNAME':'PASSWORD' -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: audio/wav' \
--data '{"text":"hellow world"}' \
'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_AllisonVoice'
Disclosure: I am an evangelist for IBM Watson.

--data '{"text":"hellow world","voice":"en-US_AllisonVoice"}'
Try this:
--data "{\"text\":\"hello world\", \"voice\":\"en-US_AllisonVoice\"}"
I took this syntax from the API documentation found here: https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/text-to-speech/quick-curl.shtml
It seems they have built the syntax of the JSON differently than your command.

I solved it not using the cURL scripting recommendation.
But by going directly to the url: https://stream.watsonplatform.net/speech-to-text/api/v1/recognize
Then removing the following 2 lines:
"word_alternatives_threshold": null,
"keywords_threshold": null,
There are issues with these lines.

Related

Unable to access github API getting bad credentials error

I am trying to add a custom code check for a PR. After doing some research I found out that it can be done using the API mentioned below.
POST /repos/{owner}/{repo}/check-runs
Initially, it was giving me this error:
{
"message": "You must authenticate via a GitHub App.",
"documentation_url": "https://docs.github.com/rest/reference/checks#create-a-check-run"
}
I followed the guideline provided in this link.
I created a GitHub app.
Gave it required permission.
Generated a private key.
Generated a JWT token using the private key.
Installed the Github app in the repo too
I created a curl request:
curl --location --request POST 'https://api.github.com/repos/X/X-app/check-runs' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.X.X-X-SAFvDnSkaJDjMI2T_BAC2iLlRZ7uNyFSe-X-UgFBFjoFrwsbcYFKfDM8f3FNPYpA6afhr18DLZ6rzu35klA' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "loremipsum"
}'
But, now I am getting this error
{
"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest"
}
I am not sure what I am missing here.
I figured this out. The GH documentation is a bit unclear/misleading. Here are the steps to make this work:
with the JWT bearer token, list your installations and note the installation id for your app
$ curl -i \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/app/installations
then get an installation access token for the above id
$ curl -i -X POST \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/app/installations/:installation_id/access_tokens
then with that token create the check run but use "Authorization: token" header
curl -i -H "Authorization: token YOUR_INSTALLATION_ACCESS_TOKEN"

IBM Watson Text-to-Speech issue with German umlaute (ä-ö-ü)

I have a porblem when I want to export a .wav file.
With the English language i don't have any issues also when i want to export a German sentence without any Umlaute it works fine. But when i want to export something like "Häuschen" I can't open the file and it's also only 1KB big. Do you guys know what could be the problem?
I used the following code on WIN10
curl -X POST -u "apikey:{key}" ^
--header "Content-Type: application/json" ^
--header "Accept: audio/wav" ^
--data "{\"text\":\"Häuschen\"}" ^
--output Haeuschen.wav ^
"{url}/v1/voices/de-DE_ErikaV3Voice/synthesize"
I have tried to reproduce this on MacOs ... I had to replace the ^ with \ to have the correct multi line syntax, but other than that no change to your command.
curl -X POST -u "apikey:{key}" \
--header "Content-Type: application/json" \
--header "Accept: audio/wav" \
--data "{\"text\":\"Häuschen\"}" \
--output Haeuschen.wav \
"{url}/v1/voices/de-DE_ErikaV3Voice/synthesize"
The service returned a playable file that was 45KB big. So even this is not a solution for your problem, this gives you a data point that it should work and you can search for the right way to send this from a Windows machine now.

How to add a label to an issue using GitHub API?

I'm trying to find a way to add a label to a GitHub issue using the API. After checking the API documentation I tried the following curl request:
curl -X POST -H "Authorization: token OOOOOOOOOOOOOOOO" -H \
"Accept: application/vnd.github.symmetra-preview+json" \
-d #label.json https://api.github.com/repos/CHSUNSONG/star-platform/issues/11
label.json contains:
["submitted"]
However, I got the following response:
{
"message": "Invalid request.\n\nFor 'links/1/schema', [\"submitted\"] is not an object.",
"documentation_url": "https://developer.github.com/v3/issues/#edit-an-issue"
}
Why isn't this working and how can I fix it?
You're POSTing to the wrong URL. Add /labels onto the end:
curl -X POST -H "Authorization: token OOOOOOOOOOOOOOOO" -H \
"Accept: application/vnd.github.symmetra-preview+json" \
-d #label.json \
https://api.github.com/repos/CHSUNSONG/star-platform/issues/11/labels

Request to VSTS REST API only works on Postman

I'm trying to run this request
curl -X POST \
'https://*****.visualstudio.com/DefaultCollection/_apis/wit/wiql?=&api-version=1.0' \
-H 'authorization: Basic *****' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: *****' \
-d '{
"query": "SELECT [System.Id] FROM WorkItems"
}'
but I keep getting this error
{"count":1,"value":{"Message":"A value is required but was not present in the request.\r\n"}}
It works as expected on Postman, so I think the request and the server are OK.
I'm trying to follow the first example shown here: https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql
Am I missing something?
The URL is wrong, remove =& from the REST API url and the url will be like this:
https://*****.visualstudio.com/DefaultCollection/_apis/wit/wiql?api-version=1.

Setting Query Parameter on MongoHQ beta API

I'm using the beta api on MongoHQ.com to query a database I set up earlier this week.
I can retrieve the list of databases on my account, the collections in each database and the documents in each collection using the basic URLs.
However, when I try to set a query, limit, fields, etc parameter, it's returning a 404 error.
This is the curl command I'm using:
curl -i -X GET 'https://beta-api.mongohq.com/mongo/<deployment id>/<database name>/collections/<collection name>/documents?query={"name": "Name"}' \
-H 'Content-Type: application/json' -H 'Authorization: api-key <API KEY>'
According to the documentation on the site here - https://docs.mongohq.com/mongohq-api-beta/mongodb-documents.html - the query has to be a "URL encoded MongoDB Extended JSON document". Unfortunately there are no examples of this.
How would I convert the query document above to a URL encoded one?
You can use curl to urlencode your query like this:
curl -i -X GET 'https://beta-api.mongohq.com/mongo/<deployment id>/<database name>/collections/<collection name>/documents' \
-G --data-urlencode 'query={"name": "Name"}' \
-H 'Content-Type: application/json' -H 'Authorization: api-key <API KEY>'
If you use operators like e.g. $gt, be sure to put double quotes around them:
curl -i -X GET 'https://beta-api.mongohq.com/mongo/<deployment id>/<database name>/collections/<collection name>/documents' \
-G --data-urlencode 'query={"value": { "$gt" : 10}}' \
-H 'Content-Type: application/json' -H 'Authorization: api-key <API KEY>'