Here 'listOfChunks' is a list of ByteArrays decoded from BASE64 (0-255).
E.g [ [23, 55, 125, 255, 234, 12, 5, ...] ]
How would I be able to use the FFT values I have generated to carry out spectrum analysis and show a spectogram.
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
question from:
https://stackoverflow.com/questions/65847186/how-to-create-a-spectogram-using-fft-values-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…