]> Sergey Matveev's repositories - nnn.git/commitdiff
Add text2speech plugin
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 22 Jun 2019 19:40:14 +0000 (01:10 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 22 Jun 2019 20:13:52 +0000 (01:43 +0530)
plugins/README.md
plugins/readit [new file with mode: 0755]

index ecb8519ef6f804db2d8c41b44170b9b709db6c0f..f969666d5d68767d96bade93172dae2871c76b2f 100644 (file)
@@ -18,6 +18,7 @@
 | pdfview | sh | pdftotext/mupdf-tools | View PDF file in `$PAGER` |
 | picker | sh | nnn | Pick files and pipe the newline-separated list to another utility |
 | pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme |
+| readit | sh | pdftotext,<br>pico2wave, mpv | Read a PDF or text file aloud |
 | ringtone | sh | date, ffmpeg | Create a variable bitrate mp3 ringtone from file |
 | splitjoin | sh | split, cat | Split file or join selection |
 | sxiv | sh | sxiv | Browse images in a dir in sxiv, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))|
diff --git a/plugins/readit b/plugins/readit
new file mode 100755 (executable)
index 0000000..b997235
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env sh
+
+# Description: Read a text or PDF file in British English
+#
+# Shell: POSIX compliant
+# Author: Arun Prakash Jana
+
+if ! [ -z "$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 "$(cat "$tmpf".txt | tr '\n' ' ')"
+
+        rm "$tmpf".txt
+    else
+        pico2wave -w "$tmpf".wav -l en-GB "$(cat "$1" | tr '\n' ' ')"
+    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