3

I have a function that has my EV3 speak

speak(){ espeak -a 200 -s 130 -v la --stdout "$@" | aplay; }

it works by simply

speak "Say this"

I want it to say the contents of a file, so I have this

printf '%b\n' "$(cat joyPhrase)"

How do get the output from the printf into the quotes for speak?

OrigamiEye
  • 209
  • 4
  • 12
  • 1
    Are there control characters in `joyPhrase` (I assume so because of the `%b` you're using)? Can you share a sample `joyPhrase` file? –  May 03 '16 at 19:48
  • output of printf command ```Give the person to your right a high five evif hgih a tfel ruoy ot nosrep eht eviG I don't know what %b is for, taking it out made no difference – OrigamiEye May 03 '16 at 20:20

2 Answers2

1

espeak supports using --stdin to read from a pipe, so one option would be to change your function call to use that instead of parameters, and pipe the printf output into your function:

speak(){ espeak -a 200 -s 130 -v la --stdout --stdin | aplay; }
printf '%b\n' "$(cat joyPhrase)" | speak

Or you can pass the output of your other command to speak's parameters, like this (although that's less likely to work if there are control characters):

speak $(printf '%b\n' "$(cat joyPhrase)")
  • echo $(printf...joyPhrase)") shows the current output by the speech is only two syllables and nonsensical. adjust the speak () function like you said and then printf '%b\n' "$(cat joyPhrase)" | speak produce the current length but completely garbled response. – OrigamiEye May 03 '16 at 19:27
  • 2
    why don't you just `speak – don_crissti May 03 '16 at 19:35
  • Thanks for the backticks tip. printf command outputs correctly. I tried flipping the text in joyPhrase in case it read backwards, no luck. – OrigamiEye May 03 '16 at 19:35
1

You can escape the double quotes

printf '%b\n' "\"$(cat joyPhrase)\""

On my machine

$ echo this is a file >> testfile
$ printf '%b\n' "\"$(cat testfile)\""
"this is a file"

Instead of using cat, you can use the redirect:

$ printf '%b\n' "\"$(< testfile)\""
"this is a file"
JayJay
  • 140
  • 3