Change the volume of a wav file in python

倖福魔咒の 提交于 2019-11-30 07:03:17
Jiaaro

I wrote a library to simplify this type of thing

You can do that like so:

from pydub import AudioSegment

song = AudioSegment.from_wav("never_gonna_give_you_up.wav")

# reduce volume by 10 dB
song_10_db_quieter = song - 10

# but let's make him *very* quiet
song = song - 36

# save the output
song.export("quieter.wav", "wav")

As you can see in the comments of the question, there are several solutions, some more efficient.

The problem was immediately detected by Jan Dvorak ("the * 5 part is clipping and overflowing") and the straightforward solution was:

s = numpy.fromstring(s, numpy.int16) / 10 * 5

In this case, this solution was perfect for me, just good enough.

Thank you all folks!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!