how to set the audio file sample rate for watson text to speech in node-red - text-to-speech

watson text to speech accepts extra parameters such as the sampling (default is 44khz)
see https://www.ibm.com/watson/developercloud/text-to-speech/api/v1/#synthesize_audio for options such as this one
(...)
audio/l16;rate=rate
(You can optionally specify endianness=big-endian
or endianness=little-endian; the default is little endian.)
(...)
but I can't see a way to set these options in node red

In the Node-red, doesn't have the option, because you need to add in your cURL.
As you can see, you can use Accept or accept query parameter header to specify the audio format.
For example:
curl -X POST -u "{username}":"{password}"
--header "Content-Type: application/json"
--header "Accept: audio/l16;endianness=big-endian"
--data "{\"text\":\"Hello world\"}"
--output hello_world.wav
"https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_AllisonVoice"
See the Official Text to Speech v1 API Explorer.

Please raise this as an improvement request on the github repo for the nodes, we can continue the discussion there. No promises, but I am open to accepting a pull request, if done right.

Related

Not able to create ENV variable using API token

I was trying to automate creating ENV variables in CI/CD by using API commands, but unfortunately getting 401 Unauthorized error.
Earlier I used to do this in same way and was able to do it.
But now it’s throwing an error, could anyone please help me to find out.
Command:
curl --request POST --header “PRIVATE-TOKEN: <your_access_token>” \
“https://gitlab.com/api/v4/projects/1/variables” --form “key=NEW_VARIABLE” --form “value=new value”
Please look into the error message:
The "Create a variable" API call indeed looks like:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value"
(make sure to use the right double-quotes " instead of “)
Double-check the ID of the project (in your case "1") and make sure the user authenticated with your token has the right permissions:
They must be "maintainer" or "owner", in order to have the right to "Manage project-level CI/CD variables".
Example, using a Personal Access Token with api scope, starting with glpat- (glpat-xxxxxxx), I can first list my projects (using jq):
curl -XGET --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/owned?=true"|jq ".[] | \"\(.id) \(.path_with_namespace)\""
That allows me to find the project id
I can then list variables for an existing project:
curl -XGET --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/<projectId>/variables"
Result:
[]
I have none on that project.
I will set one with:
curl -XPOST --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/<projectId>/variables" --form "key=NEW_VARIABLE" --form "value=new value"
Result:
{"variable_type":"env_var","key":"NEW_VARIABLE","value":"new value","protected":false,"masked":false,"environment_scope":"*"}
Let's double-check with:
curl -XGET --header "PRIVATE-TOKEN: glpat-xxxx" "https://gitlab.com/api/v4/projects/<projectId>/variables"
Result:
[{"variable_type":"env_var","key":"NEW_VARIABLE","value":"new value","protected":false,"masked":false,"environment_scope":"*"}]
It does work.
The OP Anirban Das confirms in the comments an issue with how Postman was used:
Actually in the body of Postman, select 'form', there I had mentioned directly key name in the Key section and value in the Value section.
But that was not correct.
In the Key section, we need to mention "key" and key name should be in Value section.
Similarly "value" in key section and it's value in Value section.
Once this worked, you will see "</>" icon in right navigation pane, which will provide you corresponding curl command

How to update gitlab merge request with curl? Getting 401 all the time

Need to update labels in merge request during gitlab ci. Tried different variants:
curl -X PUT https://gitlab.com/api/v4/projects/{project_id}/merge_requests/134?access_token={token}&labels=merged
Tried passing token as header and as data.
Tried passing "personal_token", "access_token", "token" and etc.
Getting {"message":"401 Unauthorized"} all the time.
I think that you should use private_token as it said on documentation:
curl https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>
or in the header, as you said:
curl --header "PRIVATE-TOKEN: xxx" "https://gitlab.com/api/v4/projects"
Have a look on the official page:
https://docs.gitlab.com/ee/api/README.html#personal-access-tokens
Example:
Getting information from merge request with iid 1(the actual labels are testlabel and testlabel3):
#curl -X GET https://gitlab.com/api/v4/projects/11209705/merge_requests/1?private_token={XXXXXX}
{"id":28761206,"iid":1,"project_id":1120970.......,"labels":["testlabel","testlabel3"],...}
Sending put with curl with "--data" and the parameter to update "labels" to "test":
# curl -X PUT https://gitlab.com/api/v4/projects/11209705/merge_requests/1?private_token={XXXXX} --data "labels=test"
Getting information from merge request with iid 1(the actual labels is "test"):
#curl -X GET https://gitlab.com/api/v4/projects/11209705/merge_requests/1?private_token={XXXXXX}
{"id":28761206,"iid":1,"project_id":1120970.......,"labels":["test"],...}

how to send correct curl command to webserver

So I got the data that is being sent to a specific server. Now I want to do the same using curl from my local machine to play around with specific repsonses from the server and learn more about curl as well.
Here is part of my data
POST /auth HTTP/1.1
platform: android
X-Auth-Token: <censored>
Content-Type: application/json; charset=utf-8
Host: api.blabla.com
Accept-Encoding: gzip
And the data that is being sent:
{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}
Now when I try cURL in my dos shell, I try
curl --insecure -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
The response I get from cURL is this:
{"code":401,"error":"blablaTokenRequired"}
Even though I specified the token. So there are two possible scenarios because the token is correct:
It has something to do with the SSL thing? (I use --insecure because I get an SSL error otherwise)
Something about my command is not correct but I can't figure out what.
Can someone kindly help me out? I am trying everything I can without success
I am not sure if I understand your application specific right, but probably one thing you need to take into account:
man curl says:
-d, --data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when
a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the
server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
-d, --data is the same as --data-ascii. --data-raw is almost the same but does not have a special interpreta‐
tion of the # character. To post data purely binary, you should instead use the --data-binary option. To URL-
encode the value of a form field you may use --data-urlencode.
As I can't see in your example the necessity of sending data as HTML form input, probably your application expects just a "raw" POST body and then you have to try this:
curl --insecure -X POST https://api.blabla.com/auth --data--binary '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
PS and for sure this is error is not about using --insecure which just asks curl to neglect ssl verification
you forgot the headers and enabling compressed encoding (gzip), however, i believe you can't force curl to only support gzip encoding using the curl command line alone, you will have to use libcurl, this will make the request say "Accept-Encoding: gzip,deflate" on most systems, using --compressed .. if that's not acceptable to you, rewrite it using libcurl (where you can force it to say only "gzip", if you wish, via CURLOPT_ENCODING )
curl -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}' --header 'platform: android' --header 'X-Auth-Token: <censored>' --header 'Content-Type: application/json; charset=utf-8' --header 'Host: api.blabla.com' --compressed
another gotcha: on some systems, there will be a default useragent header (like debian 6), while on some systems, curl comes without a default useragent (like debian 8).. you might want to use --user-agent '' too

