Simply read and write wave files for sound editing.
Returns the samples and sample rate of a wav file.
Parameters: | file_name (str) – The name of the wav file to read. The wav file must not use any compression. |
---|---|
Returns: | (list(float), int) – The wav file’s samples as a list of floats in the range -1 to 1 and the wav file’s sample rate in samples per second. |
Write a list of samples in the range -1 to 1 as a 16-bit mono wav.
Parameters: |
|
---|
Here is an example of using the Sound module to lower the volume of a sound file:
import sound
sound_file_name = 'pretty_sound.wav'
fraction_decrease = 0.5
(samples, sample_rate) = sound.read_sound(sound_file_name)
for i in range(len(samples)):
samples[i] = samples[i] * fraction_decrease
sound.write_sound(sound_file_name, samples, sample_rate)