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"