Play a wave file in linux

19,410

Solution 1

The problem is, there's not really a Linux sound API. There's ALSA and OSSv4 for hardware access, but if you use either API directly, you will likely be fighting a mixing daemon, such as PulseAudio, for access to the sound device.

You may be best off using something like libao or PortAudio.

Solution 2

I would use aplay, which is part of the ALSA system itself.

$aplay a.wav

Links: (Wikipedia) (aplay man page)

Since PusleAudio is built over ALSA, it will work on PulseAudio systems, too.

Solution 3

cat mywav.wav > /dev/dsp

so i guess write to that file with a wav file ?

see here

Share:
19,410
mbac32768
Author by

mbac32768

Updated on June 04, 2022

Comments

  • mbac32768
    mbac32768 almost 2 years

    What is the most portable way to play a wave file in Linux? I'd like this to succeed even if the user doesn't have particularly nice sound libraries installed (assume libc is installed and the user has sound configured, but nothing else).

    Preferably, the method I use to blocks until the sound finishes playing and also avoids the overhead of launching a whole separate utility.