I have just started writing a program to manipulate some audio in python. Before I write any filtering functions, I wanted to do a test to compare the input signal to the output signal after having the input signal go through an rfft and irfft. For some reason the output file has an incredible amount of gain in it (50db!) compared to the input file, and I can't figure out why this is happening. Here is the code:
from scipy.io.wavfile import read, write
from scipy.fftpack import rfft, irfft
import numpy as np
rate, input = read('5and10ksm.wav')
transformed = rfft(input)
output = irfft(transformed)
write('smaller.wav', rate, output)
Thanks!
scipy.fftpack.irfft
returns an array of floats. Convert it to the dtype of your input file before writing it as wav file: output.astype(input.dtype)
.
来源:https://stackoverflow.com/questions/35931169/rfft-or-irfft-increasing-wav-file-volume-in-python