buling
Posts: 18
Joined: Thu Oct 04, 2012 7:11 am

pygame set_volume no longer working on raspberry pi

Wed Feb 21, 2018 10:04 am

So Im trying to set the volume of a sound in pygame, playing it on the 3.5mm output.
The sound plays perfectly, but i cant change the volume of the sound. This has worked in the past.

Im essentially doing this:

Code: Select all

pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
self._snd = pygame.mixer.Sound("sound file path")
self.channel = pygame.mixer.find_channel()
self.channel.set_volume(0.1)
self._snd.set_volume(0.1)
print self._snd.get_volume()
self.channel.play(self._snd, 1, 0])
print self._snd.get_volume()
The "print self._snd.get_volume()" row prints the correct volume, but it plays at full volume.
Does anyone have any ideas?

version: Linux UA 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux

User avatar
rados-dataplicity
Posts: 40
Joined: Wed Aug 03, 2016 11:56 am
Location: UK
Contact: Website Facebook Twitter

Re: pygame set_volume no longer working on raspberry pi

Wed Feb 21, 2018 10:22 am

I haven't used pygame before but this looks like you're changing the state of two different objects, _snd and channel whereas maybe you have to change the state of just one of them
I tinker around with Raspberry Pis daily and make sure that people can easily access theirs remotely.

Community outreach @ dataplicity.com

buling
Posts: 18
Joined: Thu Oct 04, 2012 7:11 am

Re: pygame set_volume no longer working on raspberry pi

Wed Feb 21, 2018 10:26 am

Thanks, but according to the docs the result should be 0.1*0.1 in that case.
I've tried setting them one at a time, both, and none. Makes no difference.

The sound obj reports having a low volume set, but still plays at max.

Return to “Python”