3

I'm facing a problem with my Raspberry Pi while playing a sound through a web page. The page is built in with Django and is quite simple: you push on a button and a sound is played (a Python script is executed). I tested it on a Debian 7 in a VirtualBox environment successfully, but then I decided to move to my Pi.

Everything went ok but when I click on the "play" button, I receive a 500 error with the following message:

IOError at /alarma/triggerAlarm [Errno Invalid output device (no default output device)] -9996 Request Method:

  GET Request URL: ttp://localhost/alarma/triggerAlarm Django Version:  1.5.4
  Exception Type: **IOError Exception Value: [Errno Invalid output device (no default output device)] -9996 Exception**
  Location: /usr/local/lib/python2.7/dist-packages/pyaudio.py in __init__, line 442 Python   
  Executable:   /usr/bin/python Python Version: 2.7.3 Python Path:
     ['/var/www/webapps/example_django/example',
      '/var/www/webapps/example_django/bin',
      '/usr/local/lib/python2.7/dist-packages',
      '/var/www/webapps/example_django/example', '/usr/lib/python2.7',
      '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk',
      '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload',
      '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7']
      Server time: Sat, 19 Oct 2013 17:39:54 +0200

I tried to play the file by hand in the python console without any problems, but when I try to do it through django it seems it can't.

I think the problem is related with this:

Ouput from aplay -L:

null
Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device

I searched in Google and tried several solutions like create an asound.conf file in the home directory, but none of them worked out. I really don't understand why sound is working from the aplay command and the python shell but no while the python script is excuted by Django.

  • What user is the web server executed as? What are the permissions on the device nodes in /dev/snd/? – CL. Oct 25 '13 at 12:01
  • /dev/snd is set for root user (root:audio), except /dev/snd/by-path which is (root:root). THe server I think is executed as "pi". Maybe this is the problem! – cabreracanal Oct 25 '13 at 12:40
  • What are the permission bits (rwx) on the files, not the directories? – CL. Oct 25 '13 at 14:22
  • Hey, if you're asking about /dev/snd permissions, first I have: "lrwxrwxrwx 1 root root 12 Oct 25 15:17 /dev/snd/by-path/platform-bcm2835_AUD0.0 -> ../controlC0" and for the rest of the /dev/snd nodes (controlC0, pcmC0DCp, seq and timer) the permissions are crw-rw---T – cabreracanal Oct 28 '13 at 6:48
  • Login (or sudo) as pi, and try aplay. – CL. Oct 28 '13 at 21:31
1

A process that wants to play sounds must be able to access the device nodes in /dev/snd/ (and to read the files in /usr/share/alsa/).

In this case, this means that the web server's user must be made a member of the audio group.

  • My webserver is gunicorn and it is executed as pi:pi. pi user belongs to the audio group (grep '^audio' /etc/group shows audio:x:29:pi). I changed permissions recursively (sudo chown -R pi:audio <directories>) for /dev/snd and /usr/share/alsa, but the problem is still there. Do you need any log? – cabreracanal Oct 28 '13 at 19:07
  • You were right. I was thinking that my gunicorn user was pi all this time, but it is not! The problem was with the supervisor config. I checked /etc/supervisor/conf.d/<your_project>.conf (supervisor launches gunicorn) and changed the user to pi (pi was already as an audio user). Now I can play the sound with a simple click from my web page. Thank you. – cabreracanal Oct 31 '13 at 14:01

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.