12

I'm working through a Linux textbook, and it's telling me about devices. It says that if I send the appropriate output to /dev/dsp, then it will play a sound. The example is cat file.wav > /dev/dsp, where file.wav is just any .wav file.

When I do this I get permission denied. If I run this with sudo I still get permission denied. If I su first, no sound plays.

Why do I get permission denied with sudo? Why does no sound play even with su?

  • 1
    Make sure your user is in the audio group. – Carl Groner Dec 4 '13 at 22:10
  • You might also need to ensure that your wav file is raw audio - not all .wav files are raw. – Drake Clarris Dec 4 '13 at 22:27
  • @DrakeClarris, that would cause noise to be output, not a permission denied error. – cjm Dec 4 '13 at 22:56
  • @cjm I was thinking more of the silence when playing using su – Drake Clarris Dec 5 '13 at 16:51
14

/dev/dsp is part of OSS, which hasn't been part of the Linux kernel in... a very long time. It has long been supplanted by ALSA, which uses different devices, different programs, and a different API.

There is an emulation layer module though. If it is available then loading the snd-pcm-oss module will enable you to use the PCM devices for OSS such as /dev/dsp.

Or just stick to piping data to aplay or paplay instead.

  • 2
    sudo modprobe snd-pcm-oss works on my ubuntu to load that module. I get a /dev/dsp1 and a /dev/dsp2 out of this. – Veda Mar 14 '17 at 8:25
9

If I run this with sudo I still get permission denied.

By this statement, it sounds like you are trying a command like:

sudo cat file.wav > /dev/dsp

The reason you continue to get "permission denied" is that your shell first tries to open the /dev/dsp device for output, before running the command (which is sudo). To have the shell open the redirection with root privileges, you would have to do something like:

sudo sh -c 'cat file.wav > /dev/dsp'
6

Out of date book, as noted.
So to make the examples work with more modern linux, where it says something like

cat music.wav > /dev/dsp

change it to:

cat music.wav | aplay

And you've just done your first porting of code! Win! Feel free to send the book author patches. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.