How to do it...

  1. In this recipe, we start by importing all libraries:
import globimport numpy as npimport randomimport librosafrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import LabelBinarizerimport kerasfrom keras.layers import LSTM, Dense, Dropout, Flattenfrom keras.models import Sequentialfrom keras.optimizers import Adamfrom keras.callbacks import EarlyStopping, ModelCheckpoint
  1. Let's set SEED and the location of the .wav files:
SEED = 2017DATA_DIR = 'Data/spoken_numbers_pcm/' 
  1. Let's split the .wav files in a training set and a validation set with scikit-learn's train_test_split function:
files = glob.glob(DATA_DIR + "*.wav")X_train, X_val = train_test_split(files, test_size=0.2, random_state=SEED) ...

Get Python Deep Learning Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.