Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@Mariyem1998

This comment has been minimized.

Copy link

@Mariyem1998 Mariyem1998 commented Jan 1, 2021

Please, I have an error in ligne 8 that tell this :
"ValueError: x and y must have same first dimension, but have shapes (16000,) and (87061,) "

@redmlr

This comment has been minimized.

Copy link

@redmlr redmlr commented Feb 13, 2021

Same here, did you managed it @Mariyem1998?

@jdigruttola

This comment has been minimized.

Copy link

@jdigruttola jdigruttola commented Apr 16, 2021

I got the same issue and sounds logic, so I decided to generate the graphic with librosa.display.waveplot

import os
import librosa #for audio processing
import librosa.display
import IPython.display as ipd
import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile #for audio processing
import warnings
warnings.filterwarnings("ignore")

# Constants
FOLDER_PATH = '/foo/'
FILE_PATH = FOLDER_PATH + '001.wav'
PLOT_TITLE = 'Raw wave of ' + FILE_PATH

# Creates the main plot
fig = plt.figure(figsize=(14, 8))

# Creates the sub-plot for the graphic
ax1 = fig.add_subplot(211)
ax1.set_title(PLOT_TITLE)
ax1.set_xlabel('time')
ax1.set_ylabel('Amplitude')

# Loads audio file
samples, sample_rate = librosa.load(FILE_PATH, sr=16000)
print('Sampling rate: ' + str(sample_rate))
print('Sample number: ' + str(len(samples)))

# Generates the graphic
librosa.display.waveplot(samples, sr=sample_rate, ax=ax1)

# Prints plots
plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment