-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclipboard_ocr_tts_ocr_and_text2.sh
More file actions
executable file
·37 lines (32 loc) · 1.33 KB
/
clipboard_ocr_tts_ocr_and_text2.sh
File metadata and controls
executable file
·37 lines (32 loc) · 1.33 KB
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
31
32
33
34
35
36
#!/bin/bash
# this script is able to read stuff put to the clipboard in text and images (which will be OCR'ed using tesseract).
# It is inteded to be used with ocular and cbz/r files where you can easily select areas and copy them to the clipboard...
LAST_HASH=""
echo "[INFO] Clipwatcher gestartet..."
while true; do
# Versuche, Text aus Zwischenablage zu holen
TEXT=$(xclip -selection clipboard -o 2>/dev/null)
if [[ -n "$TEXT" ]]; then
HASH=$(echo "$TEXT" | sha256sum | awk '{print $1}')
if [ "$HASH" != "$LAST_HASH" ]; then
LAST_HASH="$HASH"
echo "[TEXT] $TEXT"
CLEAN=$(echo "$TEXT" | tr '[:upper:]' '[:lower:]')
espeak "$CLEAN"
fi
else
# Kein Text? Dann prüfen, ob Bild vorhanden ist
if xclip -selection clipboard -t image/png -o > /tmp/clipwatch_img.png 2>/dev/null; then
HASH=$(sha256sum /tmp/clipwatch_img.png | awk '{print $1}')
if [ "$HASH" != "$LAST_HASH" ]; then
LAST_HASH="$HASH"
echo "[INFO] OCR läuft..."
OCRTEXT=$(tesseract /tmp/clipwatch_img.png stdout -l deu 2>/dev/null)
echo "[OCR] $OCRTEXT"
CLEAN=$(echo "$OCRTEXT" | tr '[:upper:]' '[:lower:]')
espeak "$CLEAN"
fi
fi
fi
sleep 2
done