Jouke has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
For the project I'm working on (see my homenode for details), I need a way to play sounds on both Win32 and Unix platforms. Currently I'm using system("play", $soundfile), but since I don't know about any 'play'-like command on Win32 systems, I'm looking for a more portable, more Perl-way to do it.

Currently all soundfiles are .WAV, but I don't mind changing it into MP3 or AU format if that is neccesary for a good solution.

Jouke Visser, Perl 'Adept'

Replies are listed 'Best First'.
Re: Portable solution for playing sound?
by arhuman (Vicar) on Mar 05, 2001 at 14:57 UTC
    AFAIK, there's no clean perl way to play sound on Windows and Unix.
    (But I'm not an expert!)

    So a acceptable strategy could be to use a cross-platform sound player.
    (A quick search gave me :Sox not really a player but rather a portable sound library)

    Or put the path/name of the sound player as an OS dependant variable...
    (Ok this one is rather dirty, but SO simple)
    There are a lot of OS-specific simple command line player..

    A CPAN search seems to suggest Audio-SoundFile-0.14
    (based on libsndfile which is a portable sound lib too)
Re: Portable solution for playing sound?
by Anonymous Monk on Mar 05, 2001 at 18:16 UTC
    Personally, I've been pretty happy with XAudio. It's a multi-platform, asynchronous, proprietary (free for personal use), mp3 playing library. There is, of course, a C library (SDK) and someone has already written MPEG::MP3Play to interface with it. Alternatively, you can just download the xaudio player and use the 'rxaudio' binary to control a player via an IPC connection.

    I've found it to be very stable (the library and the perl module), it keeps playing in many instances where mpg123 would die in buffer handling, and it offers a fairly clean and tidy interface to the player as well as a decent amount of state information while it's playing.

      Thanx for the link to XAudio, but MPEG::MP3Play does not support Win32 (according to its docs), so that's no improvement to my current situation

      Jouke Visser, Perl 'Adept'
Re: Portable solution for playing sound?
by davemabe (Monk) on Mar 05, 2001 at 18:55 UTC
    Check out Misterhouse. It is a very cool project for cross platform home automation in perl. There is code in there for playing mp3's and text to speech across platforms. It would definitely be worth a look.

    Dave
      Cool project indeed. Problem is though, that from what I read at the site, it uses all kinds of 3rd party stuff on the different platforms (Festival on Unix, M$ solution on Win32), and I'm looking for a neat solution with only 1 interface on different platforms.

      Jouke Visser, Perl 'Adept'