For training, speech is acquired from a microphone and brought into the development environment for offline analysis. For testing, speech is continuously streamed into the environment for online processing.
During the training stage, it is necessary to record repeated utterances of each digit in the dictionary. For example, we repeat the word ‘one’ many times with a pause between each utterance.
Using the following MATLAB code with a standard PC sound card, we capture ten seconds of speech from a microphone input at 8000 samples per second:Fs = 8000; % Sampling Freq (Hz) Duration = 10; % Duration (sec) y = wavrecord(Duration*Fs,Fs);
We save the data to disk as ‘’:
This approach works well for training data. In the testing stage, however, we need to continuously acquire and buffer speech samples, and at the same time, process the incoming speech frame by frame, or in continuous groups of samples.
We use Data Acquisition Toolbox™ to set up continuous acquisition of the speech signal and simultaneously extract frames of data for processing.
The following MATLAB code uses a Windows sound card to capture data at a sampling rate of 8000 Hz. Data is acquired and processed in frames of 80 samples. The process continues until the “RUNNING” flag is set to zero.% Define system parameters framesize = 80; % Framesize (samples) Fs = 8000; % Sampling Frequency (Hz) RUNNING = 1; % A flag to continue data capture % Setup data acquisition from sound card ai = analoginput('winsound'); addchannel(ai, 1); % Configure the analog input object. set(ai, 'SampleRate', Fs); set(ai, 'SamplesPerTrigger', framesize); set(ai, 'TriggerRepeat',inf); set(ai, 'TriggerType', 'immediate'); % Start acquisition start(ai) % Keep acquiring data while "RUNNING" ~= 0 while RUNNING % Acquire new input samples newdata = getdata(ai,ai.SamplesPerTrigger); % Do some processing on newdata ... <DO _ SOMETHING> ... % Set RUNNING to zero if we are done if <WE _ ARE _ DONE> RUNNING = 0; end end % Stop acquisition stop(ai); % Disconnect/Cleanup delete(ai); clear ai;