From OP's comments it sounds like all mycommand output is going to stderr ... maybe. OP has also clarified that mycommand is writing directly to the log file.
I'm going to assume we don't know, for sure, if output is going to stdout, stderr or a mix.
For demo purposes I'll use the following:
% cat mycommand
#!/bin/zsh
for str in "starting ..." "running ..." "ERROR: had a problem" "stopping"
do
if [[ "${str}" =~ ERROR: ]]
then
echo "${str}" >&2 # remove ">&2" to write to stdout
else
echo "${str}" # append ">&2" to write to stderr
fi
sleep 2
done
One approach benefiting from zsh's ability to use multiple redirections:
% ./mycommand 1> >(tee /dev/tty | grep --line-buffered '^ERROR:' | espeak) 2>&1
starting ...
running ...
ERROR: had a problem # espeak output heard on speakers
stopping
NOTES:
- 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 --line-bufferedis aGNU grepextension that insures we hear theespeakoutput at the same time as we see theERROR:line- OP can install
espeakviasudo apt install espeak - OP can replace
espeakwith whatever sound producing program they wish