Skip to content

Instantly share code, notes, and snippets.

@rmtbb
Last active May 2, 2024 03:14
Show Gist options
  • Save rmtbb/bf4cb328a9f5a9f538dea319dcaf58ab to your computer and use it in GitHub Desktop.
Save rmtbb/bf4cb328a9f5a9f538dea319dcaf58ab to your computer and use it in GitHub Desktop.
nohup bash -c 'for i in {0..100}; do voice=$(say -v "?" | awk "{print \$1}" | sort -R | head -1); rate=$((50 + RANDOM % 150)); say -v "$voice" -r $rate $i; done' &
@rmtbb
Copy link
Author

rmtbb commented May 2, 2024

Number Counting Prank: Announce numbers 0 through 100 at random voices and speech rates.

to use Number Counting Prank via Terminal:

nohup bash -c 'for i in {0..100}; do voice=$(say -v "?" | awk "{print \$1}" | sort -R | head -1); rate=$((50 + RANDOM % 150)); say -v "$voice" -r $rate $i; done' &

to use Number Counting Prank via curl:

curl -s https://gist.githubusercontent.com/rmtbb/bf4cb328a9f5a9f538dea319dcaf58ab/raw/dcb09c895d1f073bf6e1f5802a5b13d1b71189b7/macNumberPrank.sh | bash

Explanation of the Script

This script is designed to run a sequence in the background of a Unix-like operating system that audibly announces numbers from 0 to 100. Each number is spoken using the say command, with randomly selected voices and varying speech rates. Here's a detailed breakdown of each component:

  1. nohup:

    • nohup stands for "no hang up." It's used to run a command immune to hangups, with output to a non-tty. This ensures the command continues running even if the user logs out or the terminal is closed.
  2. bash -c:

    • This command tells the system to execute the enclosed string as a command using the Bash shell. The -c option allows passing the entire command sequence as a single string.
  3. for i in {0..100}; do ... done:

    • This is a for loop that iterates over the numbers from 0 to 100. Each iteration of the loop executes the commands within the do ... done block.
  4. voice=$(say -v "?" | awk "{print \$1}" | sort -R | head -1);:

    • say -v "?": This command lists all available voices for the say command.
    • awk "{print \$1}": Uses awk to print the first column of the output, which corresponds to the voice names.
    • sort -R: Randomly shuffles the list of voices.
    • head -1: Selects the first entry from the shuffled list, which will be the random voice chosen for that iteration. The selected voice is stored in the variable voice.
  5. rate=$((50 + RANDOM % 150));:

    • This command calculates a random speech rate. RANDOM % 150 produces a random number between 0 and 149, which, when added to 50, results in a speech rate ranging from 50 to 199.
  6. say -v "$voice" -r $rate $i;:

    • Uses the say command with the selected voice ($voice) and the calculated rate ($rate) to announce the current number ($i).
  7. &:

    • This symbol places the command into the background, allowing the terminal to be used for other tasks while the command runs indefinitely.

Overall Function

This script demonstrates an engaging use of the say command, combining it with loops and randomization to create a varied auditory experience. It can serve educational purposes or simply as an entertaining script that showcases Bash scripting capabilities involving text-to-speech functions.

The Antidote: Shut Your Computer Up

to use The Antidote via terminal:

nohup bash -c "ps aux | grep '[s]ay' | awk '{print \$2}' | xargs kill" &

to use The Antidote via curl:

curl -s https://gist.githubusercontent.com/rmtbb/3da43e9f5b03392dbe5d74e09a43f556/raw/38359290144829a7276824a96a778329e3607487/macNumbersPrankAntidote.sh | bash

More Info on the Antidote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment