Common Curl API problems: quote within quote / IBM Speech-to-text API

6 views
Skip to first unread message

r poon

unread,
Mar 23, 2019, 7:28:43 AM3/23/19
to Machine Intelligence and Data Science Group

After get stuckec for more than once, and having seen various stackoverflow and web questions for "URL not found".. and various type of errors, it is worth take note of the following:


In Windows prompt it is daunting due to quote within quote. I tried this out and work: 

1. The original post in IBM web site/cloud has two versions, 

--data '{"text": "hello world"}', another one is
--data "{\"text\":\"hello world\"}'

(ie. if you use only double quote within double quote, you must use \, and also no space after :)

2. if you use the second way, you can't have space after colon:
So better always delete the space for safe.

3. Both of the following works:


-X POST -u "apikey:xxxxxxxxxxxxxxxxxxxxx" --header "Content-Type: application/json" --header "Accept: audio/wav" --data '{"text":"hello world"}' --output hello_world.wav  "https://stream.watsonplatform.net/api/text-to-speech/api/v1/synthesize"

C:\Users\rpo\IBM-Watson>curl -X POST -u "apikey:xxxxxxxxxxxxxxxxxx" --header "Content-Type: application/json" --header "Accept: audio/wav" --data "{\"text\":\"hello world\"}" --output "hello_world.wav"  https://stream.watsonplatform.net/api/text-to-speech/api/v1/synthesize

4. It seems no need to quote the http string...


*********************************************************************


Reference: original IBM Watson Speech-to-text api:

Try an API call

The following commands use the POST /v1/synthesize method to synthesize US English input to audio files in two different formats. Both requests use the default US English voice, en-US_MichaelVoice.

1. Issue the following command to synthesize the string "hello world" and produce a WAV file that is named hello_world.wav.
curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: application/json" \
--header "Accept: audio/wav" \
--data '{"text": "hello world"}' \
--output hello_world.wav \
"{url}/v1/synthesize"
2. Issue the following command to synthesize the same text but produce an Ogg file (the default format) that is named hello_world.ogg.
curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: application/json" \
--data '{"text": "hello world"}' \
--output hello_world.ogg \
"{url}/v1/synthesize"


Reply all
Reply to author
Forward
0 new messages