Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Playing sounds (updated)

by haukex (Abbot)
on Nov 09, 2017 at 16:45 UTC ( #1203063=note: print w/replies, xml ) Need Help??

in reply to Playing sounds

which exec() a system tool for playing sounds (afplay, on the Mac). But that's quite clumsy, system-dependent,

Unfortunately, any solution that runs an external command will most likely be system-dependent. Even without looking at Audio::Play::MPG123, I strongly suspect based on the error message that it's also just trying to run an external command. Update: After having looked into this a little more, let me rewrite that paragraph. Calling an external program of course feels a little clunky and inelegant, but at the moment I am not aware of cross-platform Perl modules for playing audio that don't make use of any external tools (perhaps I've just overlooked them, if someone else knows of one, please share - Update 3: see Discipulus's and zentara's comments about SDL here). So perhaps calling an external program is not such a bad choice, if you can run it in the background and control its execution. Audio::Play::MPG123 uses mpg123, which like SoX below also says it is cross-platform, so perhaps you just don't have it installed (Update 2: as 1nickt also pointed out in the meantime). Instead of that module, you can also use the solution I linked to below.

Perhaps this will help in being a small piece in your puzzle: I showed some working code how to run a program that plays a sound while your script keeps running, and how to interrupt playback, using IPC::Run at Re^5: Killing a child process (the rest of the thread may be an interesting read too). The script uses the play tool from SoX, which according to its website is available for *NIX including Mac OS X, as well as Windows.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1203063]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-07-20 18:38 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (439 votes). Check out past polls.