python-3.xpycharmlogitechplaysound

playsound plays mp3 file but plays it very quietly


I am trying to get a simple click tone to play on Pycharm2023/Python3.11/Win7. But the audio file, which when I play it by itself (whether by windows media player or VLC) sounds fine, but in the python script it is very faint I can barely hear it.

I got the mp3 file here: https://pixabay.com/sound-effects/search/metronome/ the very first tone.


from playsound import playsound
import time

def print_hi(name):
    while True:
        playsound('click.mp3')
        time.sleep(1)

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')

My speaker is logitech Z407. Same effect if I just run the script on IDLE too.


Solution

  • You could try playing the file with Pygame. Increase the volume to 1.0, then 1.2 and test in small increments.

    #!/usr/bin/env python3
    
    from pygame import mixer 
      
    # Starting the mixer 
    mixer.init() 
      
    # Loading the song 
    mixer.music.load("song.wav") 
      
    # Setting the volume 
    mixer.music.set_volume(0.7) 
      
    # Start playing the song 
    mixer.music.play() 
      
    # infinite loop 
    while True: 
          
        print("Press 'p' to pause, 'r' to resume") 
        print("Press 'e' to exit the program") 
        query = input("  ") 
          
        if query == 'p': 
      
            # Pausing the music 
            mixer.music.pause()      
        elif query == 'r': 
      
            # Resuming the music 
            mixer.music.unpause() 
        elif query == 'e': 
      
            # Stop the mixer 
            mixer.music.stop() 
            break