I am a beginner in learning python. Recently in the process of reading one source code on GitHub, I feel confused and have some questions.
First, I feel confused about the code lb.audio.fft.fft.
ok_fft = np.abs(lb.audio.fft.fft(ok_frame))[0:int(len(ok_frame)/2+1)]
This is part of the code about fft but I have looked over the librosa’s offical website(librosa.org) and switch version 0.63/0.7/0.8 to find information about librosa.audio finally I end up with finding nothing.
So, I just want to know if anyone knows about this and tells me about how this part functions?
Second, I will receive an error which shows "attributeerror: ‘module’ object has no attribute ‘fft’" when I try to execute .py file.I have tried to google and solve by myself (I actually find some relevant questions and answers on this site but none of them can fix my error）
This is my first post here, please forgive for any mistakes and format errors. I would appreciate it very much if you can spare your precious time to reply me! Thanks in advance!
code as follows:
import librosa as lb import numpy as np import scipy as sc def scramble_fft(ok_frame): ok_fft = np.abs(lb.audio.fft.fft(ok_frame))[0:int(len(ok_frame)/2+1)] new_ok = np.zeros_like(lb.audio.fft.fft(ok_frame))[0:int(len(ok_frame)/2+1)] i = 0 while(True): # print("index ",i) if(i>=ok_fft.shape): break ok_fft_val = ok_fft[i] new_ok_val = findExample(ok_fft_val) if(np.equal(np.abs(new_ok_val),ok_fft[i])): new_ok[i] = new_ok_val i += 1 else: continue new_ok_long = half_to_full(new_ok) new_ok_long = sc.ifft(new_ok_long) new_ok_long = throw_imaginary(new_ok_long) return new_ok_long def throw_imaginary(fft_arr): result = np.zeros(len(fft_arr)) for i in range(fft_arr.shape): result[i] = fft_arr[i].real return result def half_to_full(new): new_1 = new new_2 = np.delete(new_1, len(new_1)-1) new_2 = np.delete(new_2, 0) new_flp = np.append(new_1,np.flip(new_2,0)) for i in range(1,int(len(new_flp)/2)): index_read = int(len(new_flp)/2-i) index_write = int(len(new_flp)/2+i) real = new_flp[index_read].real imag = new_flp[index_read].imag new_flp[index_write] = real-imag*1j return new_flp
Edit:This issue has already been resolved!
Anonymous Asked question May 13, 2021