Pushbullet API from cURL - invalid request

I'm working on an app using Pushbullet's API, but I'm running into odd errors when running through the sample code at https://docs.pushbullet.com/v2/pushes/.
I'm executing the following cURL command (in Windows):
curl -k -u <MY_API_KEY>: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'
...but it keeps generating the following error:
{"error": {"type":"invalid_request","message":"The param 'type' has an invalid value.","param":"type","cat":"\u003e:3"}}
It also produces this error:
The other commands for the other endpoints in the documentation work fine...it's just this one.
Got any suggestions? Thanks for the help! :)
It looks like windows doesn't support those kinds of quotes on the command line. Here's an example that works:
curl https://api.pushbullet.com/v2/pushes -X POST -u <access token>: --header "Content-Type: application/json" --data-binary "{\"type\": \"note\", \"title\":\"Note Title\", \"body\": \"Note Body\"}"
I think I'm going to try to replace the curl examples with something that has less confusing behavior.
I figured it out - I don't really know why, but the cURL command wasn't working through the DOS prompt, and also wasn't working using the Postman REST client for Chrome, but I got it working in the DHC extension for Chrome. The trick was setting the Authorization header to "Basic", which resolves the Pushbullet access token to some other form, and makes a successful the HTTP request.
Hope this helps someone down the road if they run into this on Windows!

Can I set multiple headers with Siege?

I want to use siege to target a number of URLs on my app, each with different headers. I can set headers for one request
siege -u http://localhost/xyz -d1 -r1000 -c25 --header="Token: f2840fc1"
(this appears to be undocumented)
I can specify a list of URLs in the URL file, with custom headers for each URL. But I can't see a way in the docs.
I suggest using two concurrent calls to siege. Write a URL file that uses Header-A, and another for Header-B.
For my API testing, I've got a get_urls.txt file and post_json_urls.txt file, which I call on two instances of Siege at once. This way one gets called with Content-Type: text/json and the other doesn't. Short of rewriting the Siege url parser, this is the only way I know to do it.
For example:
siege -f get_urls.txt & siege -H 'Content-Type: text/json' -f post_json_urls.txt
As far as I can see from the man page and reading around I think you are right. The only way to specify headers is on the command line using the -H --header options not in the URL file.
You can try this example siege --concurrent=5 --reps=100 --header='sdk:3.0, config:3.0,zid:0' 'https://google.com/api/REGME POST uid=a8qn&aid=43ZK0'