% cat mycommand
#!/bin/zsh
for str in "starting ..." "running ..." "ERROR: had a problem" "stopping"
do
    if [[ $str"${str}" ==~ *ERRORERROR:* ]]
    then
        printecho -r"${str}" -u2>&2 -- $str             # remove "-u2"">&2" to write to stdout
    else
        printecho -r"${str}" -- $str                 # Addappend "-u2"">&2" to write to stderr
    fi
    sleep 2
done
-  regardless of modifying mycommandto send output to stdout, stderr or a mix of stdout/stderr ...
-  in my system I hear ERROR <pause> had a problemover my speakers as the lineERROR: had a problemwas printed to the terminal
- tee /dev/tty- insures all data coming in on stdout is copied to the terminal at the same time asbefore being piped to- grep
- 2>&1- insures all data coming in on stderr is redirected to stdout (which means stderr is also routed through the- tee /dev/tty | grep ... | espeakpipeline)
- grepis used to extract just the lines we wish to pass to- espeak; if looking for multiple strings, you can use- grep -e '^string1' -e '^string2'or switch you'll likely need to enable extended regexp which has an alternation operatorregex support (eg,- grep -E '^(string1|string2...)').
- --line-bufferedis a- GNU grepextension that insures we hear the- espeakoutput at the same time as we see the- ERROR:line
-  OP can install espeakviasudo apt install espeak
-  OP can replace espeakwith whatever sound producing program they wish
 This solution (above) will speak the entire line when said line starts withcontains the string ERROR^ERROR:.
 Speaking just the word error or warning for each occurrence ofwhen there's a case insensitive match on the strings ERROR and/or Warning in the line:
./mycommand 1> >(tee /dev/tty | grep -oi -E --line-buffered 'ERROR|WARNING''(ERROR|WARNING)' | espeak) 2>&1
 
                