File: pdfread

package info (click to toggle)
nnn 5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,184 kB
  • sloc: ansic: 11,902; sh: 3,585; makefile: 512; cpp: 80; python: 31; csh: 2
file content (30 lines) | stat: -rwxr-xr-x 737 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env sh

# Description: Read a text or PDF file in British English
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana

if [ -n "$1" ]; then
    tmpf="$(basename "$1")"
    tmpf="${TMPDIR:-/tmp}"/"${tmpf%.*}"

    if [ "$(head -c 4 "$1")" = "%PDF" ]; then
        # Convert using pdftotext
        pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' > "$tmpf".txt

        pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$tmpf".txt)"

        rm -- "$tmpf".txt
    else
        pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$1")"
    fi

    # to jump around and note the time
    mpv "$tmpf".wav

    # flat read but better quality
    # play -qV0 "$tmpf".wav treble 2 gain -l 2

    rm -- "$tmpf".wav
fi