How to do it...

Let's see how to build a speech recognizer:

  1. Create a new Python file and import the following packages (the full code is in the speech_recognizer.py file that's already provided for you):
import os 
import argparse  
 
import numpy as np 
from scipy.io import wavfile  
from hmmlearn import hmm 
from python_speech_features import mfcc 
  1. Define a function to parse the input arguments in the command line:
# Function to parse input arguments 
def build_arg_parser():    parser = argparse.ArgumentParser(description='Trains the HMM classifier')    parser.add_argument("--input-folder", dest="input_folder", required=True,            help="Input folder containing the audio files in subfolders")    return parser
  1. Let's use the HMMTrainer class defined in the previous ...

Get Python Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.