Created
December 13, 2016 05:40
-
-
Save Glavin001/bfd8bcb3b721ea728ce99391baf3a072 to your computer and use it in GitHub Desktop.
Convert Google Document to an "Audiobook" with Mac's built-in text-to-speech!
This file contains hidden or 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
#/usr/bin/env bash | |
# Configure | |
DOC_NAME="DOC NAME" | |
DOC_ID="DOC ID" | |
TOKEN="MY_TOKEN" | |
READ_SPEED=170; | |
URL="https://docs.google.com/document/export?format=txt&id=${DOC_ID}&token=${TOKEN}, https://docs.google.com/document/d/${DOC_ID}/edit" | |
DOWNLOAD_DIR="audio_books" | |
RAW_DOWNLOAD_PATH="${DOWNLOAD_DIR}/${DOC_NAME}.txt"; | |
CLEAN_PATH="${DOWNLOAD_DIR}/${DOC_NAME}-clean.txt"; | |
AUDIO_PATH="${DOWNLOAD_DIR}/${DOC_NAME}.m4a"; | |
mkdir -p "$DOWNLOAD_DIR" | |
wget --quiet "$URL" -O "$RAW_DOWNLOAD_PATH" | |
vim "$RAW_DOWNLOAD_PATH" | |
node -e " | |
// Dependencies | |
var fs = require('fs'); | |
// Configure | |
var rawPath = process.argv[1]; | |
var cleanPath = process.argv[2]; | |
// Read file | |
var text = fs.readFileSync(rawPath).toString(); | |
// Clean | |
console.log('Read ' + text.split('\n').length + ' lines'); | |
cleanText = text.split('\n') | |
.map((line) => line.replace(/(?:https?|ftp):\/\/[\n\S]+/g, 'URL')) | |
.map((line) => line.replace('etc', 'et cetera')) | |
.map((line) => line.replace(/^to-do.*$/img, '')) | |
.map((line) => line.replace(/^https?\:.*$/img, '')) | |
.map((line) => line.replace(/^.*\.{png,jpg}$/img, 'Image')) | |
.map((line) => line.trim()) | |
.filter((line) => line.length > 0) | |
.map((line) => (/^.*[^a-zA-Z0-9 ]+$/g).test(line) ? line : line + '.' ) | |
.join('\n'); | |
// Save clean file | |
fs.writeFileSync(cleanPath, cleanText); | |
console.log('Write ' + cleanText.split('\n').length + ' lines'); | |
console.log('Saved to', cleanPath); | |
" "$RAW_DOWNLOAD_PATH" "$CLEAN_PATH" | |
say -v "Ava" -f "$CLEAN_PATH" -r $READ_SPEED -o "$AUDIO_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment