问题描述
此处的“listofChunks”是从 BASE64 (0-255) 解码的 ByteArray 列表。 例如 [[23,55,125,255,234,12,5,...] ]
我如何能够使用我生成的 FFT 值进行频谱分析并显示频谱图。
from scipy.fft import fft,ifft,fftfreq
import numpy as np
import matplotlib.pyplot as plot
@app.route('/api',methods=['GET','POST'])
def test():
listofChunks = []
try:
data = request.get_json()
audioChunk = data['audioChunk']
listofChunks.append(audioChunk['data'])
except Exception as e:
print("An error has occured: ",e)
return "Error"
for i in listofChunks:
# Smaller memory consumption & faster & optimized functions for FFT
npArray = np.array(i)
#
fftArray = fft(npArray)
# The ifft takes frequency domain input data and converts to time domain output data
ifftArray = (fftArray)
#Plotting
N = 600
T = 1.0 / 800.0
npArray = np.linspace(0.0,N*T,N,endpoint=False)
fftArray = np.sin(50.0 * 2.0*np.pi*npArray) + 0.5*np.sin(80.0 * 2.0*np.pi*npArray)
yf = fft(fftArray)
xf = fftfreq(N,T)[:N//2]
plt.plot(xf,2.0/N * np.abs(yf[0:N//2]))
plt.grid()
plt.show()
# 3584 items per chunk (3MB)
print(ifftArray)
return "Success"
[1]: https://i.stack.imgur.com/Z5YEl.png
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)