From 3332cb8d397baf0cd79435ea72af418959732adf Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 4 Oct 2022 20:48:30 -0400 Subject: [PATCH] Improvements to the clipboard translator. --- speech/clipboard_translator.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/speech/clipboard_translator.sh b/speech/clipboard_translator.sh index eab5879..c5c9b20 100755 --- a/speech/clipboard_translator.sh +++ b/speech/clipboard_translator.sh @@ -20,9 +20,14 @@ while : ; do if [[ "${#newText}" -lt 1 ]]; then continue fi + if [[ "${newText}" =~ ^[0-9A-Za-z[:space:][:punct:]]+$ ]]; then + spd-say "$newText" + echo "" | xclip -d "${DISPLAY:-:0}" -selection clipboard 2> /dev/null + continue + fi export newText - translatedText="$(awk -v originalText="${newText}" 'BEGIN { exitCode = 1; FS = "\\)==:\\[" } - $1~originalText { print $2; exitCode = 0; exit} + translatedText="$(awk -v originalText="${newText})==:" 'BEGIN { exitCode = 1; FS = "\\)==:\\[" } + $0~originalText { print $2; exitCode = 0; exit} END { exit exitCode }' "$dictionaryFile")" if [[ "${#translatedText}" -ge 1 ]]; then spd-say "$translatedText" @@ -30,7 +35,7 @@ while : ; do continue fi translatedText="$(trans -b -- "$newText")" - if [[ "${newText}" != "${translatedText}" ]]; then + if ! [[ "${newText}" =~ ^[0-9[:punct:]]+$ ]]; then echo "${newText})==:[${translatedText}" >> "$dictionaryFile" fi spd-say "$translatedText"