简体   繁体   中英

rfft or irfft increasing wav file volume in python

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) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM