Skip to content

Instantly share code, notes, and snippets.

@johan-bjareholt
Created December 8, 2015 15:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save johan-bjareholt/5a28e3742fb5ce0f32a3 to your computer and use it in GitHub Desktop.
Save johan-bjareholt/5a28e3742fb5ce0f32a3 to your computer and use it in GitHub Desktop.
Speech recognition on linux using Google Speech API
#!/bin/bash
# Record from mic
arecord -d 3 -f cd -t wav -r 16000 -c 1 -D pulse test.wav
# Get record volume
sox test.wav -n stats -s 16 2>&1 | grep 'Max level' | awk '{print $3}'
# Convert to flac for smaller footprint
flac -f test.wav
# Google speech recognition
LANG=en-us
AGENT='Mozilla/5.0'
APIKEY='AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw'
curl -X POST \
--data-binary @'test.flac' \
--user-agent $AGENT \
--header 'Content-Type: audio/x-flac; rate=16000;' \
"https://www.google.com/speech-api/v2/recognize?output=json&lang=en&key="$APIKEY"&client="$AGENT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment