1

I have some project that need to play sound which can volume it up

import playsound
    playsound.playsound(PathToFile)

How can i volume up my sound with playsound library

Or i should use other library ?

Kanzt
  • 135
  • 1
  • 6
  • 13
  • 2
    https://stackoverflow.com/questions/13329617/change-the-volume-of-a-wav-file-in-python – Gwendal Grelier Jan 19 '18 at 09:31
  • @GwendalGrelier i don't want to create new file ,but i want something like this : first play sound with 10dB second is 20dB and third is 30dB – Kanzt Jan 19 '18 at 09:49

1 Answers1

3

There isn't much of a documentation for playsound module, but here is how you could do it with pygame

import pygame
pygame.init()
pygame.mixer.init()
sound = pygame.mixer.Sound(thepath)
sound.set_volume(0.9)   # Now plays at 90% of full volume.
sound.play()     

i got this from pygame official website, you can check it too for more info, pygame website.

EHM
  • 877
  • 1
  • 7
  • 28
  • I try to add this pygame.mixer.init(44100,-16,2,2048) to my first line and it's not error anymore ,but when i run my file i can't here the sound .I don't know what is 44100,-16,2,2048 – Kanzt Jan 19 '18 at 10:21
  • 44100 is the frequency, -16 is the size, 2 is the channel, and 2048 is the buffer. – EHM Jan 19 '18 at 10:35
  • is it a *wav file – EHM Jan 19 '18 at 10:39
  • Yes,it is . now i can play sound ,but i can't volume it up – Kanzt Jan 19 '18 at 11:00
  • try setting the new volume before playing the sound – EHM Jan 19 '18 at 11:17
  • ALSA lib pcm.c:7963:(snd_pcm_recover) underrun occurred << it shows on my output – Kanzt Jan 19 '18 at 11:42
  • @EHM Can you use pygame to control the volume of individual speaker (of a headset), such that at one point the volume from the right speaker is 100% and the volume of the left speaker is 50%? – Is_this_my_username Oct 14 '20 at 06:54