software/hoardy-web/./tool/script/hoardy-web-spd-say

Passively capture, archive, and hoard your web browsing history, including the contents of the pages you visit, for later offline viewing, mirroring, and/or indexing. Your own personal private Wayback Machine that can also archive HTTP POST requests and responses, as well as most other HTTP-level data.

Files

Raw Source

Contents

#!/usr/bin/env bash

usage() {
    cat << EOF
usage: $0 [--help] [--dry-run] [-s pattern] [-e pattern] [WRRFILE ...]

Feed (a part of) an HTML document containted in a given WRR file to a text-to-speech (TTS) engine.

This depends on \`pandoc\`, \`sed\`, and \`spd-say\` of \`speech-dispatcher\`.

The latter of which is a speech server that provides a single common API for whole lot of different TTS engines.
Configuring your \`speech-dispatcher\` is out of scope of this script, look it up elsewhere.

# Options:

  --help                print this message and exit

  -s PATTER, --start PATTERN
                        start speaking starting from this PATTERN

  -e PATTER, --end PATTERN
                        stop speaking at this PATTERN

  --dry-run             just print the text that would be fed to the TTS to
                        stdout, without actually running \`spd-say\`

# Note:

\`--start\` and \`--end\` run \`sed -n "\$start,$end p"\` and similar commands internally.
Which is why see \`man 1 sed\` for more info about PATTERN syntax.

# Examples:

- Feed the whole document to the TTS:

  $0 path/to/wrr/file/containing/html.wrr

- Skip first 5 lines, then feed the next 100 lines to the TTS:

  $0 -s 5 -e +100 path/to/wrr/file/containing/html.wrr

- Start speaking aloud starting from the first \`<hr>\` element:

  $0 -s "/^-----/" path/to/wrr/file/containing/html.wrr

- Feed everything between the first two \`<hr>\` elements to the TTS:

  $0 -s "/^-----/" -e "/^-----/" path/to/wrr/file/containing/html.wrr

- Feed everything between the first "Chapter" header and the following "Next Chapter" link to the TTS:

  $0 -s "/^Chapter [0-9]/" -e "/^Next Chapter/" path/to/wrr/file/containing/html.wrr

EOF
}

start=0
end='$'
dry=
while (($# > 0)); do
    case "$1" in
    --help) usage; exit 0 ;;
    -s|--start) start="$2"; shift ;;
    -e|--end) end="$2"; shift ;;
    --dry-run) dry=1 ;;
    *) break ;;
    esac
    shift
done

play() {
    { [[ "$start" != '0' ]] && sed -n "$start"',$ p' || cat - ; } | \
    { [[ "$end" != '$' ]] && sed "$end"',$ d' || cat - ; } | \
    {
        if [[ -z "$dry" ]]; then
            spd-say -ew
        else
            cat
        fi
    }
}

# we need this so that other messages don't get interrupted on success
ok=
# stop talking immediately on interrupt
trap '[[ -z "$ok" ]] && spd-say -S' 0

for file in "$@"; do
    echo "reading $file aloud from $start to $end"
    hoardy-web run -- pandoc -f html -t plain "$file" | play
done
ok=1