簡單地為語音添加雜訊
目的:為語音數據添加指定的雜訊類型
原理:在指定的信噪比下添加雜訊
簡單的公式說明,假設給定雜訊在幅值上擴大 倍後剛好達到指定的信噪比那麼
附上批處理代碼:
function addnoise(dB,newdir)
% -------------------------------------
% dB : 指定信噪比
% newdir : 保存路徑
% example : addnoise(10,./noisywav/)
% -------------------------------------
if (isdir(newdir)==0)
mkdir(newdir);
end
% --------------------------------------------------
% 讀取一個.wav格式的雜訊音頻數據文件
% --------------------------------------------------
[name,path] = uigetfile(*.wav,select one noise wav as background, MultiSelect,off);
[noise, fs] = audioread([path,name]);
Ln = size(noise,1);
clear name path;
% --------------------------------------------------
% 讀取多個較乾淨的.wav格式的音頻數據文件
% --------------------------------------------------
[name,path] = uigetfile(*.wav,select wav Files to add noise, MultiSelect,on);
tic
if iscell(name)
E = length(name);
for e = 1:E
[speech,fs] = audioread([path,name{e}]);
Ls = size(speech,1);
Es = speech * speech;
Ps = floor( rand(1,1)*(Ln-Ls) + 1 );
Pe = Ps + Ls - 1;
En = noise(Ps:Pe) * noise(Ps:Pe);
K = sqrt(Es/En) * 10^( -( dB + rand(1,1) )/20 );
speech = speech + K * noise(Ps:Pe);
audiowrite([newdir num2str(dB) dB_ name{e}], speech, fs);
end
else
disp(please select more than one wav file.);
end
toc
end
覺得好用就拿走吧 ?
推薦閱讀: