I applied for the OpenAI Codex beta, and tried it out. It’s very cool.
It’s like GPT trained on Github or something like that, so you can just give it a prompt, and it tries to carry on the sentence with what it expects next.
So the easy way to use it, I’ve found, is to write a comment for the code you want it to write for you. I switched the engine to ‘davinci-codex’ and cranked up the response length to 1600 or so. Sometimes it just makes up more comments, or does something silly. But now and then it hits a home run.
Here’s an example.
""" Take an example wav file, found at file_name="/home/jovyan/work/307.wav", and plot a mel spectrogram of it. """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() S = librosa.feature.melspectrogram(y, sr=sr, n_mels=128) log_S = librosa.power_to_db(S, ref=np.max) plt.figure(figsize=(12, 4)) librosa.display.specshow(log_S, sr=sr, x_axis='time', y_axis='mel') plt.title('mel power spectrogram') plt.colorbar(format='%+02.0f dB') plt.tight_layout() plt.show()
I had to install librosa, but then it worked. It did more than I asked for.
Then I fed that whole thing, with another
"""
Plot the MFCC of file_name="/home/jovyan/work/307.wav"
"""
and it carried like an example giving champ:
""" Take an example wav file, found at file_name="/home/jovyan/work/307.wav", and plot a mel spectrogram of it. """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() S = librosa.feature.melspectrogram(y, sr=sr, n_mels=128) log_S = librosa.power_to_db(S, ref=np.max) plt.figure(figsize=(12, 4)) librosa.display.specshow(log_S, sr=sr, x_axis='time', y_axis='mel') plt.title('mel power spectrogram') plt.colorbar(format='%+02.0f dB') plt.tight_layout() plt.show() """ Plot the MFCC of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=40) plt.figure(figsize=(12, 4)) librosa.display.specshow(mfccs, x_axis='time') plt.colorbar() plt.title('MFCC') plt.tight_layout() plt.show() """ Plot the chromagram of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() chroma = librosa.feature.chroma_stft(y=y, sr=sr) plt.figure(figsize=(12, 4)) librosa.display.specshow(chroma, y_axis='chroma', x_axis='time') plt.colorbar() plt.title('Chromagram') plt.tight_layout() plt.show() """ Plot the chromagram of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() chroma = librosa.feature.chroma_stft(y=y, sr=sr) plt.figure(figsize=(12, 4)) librosa.display.specshow(chroma, y_axis='chroma', x_axis='time') plt.colorbar() plt.title('Chromagram') plt.tight_layout() plt.show() """ Plot the tonnetz of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() tonnetz = librosa.feature.tonnetz(y=y, sr=sr) plt.figure(figsize=(12, 4)) librosa.display.specshow(tonnetz, y_axis='tonnetz', x_axis='time') plt.colorbar() plt.title('Tonal Centroids (Tonnetz)') plt.tight_layout() plt.show() """ Plot the zero-crossing rate of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() zrate = librosa.feature.zero_crossing_rate(y) plt.figure(figsize=(12, 4)) librosa.display.specshow(zrate, x_axis='time') plt.colorbar() plt.title('Zero Crossing Rate') plt.tight_layout() plt.show() """ Plot the spectral centroid of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() cent = librosa.feature.spectral_centroid(y=y, sr=sr) plt.figure(figsize=(12, 4)) librosa.display.specshow(cent, x_axis='time') plt.colorbar() plt.title('Spectral Centroids') plt.tight_layout() plt.show() """ Plot the spectral bandwidth of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() spec_bw = librosa.feature.spectral_bandwidth(y=y, sr=sr) plt.figure(figsize=(12, 4)) librosa.display.specshow(spec_bw, x_axis='time') plt.colorbar() plt.title('Spectral Bandwidth') plt.tight_layout() plt.show() """ Plot the spectral rolloff of file_name="/home/jovyan/work/307.wav" """ import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 4)) librosa.display.waveplot(y, sr=sr) plt.show() spec_rolloff = lib
After waiting a while… we get:
import librosa import librosa.display import matplotlib.pyplot as plt file_name="/home/jovyan/work/307.wav" y, sr = librosa.load(file_name) plt.figure(figsize=(12, 8)) D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max) plt.subplot(4, 2, 1) librosa.display.specshow(D, y_axis='linear') plt.colorbar(format='%+2.0f dB') plt.title('Linear-frequency power spectrogram') plt.subplot(4, 2, 2) librosa.display.specshow(D, y_axis='log') plt.colorbar(format='%+2.0f dB') plt.title('Log-frequency power spectrogram') plt.subplot(4, 2, 3) librosa.display.specshow(D, x_axis='time') plt.colorbar(format='%+2.0f dB') plt.title('Time-frequency power spectrogram') plt.subplot(4, 2, 4) librosa.display.specshow(D, x_axis='time', y_axis='log') plt.colorbar(format='%+2.0f dB') plt.title('Log-Time-frequency power spectrogram')