0

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
  • I think this has been covered a couple of times. I would consult other answers first e.g. https://stackoverflow.com/a/44800492/8876321 – fdcpp Jan 23 '21 at 12:34
  • Does this answer your question? [How to convert a .wav file to a spectrogram in python3](https://stackoverflow.com/questions/44787437/how-to-convert-a-wav-file-to-a-spectrogram-in-python3) – fdcpp Jan 24 '21 at 08:02

0 Answers0