Skip to content

Instantly share code, notes, and snippets.

@ca4ti
Forked from germanattanasio/stt.sh
Created November 22, 2021 17:21
Show Gist options
  • Save ca4ti/c9fbfe461dd8fe80681822f1e7aa78d3 to your computer and use it in GitHub Desktop.
Save ca4ti/c9fbfe461dd8fe80681822f1e7aa78d3 to your computer and use it in GitHub Desktop.
curl commands to use the Speech to Text service
#!/bin/sh
# This script clears the terminal, call the IBM Watson Speech to Text service.
USERNAME="<SERVICE_USERNAME>"
PASSWORD="<SERVICE_PASSWORD>"
SESSION_ID="<SESSION_ID>" # you will get this after running (1)
# 1. Create a session:
curl -X POST -b cookies.txt -c cookies.txt -u $USERNAME:$PASSWORD -d "{}" "https://stream.watsonplatform.net/speech-to-text/api/v1/sessions"
# This returns you a session URL. Note that the client needs to support cookies for sessions to work.
# 2. GET as follows to fetch the interim transcription results:
curl -b cookies.txt -c cookies.txt -u $USERNAME:$PASSWORD \
"https://stream.watsonplatform.net/speech-to-text/api/v1/sessions/$SESSION_ID/observer_result?interim_results=true"
# This request will wait until the audio is submitted, and then it will return interim results in a timely manner.
# 3. POST the audio to the session recgonize URL, similar to the above examples.
# Here the audio can be sent in realtime, as it is being recorded from the system microphone.
curl -X POST -b cookies.txt -c cookies.txt -u $USERNAME:$PASSWORD \
"https://stream.watsonplatform.net/speech-to-text/api/v1/sessions/$SESSION_ID/recognize?continuous=true" --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked" --data-binary @pcm0003.flac
# At this point you can continue submitting requests and observing interim results.
# 4. When you are done, close the session:
curl -X POST -b cookies.txt -c cookies.txt -u $USERNAME:$PASSWORD \
-X DELETE "https://stream.watsonplatform.net/speech-to-text/api/v1/sessions/$SESSION_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment