#!/bin/bash # Pronounce a word using English audio from dictionary.cambridge.org # # Copyright (C) 2019 Mike Gerwitz # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # This script requires wget for scraping and mpv for playback. Please # consider your privacy---if you do not want to leak the words you are # looking up, prefix this command with `torify' to proxy through Tor. # # A suggestd improvement to this script to anyone who may want to do so: # derive region and language from $LANG environment variables. ## which mpv &>/dev/null || { echo 'missing mpv' >&2 exit 1 } declare -r name=$( basename "$0" ) declare -r www=${PRONOUNCE_WWW:-https://dictionary.cambridge.org/} declare -r region=${PRONOUNCE_REGION:-us} declare -r lang=${PRONOUNCE_LANG:-english} usage() { cat <. EOU exit 64 # EX_USAGE } main() { test $# -gt 0 || usage local -r word=$1 local -r ogg_url=$( wget -O- "$www/$region/pronunciation/$lang/$word" \ | grep -o 'data-src-ogg="[^"]\+"' \ | grep "$region"_pron_ogg \ | head -n1 \ | cut -d\" -f2 ) test -n "$ogg_url" || { echo "US OGG not found for \`$word'" >&2 exit 1 } mpv -vo null "$www/$ogg_url" } main "$@"