Created
July 10, 2019 07:21
-
-
Save aravindpai/e077b793e9c3204031d069d0976bafb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| train_audio_path = '../input/tensorflow-speech-recognition-challenge/train/audio/' | |
| samples, sample_rate = librosa.load(train_audio_path+'yes/0a7c2a8d_nohash_0.wav', sr = 16000) | |
| fig = plt.figure(figsize=(14, 8)) | |
| ax1 = fig.add_subplot(211) | |
| ax1.set_title('Raw wave of ' + '../input/train/audio/yes/0a7c2a8d_nohash_0.wav') | |
| ax1.set_xlabel('time') | |
| ax1.set_ylabel('Amplitude') | |
| ax1.plot(np.linspace(0, sample_rate/len(samples), sample_rate), samples) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got the same issue and sounds logic, so I decided to generate the graphic with librosa.display.waveplot
import osimport librosa #for audio processingimport librosa.displayimport IPython.display as ipdimport matplotlib.pyplot as pltimport numpy as npfrom scipy.io import wavfile #for audio processingimport warningswarnings.filterwarnings("ignore")# ConstantsFOLDER_PATH = '/foo/'FILE_PATH = FOLDER_PATH + '001.wav'PLOT_TITLE = 'Raw wave of ' + FILE_PATH# Creates the main plotfig = plt.figure(figsize=(14, 8))# Creates the sub-plot for the graphicax1 = fig.add_subplot(211)ax1.set_title(PLOT_TITLE)ax1.set_xlabel('time')ax1.set_ylabel('Amplitude')# Loads audio filesamples, sample_rate = librosa.load(FILE_PATH, sr=16000)print('Sampling rate: ' + str(sample_rate))print('Sample number: ' + str(len(samples)))# Generates the graphiclibrosa.display.waveplot(samples, sr=sample_rate, ax=ax1)# Prints plotsplt.show()