MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.20.0 is available! For more information about this release, check out this topic.

    UNSOLVED Trouble playing audio file

    Troubleshooting
    3
    15
    203
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mZuil last edited by

      Hello everybody, I am currently having some issues playing an mp3 or wav file.
      So far I have tried the following packages in the node_helper but none seem to work:
      play
      a-play
      play-sound
      sound-play
      play-audio
      node-aplay
      child-proccess executing cvlc command

      Some of them give errors and the others do not produce any sound.

      I am asking for help over here since I have been working the last couple of days and I could really use some help.

      Thank you in advance! 😃

      S 1 Reply Last reply Reply Quote 0
      • S
        sdetweil @mZuil last edited by

        @mZuil if u bring up YouTube do you get audio?

        my Ubuntu has lost access to my sound device
        . haven’t figured that out yet

        Sam

        Create a working config
        How to add modules

        M 1 Reply Last reply Reply Quote 0
        • M
          mZuil @sdetweil last edited by

          @sdetweil Yeah, the monitor I use has speakers and I have tried to reproduce YouTube and even this mp3 o wav file without the Magic Mirror started and it works, but when I call some functions to execute the audio with the Magic Mirror it doesn’t work. I am generating this audio with gtts and I don’t know if the problem is because those two actions are executed at the same time:

          const gTTS = require('gtts');
          var play = require('play').Play();
          var gtts = new gTTS('text to speak', 'es-es');
          gtts.save('/tmp/hello.wav', function (err, result) {
            if(err) { throw new Error(err) }
            console.log('Success! Open file /tmp/hello.mp3 to hear result.');
          });
          play.sound('/tmp/hello.wav');
          

          The code below is one of the many attempts I have tried 😞
          Thanks for the response!

          S 1 Reply Last reply Reply Quote 0
          • S
            sdetweil @mZuil last edited by

            @mZuil can u run this piece of code from a terminal window?

            put the code in xxx.js

            then
            node xxx.js

            does it work?

            Sam

            Create a working config
            How to add modules

            M 1 Reply Last reply Reply Quote 0
            • M
              mZuil @sdetweil last edited by

              @sdetweil Sorry, I couldn’t try it before.
              It doesn’t work 😞 I am a beginner and I don’t understand well what is happening, could you help me, please? 😢

              S 2 Replies Last reply Reply Quote 0
              • S
                sdetweil @mZuil last edited by sdetweil

                @mZuil what does the play() library say about sound output configuration?

                https://github.com/Marak/play.js#readme
                requirements:

                One of the CLI based audio player
                

                CLI means Command Line Interface

                I think you should have seen this error

                      console.log('No suitable audio player could be found - exiting.'.red);
                

                Sam

                Create a working config
                How to add modules

                1 Reply Last reply Reply Quote 0
                • S
                  sdetweil @mZuil last edited by

                  @mZuil none of the players listed in his code and doc are installed on raspberry pi os by default.

                  Sam

                  Create a working config
                  How to add modules

                  B 1 Reply Last reply Reply Quote 0
                  • B
                    bugsounet @sdetweil last edited by

                    @sdetweil the problem is not there…
                    The problem is you can’t play a file when it’s not fully created!

                    2 solutions:
                    Make a promise
                    Or play the file when the file is created


                    I am not a reference in this forum
                    I am not a magician
                    I'm just a developer

                    Please DON'T ADS ANY of My Modules There !

                    Follow new support of 4th party modules on https://forum.bugsounet.fr

                    S 1 Reply Last reply Reply Quote 1
                    • S
                      sdetweil @bugsounet last edited by sdetweil

                      @bugsounet ah yes good catch. I jumped to play()…

                      move the play() inside the callback on save()

                      players will be the next problem

                      Sam

                      Create a working config
                      How to add modules

                      B 1 Reply Last reply Reply Quote 1
                      • B
                        bugsounet @sdetweil last edited by

                        just because sometime i'm kind... (my favorite sentence!)

                        Try this:

                        const gTTS = require('gtts');
                        var player = require('play-sound')(
                          opts = {
                            player: "mpg123" // use only `mpg123` for playing sounds
                          }
                        );
                        var gtts = new gTTS('text to speak', 'es-es');
                        
                        // main file player 
                        function playing (file) {
                          player.play(file, (err) => {
                            if (err) throw new Error(err)
                          });
                        }
                        
                        gtts.save('/tmp/hello.wav', (err, result) => {
                          if(err) { throw new Error(err) }
                          console.log('Success! start playing result.');
                          // right ! sound file is created let's play it !
                          playing("/tmp/hello.wav");
                        });
                        

                        Notes:

                        • You need to install mpg123 app with sudo apt-get install mpg123
                        • I replace your play library by play-sound for better compatibility
                          Don’t forget to install this library npm install play-sound
                        • You can see manual of play-sound library there

                        I am not a reference in this forum
                        I am not a magician
                        I'm just a developer

                        Please DON'T ADS ANY of My Modules There !

                        Follow new support of 4th party modules on https://forum.bugsounet.fr

                        M 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy