Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.

Morse 2


#!/bin/bash
# Filename: morse2.sh
# Version.: 03102017
# Author..: robz
# Enter words hear morse.

trap 'kill -9 $pid 2>/dev/null; echo; exit' TERM EXIT

declare -A morse
morse[A]=".-"     morse[B]="-..."   morse[C]="-.-."   morse[D]="-.."
morse[E]="."      morse[F]="..-."   morse[G]="--."    morse[H]="...."
morse[I]=".."     morse[J]=".---"   morse[K]="-.-"    morse[L]=".-.."
morse[M]="--"     morse[N]="-."     morse[O]="---"    morse[P]=".--."
morse[Q]="--.-"   morse[R]=".-."    morse[S]="..."    morse[T]="-"
morse[U]="..-"    morse[V]="...-"   morse[W]=".--"    morse[X]="-..-"
morse[Y]="-.--"   morse[Z]="--.."   morse[1]=".----"  morse[2]="..---"
morse[3]="...--"  morse[4]="....-"  morse[5]="....."  morse[6]="-...."
morse[7]="--..."  morse[8]="---.."  morse[9]="----."  morse[0]="-----"
morse[.]=".-.-.-" morse[,]="--..--" morse[?]="..--.."

while true; do
    read -p "Input a word or sentence: " input
    echo
    while read -n1 character; do
        character="${character^^}"
        if [ "$character" ]; then
            echo -ne " $character\t"
            while read -n1 dotdash; do
                tput bold
                [ "$dotdash" = "." ] && duration="0.2" || duration="0.4"
                echo -n "$dotdash"
                (speaker-test -t sine -f 400 >/dev/null) & pid="$!";\
                sleep "$duration"; kill -9 "$pid"
                tput sgr0
            done < <(echo -n "${morse[$character]}")
            sleep 0.2; echo
        else sleep 0.4; echo
        fi 2> /dev/null
    done < <(echo -n "$input")
    echo
done

No comments: