Final answer:
To record your voice for 5 seconds at a sampling rate of 16000 samples/sec with a microphone connected to a PC in MATLAB, use the audiorecorder function to create an object, record the audio, retrieve the recorded data, and save it to a file using audiowrite.
Step-by-step explanation:
To record your voice using a microphone connected to the PC using MATLAB, you can use the built-in audiorecorder function. The following MATLAB code snippet will record audio for 5 seconds at a sampling rate of 16000 samples per second.
fs = 16000; % Define the sampling rate
nBits = 16; % Number of bits per sample
nChannels = 1; % Number of audio channels (1 for mono, 2 for stereo)
% Create the audiorecorder object
recObj = audiorecorder(fs, nBits, nChannels);
% Record the audio for 5 seconds
recordblocking(recObj, 5);
% Retrieve the audio data from the audiorecorder object
myRecording = getaudiodata(recObj);
% Save the recording to a file
audiowrite('myVoiceRecording.wav', myRecording, fs);
This code uses record blocking to record audio for a fixed number of seconds and get audio data to retrieve the recorded audio from the audio recorder object. The recording is then saved as a WAV file using Audiowrite.