|
![]() |
Raspberry Pi Speech Commands with PyTorch
This labnote was last updated on 1/1/2020 OverviewBasic speech command recognition with PiTorch on the Raspberry Pi. This project is based on the example on the PyTorch website found here: https://pytorch.org/tutorials/intermediate/speech_command_recognition_with_torchaudio.html
We use a slightly modified version of the example program to train the ANN to recognize the spoken commands. This program runs on the a high end desktop with a NVIDIA GeForce GTX 10810 Ti GPU. The second program is for the Raspberry Pi and uses the trained ANN to recognize the spoken commands. We used PyAudio instead of TorchAudio for this version. At the time of the this article, there was not a handy version of TorchAudio for the Raspberry Pi available. The training data if from the SpeechCommand dataset which includes 35 commands. Which can be found here: https://arxiv.org/abs/1804.03209
System Requirements
Training ProgramThe training program is setup to take advantage of a GPU if avail. device = torch.device("cuda" if torch.cuda.is_available() else "cpu") print(device) We added some code to save and load the model: print("Loading weights...\n") model= torch.load('D:\Pytorch\Speech001') print("Weights Loaded!\n") If you want to start with a clean ANN, must comment this code out.
After the ANN is trained or with the program exits, the ANN model is saved: model.saveWeights(model)
Training DataSpeechCommands version .02 was used for this project. It includes the following commands:
Source CodeThis project includes three python 3 program and a trained copy of the ANN.
Source Code can be downloaded here: SpeechCommand_PiTorch_Rpi TestingWe added code to allow a spoken command to be tested against the trained ANN. Press enter the when “Recording” appears – speak a command
Type “exit” to end the program.
Raspberry Pi Version
Speech_Test_NoPyTorchAudio comments: To run the test application on the Raspberry Pi, we had to remove the TorchAudio library. PyAudio is used instead to handle the microphone requirements. The work labels are hard coded in the test code. Error trapping has been added to supress ALSA warnings. ## Added to suppress ALSA warnings ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p) def py_error_handler(filename, line, function, err, fmt): pass c_error_handler = ERROR_HANDLER_FUNC(py_error_handler)
@contextmanager def noalsaerr(): asound = cdll.LoadLibrary('libasound.so') asound.snd_lib_error_set_handler(c_error_handler) yield asound.snd_lib_error_set_handler(None)
|
![]() |
|