• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Trouble playing audio file

Scheduled Pinned Locked Moved Unsolved Troubleshooting
15 Posts 3 Posters 3.7k Views 3 Watching
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 Offline
    mZuil @sdetweil
    last edited by Apr 23, 2022, 9:53 AM

    @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? :crying_face:

    S 2 Replies Last reply Apr 23, 2022, 11:07 AM Reply Quote 0
    • S Offline
      sdetweil @mZuil
      last edited by sdetweil Apr 23, 2022, 11:54 AM Apr 23, 2022, 11:07 AM

      @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

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @mZuil
        last edited by Apr 23, 2022, 12:47 PM

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

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        B 1 Reply Last reply Apr 23, 2022, 2:07 PM Reply Quote 0
        • B Offline
          bugsounet Banned @sdetweil
          last edited by Apr 23, 2022, 2:07 PM

          @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

          S 1 Reply Last reply Apr 23, 2022, 2:44 PM Reply Quote 1
          • S Offline
            sdetweil @bugsounet
            last edited by sdetweil Apr 23, 2022, 2:48 PM Apr 23, 2022, 2:44 PM

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

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

            players will be the next problem

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            B 1 Reply Last reply Apr 23, 2022, 7:11 PM Reply Quote 1
            • B Offline
              bugsounet Banned @sdetweil
              last edited by Apr 23, 2022, 7:11 PM

              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
              M 1 Reply Last reply Apr 28, 2022, 7:44 AM Reply Quote 0
              • M Offline
                mZuil @bugsounet
                last edited by Apr 28, 2022, 7:44 AM

                Thanks to both of you!
                I have just tried the code and it works in a js file, but when I try to replicate this code in the MMirror I get the error that opts is not defined. Where do I have to declare opts?

                M 1 Reply Last reply Apr 28, 2022, 7:47 AM Reply Quote 0
                • M Offline
                  mZuil @mZuil
                  last edited by Apr 28, 2022, 7:47 AM

                  I am writing this code in the node_helper file

                  B 1 Reply Last reply Apr 28, 2022, 8:18 AM Reply Quote 0
                  • B Offline
                    bugsounet Banned @mZuil
                    last edited by Apr 28, 2022, 8:18 AM

                    @mZuil post your part of module code, I have do see what you have done ;)

                    M 1 Reply Last reply Apr 28, 2022, 11:16 AM Reply Quote 0
                    • M Offline
                      mZuil @bugsounet
                      last edited by Apr 28, 2022, 11:16 AM

                      @bugsounet It actually works!! :smiling_face_with_smiling_eyes: It happened because I was using the “use strict” directive, but without it, everything works as it should.
                      Wow, guys, you helped me a lot!! I will add you in the acknowledgement section of my final degree project hahaha :hugging_face:

                      B 1 Reply Last reply Apr 28, 2022, 3:16 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        9/15
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy