Skip to content

Instantly share code, notes, and snippets.

@MVoz
Forked from johan-bjareholt/Speech recognition
Created October 4, 2018 17:09
Show Gist options
  • Save MVoz/2a75b39e51268723903d5cca69d107a9 to your computer and use it in GitHub Desktop.
Save MVoz/2a75b39e51268723903d5cca69d107a9 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