The episode of Tech Talk discusses the basics of speech recognition software, its challenges, and the steps involved in creating it using Python and AI libraries. Speech recognition software can recognize human speech and convert it into text using speech signal processing and language processing. Python is a powerful language with libraries such as PyAudio and SpeechRecognition for working with AI and machine learning. The podcast explains how to set up a speech recognition engine using the Recognizer class in the SpeechRecognition library. The challenges involved include dealing with different accents and dialects. The podcast also shows how to use Python and the Keras library to implement a recurrent neural network with long short-term memory units to train a speech recognition model. The podcast provides examples of code to define the architecture of the model, train the model, and transcribe new audio data.
############EXAMPLE 1pythonimport speech_recognition as sr# create an instance of the Recognizer classr = sr.Recognizer()# use the default microphone as the audio sourcewith sr.Microphone() as source: print("Say something!") audio = r.listen(source)# recognize speech using Google Speech Recognitiontry: print("Google Speech Recognition thinks you said: " + r.recognize_google(audio))except sr.UnknownValueError: print("Google Speech Recognition could not understand audio")except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) ############ EXAMPLE 2pythonfrom keras.models import Sequentialfrom keras.layers import LSTM, Densemodel = Sequential()model.add(LSTM(128, return_sequences=True, input_shape=(None, num_mfcc)))model.add(LSTM(128))model.add(Dense(num_classes, activation='softmax'))model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])############EXAMPLE 3scssmodel.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=20, batch_size=64)############EXAMPLE 4scsspreprocessed_data = preprocess_audio(new_data)predicted_probs = model.predict(preprocessed_data)predicted_word = vocabulary[np.argmax(predicted_probs)]############EXAMPLE 5Python 3.xNumPySciPyPyAudioSpeechRecognitionTensorFlowKeras############EXAMPLE 6pip install numpy scipy pyaudio SpeechRecognition tensorflow keras############EXAMPLE 7pythonimport pyaudio# Set up audio streamp = pyaudio.PyAudio()stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)# Capture audio inputwhile True: data = stream.read(1024) # Process audio data here ############EXAMPLE 8pythonimport speech_recognition as sr# Set up recognizerr = sr.Recognizer()# Transcribe speechwith sr.Microphone() as source: audio = r.listen(source) text = r.recognize_google(audio)print(text)############EXAMPLE 9pythonimport tensorflow as tffrom tensorflow.keras.layers import Input, Dense, Dropout, LSTM, TimeDistributedfrom tensorflow.keras.models import Model# Define model architectureinputs = Input(shape=(None, 13))x = LSTM(128, return_sequences=True)(inputs)x = Dropout(0.2)(x)x = LSTM(128, return_sequences=True)(x)x = Dropout(0.2)(x)x = TimeDistributed(Dense(29, activation='softmax'))(x)model = Model(inputs=inputs, outputs=x)# Compile modelmodel.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])############EXAMPLE 10python# Load dataX_train, y_train = load_data()# Train modelmodel.fit(X_train, y_traintrain-clean-100: Contains the cleanest 100 hours of the training setdev-clean: Contains the development settest-clean: Contains the test setOnce we have extracted the dataset, we can use the following code to process the audio files and their transcriptions:pythonimport osimport shutilimport librosaimport pandas as pddef extract_features(file_name): X, sample_rate = librosa.load(file_name) stft = np.abs(librosa.stft(X)) mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T, axis=0) chroma = np.mean(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T,axis=0) mel = np.mean(librosa.feature.melspectrogram(X, sr=sample_rate).T,axis=0) contrast = np.mean(librosa.feature.spectral_contrast(S=stft, sr=sample_rate).T,axis=0) tonnetz = np.mean(librosa.feature.tonnetz(y=librosa.effects.harmonic(X),sr=sample_rate).T,axis=0) return mfccs,chroma,mel,contrast,tonnetzdef preprocess_data(dataset_dir): audio_files_dir = os.path.join(dataset_dir, "audio_files") transcripts_dir = os.path.join(dataset_dir, "transcripts") output_dir = os.path.join(dataset_dir, "processed_data") if os.path.exists(output_dir): shutil.rmtree(output_dir) os.makedirs(output_dir) transcripts_df = pd.read_csv(os.path.join(transcripts_dir, "transcripts.csv"), header=None, names=["file_name", "transcription"], delimiter=" ") for index, row in transcripts_df.iterrows(): file_name = row["file_name"] transcription = row["transcription"] audio_file_path = os.path.join(audio_files_dir, file_name + ".flac") mfccs, chroma, mel, contrast, tonnetz = extract_features(audio_file_path) output_file_path = os.path.join(output_dir, file_name + ".npy") np.save(output_file_path, [mfccs, chroma, mel, contrast, tonnetz, transcription]) ############ EXAMPLE 12pythonfrom kaldi import kaldi_iofrom kaldi.feat.mfcc import Mfcc, MfccOptionsfrom kaldi.feat.functions import compute_cmvn_stats, apply_cmvnfrom kaldi.matrix import Vector, SubVector, Matrixfrom kaldi.hmm import DecodableInterface, GaussDiag, TransitionModel, AmDiagGmm, GmmFlagsfrom kaldi.decoder import Decoder, LatticeFasterDecoderOptionsfrom kaldi.util.table import SequentialMatrixReader, SequentialIntVectorReader, RandomAccessInt32VectorReaderfrom kaldi.util.io import xopen# Set up feature extraction optionsmfcc_opts = MfccOptions()mfcc_opts.frame_opts.samp_freq = 16000mfcc_opts.use_energy = Falsemfcc_opts.num_ceps = 13# Load training data and transcriptionsfeats_reader = SequentialMatrixReader('train/feats.scp')labels_reader = SequentialIntVectorReader('train/text')# Extract--- Send in a voice message: https://podcasters.spotify.com/pod/show/rokos-basilisk/message


