1

I'm sure this is fairly elementary, but I can't figure it out.

My script:

#!/bin/bash
sez ()
{
  echo $1
  spd-say "$1"
}
sez "does this work"
sez "this does work"

What I'm trying to make happen is use spd-say in a function to make the computer talk to me.

The echo portion of my function works. It outputs both lines of text that I feed to it in the expected order. However, the spd-say part doesn't. It only ever says the last line. I'm assuming it's because the second command is "overwriting" the output of the first because it's trying to run them in parallel to the same output. I've tried adding ;wait, &&, and various other things to the end of the sez command, on the next line after, within the function on the spd-say command, etc, but everything I'm trying isn't helping.

What am I doing wrong?

1

I had a similar problem and I found a workaround. Instead of using spd-say I used espeak directly.

2
  • How do you use it directly? – Eric Sebasta Jan 14 at 5:56
  • @EricSebasta Just espeak "some sentence" should be enough – alagris Jan 19 at 17:43
0

spd-say requires a suitable shell environment. cron doesn't execute tasks in your regular shell environment.

You can try changing your script such as in this example:

#!/bin/bash
source $HOME/.profile
sez ()
{
  echo $1
  spd-say "$1"
}
sez "does this work"
sez "this does work"

See also this question for more information: http://unix.stackexchange.com/questions/67940/cron-ignores-variables-defined-in-bashrc-and-bash-profile

1
  • do not work at Ubuntu 20.04 with crontab at user still. – Zagfai Jan 13 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.