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', '/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:

Discard all samples (playback) or generate zero samples (capture)
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.

Thank you for you advice.

  • May it be a permissions issue? Maybe django or gunicorn are running as root? – cabreracanal Oct 19 '13 at 17:13

It was a permissions issue. I was thinking that my gunicorn user was "pi" all this time, but it is not! I'm using supervisor with gunicorn and the user is defined in supervisor's config.

I checked /etc/supervisor/conf.d/your_project.conf and changed the user to pi (pi is an audio user).

Now I can play the sound with a simple click from my web page.

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.