Skip to content

Instantly share code, notes, and snippets.

@wyattearp
Last active September 2, 2025 18:07
Show Gist options
  • Select an option

  • Save wyattearp/314294d553d2285a0ad6483483c658de to your computer and use it in GitHub Desktop.

Select an option

Save wyattearp/314294d553d2285a0ad6483483c658de to your computer and use it in GitHub Desktop.
bash morse code bell dinger because of AI
#!/bin/bash
# NOTE: this is probably done somewhere else, I just don't know where - WRN.
# Morse code mapping
declare -A morse_code
morse_code=(
[A]=".-"
[B]="-..."
[C]="-.-."
[D]="-.."
[E]="."
[F]="..-."
[G]="--."
[H]="...."
[I]=".."
[J]=".---"
[K]="-.-"
[L]=".-.."
[M]="--"
[N]="-."
[O]="---"
[P]=".--."
[Q]="--.-"
[R]=".-."
[S]="..."
[T]="-"
[U]="..-"
[V]="...-"
[W]=".--"
[X]="-..-"
[Y]="-.--"
[Z]="--.."
[0]="-----"
[1]=".----"
[2]="..---"
[3]="...--"
[4]="....-"
[5]="....."
[6]="-...."
[7]="--..."
[8]="---.."
[9]="----."
)
# Function to play Morse code sound
play_morse() {
for char in $(echo "$1" | tr -d '\n' | fold -w1); do
code=${morse_code[$char]}
if [[ $code ]]; then
for symbol in $(echo "$code" | fold -w1); do
if [[ $symbol == "." ]]; then
echo -e "\a" # Short beep
elif [[ $symbol == "-" ]]; then
echo -e "\a"; sleep 1 # Long beep with sleep
fi
sleep 0.5 # Space between symbols
done
sleep 1 # Space between letters
fi
done
}
# Read input from the pipe
while IFS= read -r line; do
play_morse "$line"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment