R=audiorecorder(44100,16,1);
Create an object that holds audio information , including sample rate, time, and recorded audio information. 44100 means sampled as
44100Hz (can be changed to 8000, 11025, 22050, etc., the higher the sampling frequency, the better the recorded sound quality, and the corresponding memory
The larger the storage space), 16 means 16bits storage, 1 means mono, and it can also be changed to 2 means two channels).
record(R); % Start recording , after inputting this command in the command window, speak into the microphone to start recording
pause(R); % pause recording
play(R); % play the recorded sound
resume(R); % Continue recording if necessary
stop(R); % stop recording , recording ends
getaudiodata(obj) returns the recorded audio data as an array of doubles
% 画出语音的时域波形
myspeech=getaudiodata(R); % 得到刚录制的音频信号矢量
plot(myspeech); % 画出语音波形
xlabel('时域样值'),ylabel('幅度'),title('语音波形');
% 写入和读取声音文件
audiowrite('myspeech.wav',myspeech,44100); % 语音存储
[x,Fs]=audioread('myspeech.wav');
wavwrite(myspeech,44100,'myspeech.wav') % for older versions of Matlab
[x,Fs]=wavread('myspeech.wav') % for older versions of Matlab