Read the statement by Michael Teeuw here.
Trouble playing audio file
-
@mZuil can u run this piece of code from a terminal window?
put the code in xxx.js
then
node xxx.jsdoes it work?
-
@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: -
@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 playerCLI means Command Line Interface
I think you should have seen this error
console.log('No suitable audio player could be found - exiting.'.red); -
@mZuil none of the players listed in his code and doc are installed on raspberry pi os by default.
-
@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 -
@bugsounet ah yes good catch. I jumped to play()…
move the play() inside the callback on save()
players will be the next problem
-
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
mpg123app withsudo apt-get install mpg123 - I replace your
playlibrary byplay-soundfor better compatibility
Don’t forget to install this librarynpm install play-sound - You can see manual of
play-soundlibrary there
- You need to install
-
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? -
I am writing this code in the node_helper file
-
@mZuil post your part of module code, I have do see what you have done ;)
-
@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: -
@mZuil It’s better to add
MagicMirror forumand not me, Thanks :)
because my signature says :I am not a reference in this forumIn all case i’m glade that works for you.
Happy use,
@bugsounet
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login