realtime_spectrogram.py
def generate_string_from_audio(audio_data):
    """
    This function takes one audio buffer as a numpy array and returns a
    string to be printed to the terminal.
    """
    # Compute real FFT.
    x_fft = numpy.fft.rfft(audio_data, n=N_FFT)

    # Compute mel spectrum.
    melspectrum = M.dot(abs(x_fft))

    # Initialize output characters to display.
    char_list = [' ']*SCREEN_WIDTH

    for i in range(SCREEN_WIDTH):

        # If there is energy in this frequency bin, display an asterisk.
        if melspectrum[i] > ENERGY_THRESHOLD:
            char_list[i] = '*'

        # Draw frequency axis guidelines.
        elif i % 30 == 29:
            char_list[i] = '|'

    # Return string.
    return ''.join(char_list)

    This function takes one audio buffer as a numpy array and returns a
    string to be printed to the terminal.
    
This function takes one audio buffer as a numpy array and returns a
string to be printed to the terminal.
This function takes one audio buffer as a numpy array and returns a string to be printed to the terminal .
def generate_string_from_audio(audio_data):
    x_fft = numpy.fft.rfft(audio_data, n=N_FFT)
    melspectrum = M.dot(abs(x_fft))
    char_list = [' ']*SCREEN_WIDTH
    for i in range(SCREEN_WIDTH):
        if melspectrum[i] > ENERGY_THRESHOLD:
            char_list[i] = '*'
        elif i % 30 == 29:
            char_list[i] = '|'
    return ''.join(char_list)
def generate_string_from_audio ( audio_data ) : x_fft = numpy . fft . rfft ( audio_data , n = N_FFT ) melspectrum = M . dot ( abs ( x_fft ) ) char_list = [ ' ' ] * SCREEN_WIDTH for i in range ( SCREEN_WIDTH ) : if melspectrum [ i ] > ENERGY_THRESHOLD : char_list [ i ] = '*' elif i % 30 == 29 : char_list [ i ] = '|' return '' . join ( char_list )
This function takes one audio buffer as a numpy array and returns a
string to be printed to the terminal.
This function takes one audio buffer as a numpy array and returns a string to be printed to the terminal .
"""
    This function takes one audio buffer as a numpy array and returns a
    string to be printed to the terminal.
    """ # Compute real FFT. # Compute mel spectrum. # Initialize output characters to display. # If there is energy in this frequency bin, display an asterisk. # Draw frequency axis guidelines. # Return string.
audio_data