<p>The audio transcription problem you describe is a well know problem in the Music Information Retrieval (MIR) research community. It is not one that is easy to solve and consists of two aspects: </p>

<ul>
<li><p>detecting pitch frequencies, which is often hard due to the occurrence of harmonics and the fact that notes are often glided into (C# can be detected instead of C), also due to tuning discrepancies. </p></li>
<li><p>beat detection: audio performances are often not played in time exactly, so finding the actual onsets can be tricky. </p></li>
</ul>

<p>A promising novel approach is to use deep neural networks to solve this, e.g.: </p>

<p>Boulanger-Lewandowski, N., Bengio, Y., &amp; Vincent, P. (2012). <a href="https://arxiv.org/ftp/arxiv/papers/1206/1206.6392.pdf" rel="nofollow noreferrer">Modeling temporal dependencies in high-dimensional sequences: Application to polyphonic music generation and transcription</a>. arXiv preprint arXiv:1206.6392.</p>

<p>More info:</p>

<p>Poliner, G. E., Ellis, D. P., Ehmann, A. F., Gómez, E., Streich, S., &amp; Ong, B. (2007). Melody transcription from music audio: Approaches and evaluation. IEEE Transactions on Audio, Speech, and Language Processing, 15(4), 1247-1256.</p>
How to get notes (frequencies and their times) from spectrogram in Python?
<p>I'm trying to make a program in Python from which I can upload a music file and get notes from this file (on piano). I created a <a href="https://i.stack.imgur.com/cqOUq.jpg" rel="nofollow noreferrer">Spectrogram</a>, and now how can I get a frequencies from it? How can I fix spectrogram (from half of spectrogram I have mirror reflection)? I need something like <a href="https://image.slidesharecdn.com/sigproc-selfstudy-130318120948-phpapp01/95/digital-signal-processing-through-speech-hearing-and-python-26-638.jpg?cb=1363609100" rel="nofollow noreferrer">this</a>. <a href="https://pastebin.com/t4dfKQwV" rel="nofollow noreferrer">Here</a> is my code.</p>

<pre><code>import numpy as np
from matplotlib import pyplot as plt
import scipy.io.wavfile as wav
from numpy.lib import stride_tricks

""" short time fourier transform of audio signal """
def stft(sig, frameSize, overlapFac=0.5, window=np.hanning):
    win = window(frameSize)
    hopSize = int(frameSize - np.floor(overlapFac * frameSize))

    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    samples = np.append(np.zeros(np.floor(frameSize/2.0)), sig)    
    # cols for windowing
    cols = np.ceil((len(samples) - frameSize) / float(hopSize)) + 1
    # zeros at end (thus samples can be fully covered by frames)
    samples = np.append(samples, np.zeros(frameSize))

    frames = stride_tricks.as_strided(samples, shape=(cols, frameSize), strides=(samples.strides[0]*hopSize, samples.strides[0])).copy()
    frames *= win

    return np.fft.rfft(frames)    

""" scale frequency axis logarithmically """    
def logscale_spec(spec, sr=44100, factor=20.):
    timebins, freqbins = np.shape(spec)

    scale = np.linspace(0, 1, freqbins) ** factor
    scale *= (freqbins-1)/max(scale)
    scale = np.unique(np.round(scale))

    # create spectrogram with new freq bins
    newspec = np.complex128(np.zeros([timebins, len(scale)]))
    for i in range(0, len(scale)):
       if i == len(scale)-1:
           newspec[:,i] = np.sum(spec[:,scale[i]:], axis=1)
       else:        
           newspec[:,i] = np.sum(spec[:,scale[i]:scale[i+1]], axis=1)

    # list center freq of bins
    allfreqs = np.abs(np.fft.fftfreq(freqbins*2, 1./sr)[:freqbins+1])
    freqs = []
    for i in range(0, len(scale)):
        if i == len(scale)-1:
            freqs += [np.mean(allfreqs[scale[i]:])]
        else:
            freqs += [np.mean(allfreqs[scale[i]:scale[i+1]])]

    return newspec, freqs

""" plot spectrogram"""
def plotstft(audiopath, binsize=2**10, plotpath=None, colormap="jet"):
    samplerate, samples = wav.read(audiopath)
    s = stft(samples, binsize)

    sshow, freq = logscale_spec(s, factor=1.0, sr=samplerate)
    ims = 20.*np.log10(np.abs(sshow)/10e-6) # amplitude to decibel

    timebins, freqbins = np.shape(ims)

    plt.figure(figsize=(15, 7.5))
    plt.imshow(np.transpose(ims), origin="lower", aspect="auto", cmap=colormap, interpolation="none")
    plt.colorbar()

    plt.xlabel("time (s)")
    plt.ylabel("frequency (Hz)")
    plt.xlim([0, timebins-1])
    plt.ylim([0, freqbins])

    xlocs = np.float32(np.linspace(0, timebins-1, 5))
    plt.xticks(xlocs, ["%.02f" % l for l in ((xlocs*len(samples)/timebins)+(0.5*binsize))/samplerate])
    ylocs = np.int16(np.round(np.linspace(0, freqbins-1, 10)))
    plt.yticks(ylocs, ["%.02f" % freq[i] for i in ylocs])

    if plotpath:
        plt.savefig(plotpath, bbox_inches="tight")
    else:
        plt.show()

    plt.clf()

plotstft("Sound/piano2.wav")
</code></pre>