Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

audio - How to create a Spectogram using FFT values? (Python)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...