Using spd-say in a bash script function












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?










share|improve this question





























    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?










    share|improve this question



























      1












      1








      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?










      share|improve this question
















      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?







      bash shell-script audio function text-to-speech






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 20 '18 at 22:35









      Rui F Ribeiro

      41.8k1483142




      41.8k1483142










      asked Oct 9 '16 at 15:06









      lightwinglightwing

      498




      498






















          2 Answers
          2






          active

          oldest

          votes


















          1














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






          share|improve this answer

































            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





            share








            New contributor




            user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f315289%2fusing-spd-say-in-a-bash-script-function%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














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






              share|improve this answer






























                1














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






                share|improve this answer




























                  1












                  1








                  1







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






                  share|improve this answer















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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 4 '16 at 14:05









                  Jeff Schaller

                  44k1161142




                  44k1161142










                  answered Dec 4 '16 at 10:00









                  alagrisalagris

                  465




                  465

























                      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





                      share








                      New contributor




                      user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        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





                        share








                        New contributor




                        user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          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





                          share








                          New contributor




                          user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          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






                          share








                          New contributor




                          user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.








                          share


                          share






                          New contributor




                          user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 1 min ago









                          user344053user344053

                          1




                          1




                          New contributor




                          user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          user344053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f315289%2fusing-spd-say-in-a-bash-script-function%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              宮崎県

                              濃尾地震

                              シテ島