Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Playing sounds (updated)

by haukex (Archbishop)
on Nov 09, 2017 at 16:45 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1203063]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-29 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found