Last active
January 2, 2017 05:02
-
-
Save mrwm/c0be883226cd07134a5f2c395a863f32 to your computer and use it in GitHub Desktop.
Voice Recognition for the Raspberry Pi (STT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: ./speech2txt-bing.sh | |
# Record and send audio file through Bing speech recognition API. | |
# | |
# The original script can be found here: | |
# https://stackoverflow.com/questions/38139809/408-request-timed-out-microsoft-speech-to-text/41111609#41111609 | |
# | |
SUBSCRIPTION_KEY=<ENTER_SUBSCRIPTION_KEY> | |
LOCALE=en-US | |
SCENARIOS=ulm | |
SAMPLERATE=8000 | |
CODEC=audio/pcm | |
TARGET_FILE=/tmp/out.wav | |
INSTANCE_ID=`uuidgen` # random GUID for instance | |
REQUEST_ID=`uuidgen` # random GUID for request | |
APPID=D4D52672-91D7-4C74-8AD8-42B1D98141A5 # APPID for Bing Speechrec API, don't change | |
DEVICE_OS=linux # arbitraty | |
FORMAT=json | |
AUTH_TOKEN=`curl -s -X POST "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Content-type: application/x-www-form-urlencoded" -H "Content-Length: 0" -H "Ocp-Apim-Subscription-Key: ${SUBSCRIPTION_KEY}"` | |
clear | |
echo "###############################" | |
echo "# Recording for 15 seconds... #" # 15 Seconds maximum | |
echo "###############################" | |
arecord -f dat -d 5 -D plughw:CARD=Webcam,DEV=0 $TARGET_FILE | |
clear | |
echo "###############" | |
echo "# You said... #" | |
echo "###############" | |
echo `curl -s -X POST "https://speech.platform.bing.com/recognize?scenarios=${SCENARIOS}&appid=${APPID}&locale=${LOCALE}&device.os=${DEVICE_OS}&version=3.0&format=${FORMAT}&instanceid=${INSTANCE_ID}&requestid=${REQUEST_ID}" -H "Authorization: Bearer ${AUTH_TOKEN}" -H "Content-type: audio/wav; codec='${CODEC}'; samplerate=${SAMPLERATE}" --data-binary @${TARGET_FILE} | cut -d"\"" -f18` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment