#StackBounty: #audio #bluetooth #pygame Why won't pygame play sound over Bluetooth when everything else works?

Bounty: 50

I having trouble getting a program I’ve written using the pygame sound mixer to play sound to work over Bluetooth. The program is able to work correctly over HDMI audio. The Raspberry Pi has no trouble connecting to the Bluetooth headphones, and aplay works just fine to play sound. After I attempt to play sound with pygame, aplay is broken and will not play sound until I do a reboot. Any ideas?

Here is my basic python test program:

simplePyGame.py

import pygame.mixer

pygame.mixer.init(48000, -16, 1, 1024)

sndA = pygame.mixer.Sound("A.wav")

soundChannel1A = pygame.mixer.Channel(1)

soundChannel1A.play(sndA)

Running the program outputs the following:

$ python simplePyGame.py
Traceback (most recent call last):
  File "simplePyGame.py", line 3, in <module>
    pygame.mixer.init(48000, -16, 1, 1024)
pygame.error: Couldn't set hardware audio parameters: Success

Now, using aplay to play a WAV file outputs this error. It doesn’t go away until the Raspberry Pi is restarted.

$ aplay ../20second_sine.wav
Playing WAVE '../20second_sine.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
aplay: set_params:1363: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 16
CHANNELS: 1
RATE: 8000
PERIOD_TIME: (85333 85334)
PERIOD_SIZE: (682 683)
PERIOD_BYTES: (1364 1366)
PERIODS: (5 7)
BUFFER_TIME: 511875
BUFFER_SIZE: NONE
BUFFER_BYTES: 8190
TICK_TIME: 0

Versions:
– Raspbian Stretch (Linux 9)
– Python 2.7.13
– aplay 1.1.3
– pygame 1.9.3
– bluealsa 1.2.0

Full information: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=214901


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.