Here is the Python code for altering the frequency range of a wav file from 20Hz to 2KHz using FFT:
import numpy as np
import scipy.io.wavfile as wav
# Read the input wav file
fs, data = wav.read('input.wav')
# Compute the FFT of the audio signal
fft_out = np.fft.fft(data)
# Compute the frequency range of the FFT output
freqs = np.fft.fftfreq(len(fft_out))
# Compute the indexes of the frequency range of interest
idxs = np.where((freqs >= 20) & (freqs <= 2000))[0]
# Create a new array and copy the selected frequencies to it
new_fft_out = np.zeros(len(fft_out), dtype=np.complex)
new_fft_out[idxs] = fft_out[idxs]
# Compute the inverse FFT of the modified signal
new_data = np.fft.ifft(new_fft_out)
# Write the output to a new wav file
wav.write('output.wav', fs, np.int16(new_data.real))
Note that the code assumes the input wav file has a single channel. If the file has multiple channels, you need to process each channel separately.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-08-25 11:00:00 +0000
Seen: 7 times
Last updated: Feb 12 '22
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?