Search code examples
curlspeech-to-textibm-watsonwatson

Passing URL instead of system path in WATSON speech-to-text api


I made a curl request to the Watson speech-to-text API using an input flac file stored on my system. I used the path of audio/flac file where it is stored on my system. I want to store it somewhere on cloud and use the URL of the audio file to use as my input. Please let me know how to do this. Below is the curl request where I passed input using flac file stored on my system:

curl -X POST -u username:password --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked" --data-binary @/home/rishabh/Desktop/watson/test_file.flac "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true"

In above request the input file path is : /home/rishabh/Desktop/watson/test_file.flac. How to pass this as URL


Solution

  • This isn't possible in the sense that the Watson service downloads the file on your behalf, but it is possible to download and forward the file to Watson in a single command that doesn't save a local copy on your computer:

    curl "https://watson-test-resources.mybluemix.net/resources/weather.flac" | curl -X POST -u "username:password" --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked" --data-binary @- "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true"

    There are a few things to note here:

    1. There are two curl commands. The first fetches the file, the second sends it to Watson.
    2. They are connected with the pipe operator, |
    3. The second curl command is told to accept input from the first via the --data-binary @- flag.