2017-02-14 164 views
1

我有一個代碼不再適用於最新版本的matlab,因爲wavrecord不再使用。我怎樣才能轉換此:如何將wavrecord轉換爲audiorecorder?

Fs=8000; 

my_voice=wavrecord(3*Fs,Fs,'int16'); 

wavplay(myvoice,Fs); 

在Matlab的工作方式現在呢?

+0

查看https://se.mathworks.com/matlabcentral/answers/165279-how-to-change-wavrecord-to-audiorecorder –

回答

0

驗證碼:

% Setup the recording object 
Fs = 8000; 
Nbits = 16; 
my_recorder = audiorecorder(Fs, Nbits, 1) 

% Record the audio 
record(my_recorder, 3); 
% Retrieve the sampled recording 
my_voice = getaudiodata(my_recorder); 
% Play the sampled recording 
play(my_voice); 

這將重現你張貼在你的問題的代碼(類似於answer @Jørgen linked in the comments)。

解釋上面的代碼:

首先,讓我們打破你的代碼做了什麼。

my_voice = wavrecord(3*Fs, Fs, 'int16')記錄3Fs = 8000 Hz採樣的16位音頻的秒數。如果不指定通道,則默認值爲mono或1通道輸入。

現在,您想用audiorecorder()函數複製此行爲。

audiorecorder(Fs, nBits, nChannels)創建一個audiorecorder對象,其樣本nBits音頻爲Fs Hz。

你想要錄製的16位音頻,在Fs = 8000赫茲所以nBits = 16採樣,並因爲你沒有用wavrecord()指定頻道你用1路音頻輸入,所以nChannels這裏是1my_recorder = audiorecorder(8000,16,1)

您仍然希望指定3秒的記錄時間。所以,你應該記錄來自my_recorder對象的數據3秒:record(my_recorder, 3)

爲了檢索採樣音頻:my_voice = getaudiodata(my_recorder)

相關問題