Automatically end each command in terminal with a different message or sound

Create a script and save it somewhere which contains your lines and the logic to choose a random line from your array and calling speech command on that line:

array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=${array[$RANDOM % ${#array[@]}]}
speech "$line"

Then in your .bashrc or .profile set PROMPT_COMMAND:

PROMPT_COMMAND="bash $HOME/PATH/TO/myscript.sh"

Just replace the speech with echo to get a messge instead of the voice.


Later Edit Tutorial:

Thanks to Ravexina's answer above, now the problem is solved and the solution works fantastically. I will give step-by-step instructions below, for the other people interested to make it work in Ubuntu 18.04

1. Install SVOX pico2wave package:

sudo apt-get install libttspico0 libttspico-utils libttspico-data libsox-fmt-mp3

2. Create the speech script

cd ~/scripts
gedit speech

and put this content inside, inserting the correct user in the path:

#!/bin/bash
pico2wave -l=en-US -w=/home/user/test.wav "$1"
aplay -q ~/test.wav
rm /home/user/test.wav

save and exit.

3. Create the shell_speech.sh script as indicated by Ravexina above:

gedit shell_speech
array[0]="Shields at 90%"
array[1]="Engaging proton overdrive"
array[2]="Autopilot disengaged"
array[3]="Targetting solution available"
array[4]="Alert. Incoming missile."
array[5]="Deploying countermeasures."
array[6]="Firing torpedoes."
array[7]="Engaging auto-cannon."
array[8]="Severe damage on deck 17. Sealing off."
array[9]="Deploying repair droids to deck 17."

line=${array[$RANDOM % ${#array[@]}]}
speech "$line"

save and exit.

4. Make the scripts executable and add their directory to PATH so that they could be called from everywhere:

chmod u+x ~/scripts/bin/speech
chmod u+x ~/scripts/bin/shell_speech
export PATH=$PATH:~/scripts

5. Modify .bashrc

gedit ~/.bashrc

add the following line:

PROMPT_COMMAND="bash shell_speech"

save and close

Note: you can add as many new lines as you want in the array in ~/scripts/bin/shell_speech