Search code examples
pythonplaysoundpython-playsound

How to change volume of Python's playsound


I'm using playsound library to successfully play an mp3 file:

import playsound
playsound.playsound('audio.mp3')

However, it's too loud relative to the other sound sources on my computer. How do I decrease the volume?

I don't wish to use pydub or pygame since I'm having other issues with those two libraries.


Solution

  • Since there doesn't seems to be any documentation about this functionality, the only way to me is to change the application volume.

    Changing the application volume could technically be done with ctypes.

    However, while I'm not aware of the issue pygame poses, it seems quite trivial to implement only as a mixer:

    import pygame
    pygame.init()
    pygame.mixer.init()
    sound = pygame.mixer.Sound("path/to/file")
    sound.set_volume(0.5)
    sound.play()