主要内容

用深度学习网络分离鸡尾酒会信息源

这个例子展示了如何使用深度学习网络分离语音信号。

简介

鸡尾酒会效应指的是大脑能够专注于一个说话者,同时过滤掉其他声音和背景噪音。人类在鸡尾酒会问题上表现得很好。这个例子展示了如何使用深度学习网络将单个说话者从一个男性和一个女性同时说话的语音混合中分离出来。

下载所需的文件

在详细了解示例之前,您将下载一个预先训练过的网络和4个音频文件。

downloadFolder = matlab.internal.examples.downloadSupportFile (“音频”“CocktailPartySourceSeparation.zip”);dataFolder = tempdir;unzip(downloadFolder,dataFolder) dataset = fullfile(dataFolder,“CocktailPartySourceSeparation”);

问题总结

加载音频文件,包含在4khz采样的男性和女性语音。分别听音频文件,以供参考。

[mSpeech, Fs] = audioread (fullfile(数据集,“MaleSpeech-16-4-mono-20secs.wav”));声音(mSpeech Fs)
[fSpeech] = audioread (fullfile(数据集,“FemaleSpeech-16-4-mono-20secs.wav”));声音(fSpeech Fs)

合并两个语音源。确保在混合电源中有相等的功率。缩放混合,使其最大振幅为1。

mSpeech = mSpeech /规范(mSpeech);fSpeech = fSpeech /规范(fSpeech);ampAdj = max (abs ([mSpeech; fSpeech]));mSpeech = mSpeech / ampAdj;fSpeech = fSpeech / ampAdj;mix = mSpeech + fSpeech;混合= mix. / max (abs(混合));

想象原始信号和混合信号。听混合语音信号。这个例子展示了一个从语音混合中提取男性和女性源的源分离方案。

t =(0:元素个数(混合)1)* (1 / Fs);图(1)tiledlayout(3,1) nexttile plot(t,mSpeech) title(“男性演讲》网格)fSpeech nexttile情节(t)标题(“女性语言”网格)nexttile情节(t,混合)标题(“语音组合”)包含(“时间(s)”网格)

听混音音频。

声音(混合,Fs)

时频表示

使用stft将男性、女性和混合语音信号的时频(TF)表示可视化。使用长度为128的Hann窗口,FFT长度为128,重叠长度为96。

windowLength = 128;fftLength = 128;overlapLength = 96;赢得=损害(windowLength,“周期”);图(2)tiledlayout(3,1) nexttile stft(mSpeech,Fs,Window=win,OverlapLength= OverlapLength,FFTLength= FFTLength,FrequencyRange= .“单向的”);标题(“男性演讲》) nexttile stft (fSpeech Fs,窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);标题(“女性语言”(混合)nexttile stft, Fs,窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);标题(“混合”演讲

使用理想时频掩模的源分离

TF掩码的应用已被证明是将所需音频信号从竞争声音中分离出来的一种有效方法。TF掩码是与底层STFT大小相同的矩阵。掩码与底层STFT逐个元素相乘,以隔离所需的源。TF掩码可以是二进制的,也可以是软的。

使用理想二进制掩码的源分离

在理想的二进制掩码中,掩码单元值为0或1。如果所需电源的功率大于特定TF单元上其他电源的功率之和,则该单元设置为1。否则,将单元格设置为0。

计算男性说话者的理想二进制掩码,然后将其可视化。

P_M = stft (mSpeech窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);P_F = stft (fSpeech窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);[P_mix F] = stft(混合,窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);binaryMask = abs(P_M) >= abs(P_F);图(3)plotMask(binarmask,windowLength - overlapLength,F,Fs)

通过将混合STFT乘以男性扬声器的二进制掩码来估计男性语音的STFT。通过将混合STFT乘以男性说话者二进制掩码的倒数来估计女性说话者的STFT。

P_M_Hard = P_mix。* binaryMask;P_F_Hard = P_mix。* (1-binaryMask);

利用逆短时FFT (ISTFT)估计男性和女性音频信号。可视化估计信号和原始信号。听估计的男性和女性的语音信号。

mSpeech_Hard = istft (P_M_Hard窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);fSpeech_Hard = istft (P_F_Hard窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);图(4)tiledlayout(2,2) nexttile plot(t,mSpeech)轴([t(1) t(end) -1]) title(“原来男性演讲》网格)nexttile plot(t,mSpeech_Hard) axis([t(1) t(end) -1]) xlabel(“时间(s)”)标题(“估计男性演讲》网格)nexttile plot(t,fSpeech) axis([t(1) t(end) -1]) title(“原始女性讲话”网格)nexttile plot(t,fSpeech_Hard)轴([t(1) t(end) -1]) title(“估计女性演讲》)包含(“时间(s)”网格)

声音(mSpeech_Hard Fs)
声音(fSpeech_Hard Fs)

使用理想的软掩模分离源

在软掩码中,TF掩码单元值等于所需源功率与总混合功率的比值。TF细胞的值范围为[0,1]。

计算男性扬声器的软掩码。通过将混合STFT乘以男扬声器的软掩模来估计男扬声器的STFT。通过将混合STFT乘以女扬声器的软掩模来估计女扬声器的STFT。

使用ISTFT估计男性和女性音频信号。

softMask = abs (P_M)。/ (abs (P_F) + abs (P_M) + eps);P_M_Soft = P_mix。* softMask;P_F_Soft = P_mix。* (1-softMask);mSpeech_Soft = istft (P_M_Soft窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);fSpeech_Soft = istft (P_F_Soft窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);

可视化估计信号和原始信号。听估计的男性和女性的语音信号。请注意,结果非常好,因为面具是在完全了解分离的男性和女性信号的情况下创建的。

图(5)tiledlayout(2,2) nexttile plot(t,mSpeech) axis([t(1) t(end) -1]) title(“原来男性演讲》网格)nexttile plot(t,mSpeech_Soft)轴([t(1) t(end) -1]) title(“估计男性演讲》网格)nexttile plot(t,fSpeech) axis([t(1) t(end) -1]) xlabel(“时间(s)”)标题(“原始女性讲话”网格)nexttile plot(t, fspeech h_soft) axis([t(1) t(end) -1]) xlabel(“时间(s)”)标题(“估计女性演讲》网格)

声音(mSpeech_Soft Fs)
声音(fSpeech_Soft Fs)

使用深度学习的掩码估计

本例中深度学习网络的目标是估计上述理想的软掩码。网络估计与该男性说话者对应的掩码。女性扬声器口罩直接由男性口罩衍生而来。

基本的深度学习训练方案如下所示。预测器是混合(男性+女性)音频的幅度谱。目标是与男性说话者相对应的理想软面具。回归网络使用预测器输入来最小化输出和输入目标之间的均方误差。在输出处,使用输出幅度谱和混合信号的相位将音频STFT转换回时域。

您可以使用短时傅里叶变换(STFT)将音频转换到频域,其窗口长度为128个样本,重叠为127个样本,以及一个Hann窗口。通过删除与负频率对应的频率样本(因为时域语音信号是真实的,这不会导致任何信息丢失),可以将谱向量的大小减少到65。预测器输入由20个连续的STFT向量组成。输出是一个65 × 20的软掩码。

你用训练过的网络来估计男性的言语。经过训练的网络的输入是(男性+女性)混合语音音频。

STFT目标和预测

本节说明如何从训练数据集生成目标信号和预测器信号。

分别从男性和女性演讲者中读取约400秒的训练信号,采样频率为4千赫。低采样率用于加速训练。修剪训练信号,使其长度相同。

mSpeechTrain = audioread (fullfile(数据集,“malespeech - 16 - 4 - mono - 405 secs.wav”));fSpeechTrain = audioread (fullfile(数据集,“femalespeech - 16 - 4 - mono - 405 secs.wav”));L = min(长度(mSpeechTrain), (fSpeechTrain));mSpeechTrain = mSpeechTrain (1: L);fSpeechTrain = fSpeechTrain (1: L);

分别读取由男性和女性说话者约20秒的语音组成的验证信号,以4 kHz采样。修剪验证信号,使它们的长度相同。

mSpeechValidate = audioread (fullfile(数据集,“MaleSpeech-16-4-mono-20secs.wav”));fSpeechValidate = audioread (fullfile(数据集,“FemaleSpeech-16-4-mono-20secs.wav”));L = min(长度(mSpeechValidate), (fSpeechValidate));mSpeechValidate = mSpeechValidate (1: L);fSpeechValidate = fSpeechValidate (1: L);

将训练信号扩展到相同的幂次。将验证信号扩展到相同的功率。

mSpeechTrain = mSpeechTrain /规范(mSpeechTrain);fSpeechTrain = fSpeechTrain /规范(fSpeechTrain);ampAdj = max (abs ([mSpeechTrain; fSpeechTrain]));mSpeechTrain = mSpeechTrain / ampAdj;fSpeechTrain = fSpeechTrain / ampAdj;mSpeechValidate = mSpeechValidate /规范(mSpeechValidate);fSpeechValidate = fSpeechValidate /规范(fSpeechValidate);ampAdj = max (abs ([mSpeechValidate; fSpeechValidate]));mSpeechValidate = mSpeechValidate / ampAdj;fSpeechValidate = fSpeechValidate / ampAdj;

创建培训和验证“鸡尾酒会”混合。

mixTrain = mSpeechTrain + fSpeechTrain;mixTrain = mixTrain / max (mixTrain);mixValidate = mspeech hvalidate + fspeech hvalidate;mixValidate = mixValidate / max (mixValidate);

STFTs生成培训。

windowLength = 128;fftLength = 128;overlapLength = 128 - 1;Fs = 4000;赢得=损害(windowLength,“周期”);P_mix0 = abs (stft (mixTrain窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”));P_M = abs (stft (mSpeechTrain窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”));P_F = abs (stft (fSpeechTrain窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”));

取混合STFT的对数。用平均值和标准差进行归一化处理。

P_mix = log(P_mix0 + eps);议员=意味着(P_mix (:));SP =性病(P_mix (:));P_mix = (P_mix - MP)/SP;

生成验证STFTs。取混合STFT的对数。用平均值和标准差进行归一化处理。

P_Val_mix0 = stft (mixValidate窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”);P_Val_M = abs (stft (mSpeechValidate窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”));P_Val_F = abs (stft (fSpeechValidate窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”));P_Val_mix0 = log(abs(P_Val_mix0) + eps);议员=意味着(P_Val_mix (:));SP =性病(P_Val_mix (:));P_Val_mix = (P_Val_mix - MP) / SP;

当网络的输入具有合理的平滑分布并经过归一化处理时,训练神经网络是最容易的。为了检查数据分布是否平滑,绘制训练数据的STFT值的直方图。

图(6)直方图(P_mix EdgeColor =“没有”归一化=“pdf”)包含(“输入值”) ylabel (“概率密度”

计算训练软掩码。在训练网络时使用此掩码作为目标信号。

maskTrain = P_M。/(P_M + P_F + eps);

计算验证软掩码。使用此掩码来评估经过训练的网络发出的掩码。

maskValidate = P_Val_M。/(P_Val_M + P_Val_F + eps);

为了检查目标数据分布是否平滑,绘制训练数据掩码值的直方图。

图(7)直方图(maskTrain EdgeColor =“没有”归一化=“pdf”)包含(“输入值”) ylabel (“概率密度”

从预测器和目标信号中创建大小(65,20)的块。为了得到更多的训练样本,在连续的块之间使用10个片段的重叠。

seqLen = 20;seqOverlap = 10;mixSequences = 0 (1 + fftLength/2,seqLen,1,0);maskSequences = 0 (1 + fftLength/2,seqLen,1,0);loc = 1;loc < size(P_mix,2) - seqLen mixSequences(:,:,:,end+1) = P_mix(:,loc:loc+seqLen-1);maskSequences(:,:,:,结束+ 1)= maskTrain (:, loc: loc + seqLen-1);loc = loc + seqOverlap;结束

从验证预测器和目标信号创建大小为(65,20)的块。

mixValSequences = 0 (1 + fftLength/2,seqLen,1,0);maskValSequences = 0 (1 + fftLength/2,seqLen,1,0);seqOverlap = seqLen;loc = 1;loc < size(P_Val_mix,2) - seqLen mixValSequences(:,:,:,end+1) = P_Val_mix(:,loc:loc+seqLen-1);maskValSequences(:,:,:,结束+ 1)= maskValidate (:, loc: loc + seqLen-1);loc = loc + seqOverlap;结束

重塑训练和验证信号。

mixSequencesT =重整(mixSequences,[1 1 (1 + fftLength/2)*seqLen size(mixSequences,4)]);mixSequencesV = remodeling (mixValSequences,[1 1 (1 + fftLength/2)*seqLen size(mixValSequences,4)]);maskSequencesT =重塑(maskSequences,[1 1 (1 + fftLength/2)*seqLen size(maskSequences,4)]);maskSequencesV =重塑(maskValSequences,[1 1 (1 + fftLength/2)*seqLen size(maskValSequences,4)]);

定义深度学习网络

定义网络的层。指定输入大小为大小为1 × 1 × 1300的图像。定义两个隐藏的完全连接层,每个层有1300个神经元。在每个隐藏的完全连接层后面加上一个sigmoid层。批处理归一化层归一化输出的均值和标准差。添加一个包含1300个神经元的完全连接层,然后是一个回归层。

numNodes = (1 + fftLength/2)*seqLen;层= [...imageInputLayer([1 1 (1 + fftLength/2)*seqLen],归一化=“没有”) fulllyconnectedlayer (numNodes) BiasedSigmoidLayer(6) batchNormalizationLayer dropoutLayer(0.1) fulllyconnectedlayer (numNodes) BiasedSigmoidLayer(6) batchNormalizationLayer dropoutLayer(0.1) fulllyconnectedlayer (numNodes) BiasedSigmoidLayer(0) regressionLayer];

为网络指定培训选项。集MaxEpochs3.这样网络对训练数据进行了三次传递。集MiniBatchSize64所以网络在看64每次训练信号。集情节训练进步生成随迭代次数增加而显示训练进度的图。集详细的禁用将与图中显示的数据相对应的表输出打印到命令行窗口。集洗牌every-epoch在每个历元的开始打乱训练序列。集LearnRateSchedule分段每经过一定的代数(1)时,将学习率降低指定的系数(0.1)。集ValidationData到验证预测器和目标。集ValidationFrequency使验证均方误差在每个历元计算一次。本例使用自适应力矩估计(ADAM)求解器。

maxEpochs = 3;miniBatchSize = 64;选择= trainingOptions (“亚当”...MaxEpochs = MaxEpochs,...MiniBatchSize = MiniBatchSize,...SequenceLength =“最长”...洗牌=“every-epoch”...Verbose = 0,...情节=“训练进步”...ValidationFrequency =地板(大小(mixSequencesT 4) / miniBatchSize),...ValidationData = {mixSequencesV, maskSequencesV},...LearnRateSchedule =“分段”...LearnRateDropFactor = 0.9,...LearnRateDropPeriod = 1);

训练深度学习网络

使用指定的训练选项和层架构训练网络trainNetwork.由于训练集很大,训练过程可能需要几分钟。要加载预先训练的网络,请设置speedupExample真正的

speedupExample =如果trainNetwork(mixSequencesT,maskSequencesT,layers,options);其他的s =负载(fullfile(数据集,“CocktailPartyNet.mat”));CocktailPartyNet = s.CocktailPartyNet;结束

将验证预测器传递给网络。输出是估计的掩码。重塑估计的面具。

estimatedMasks0 =预测(CocktailPartyNet mixSequencesV);estimatedMasks0 = estimatedMasks0。”;estimatedMasks0 =重塑(estimatedMasks0,1 + fftLength/2, numl (estimatedMasks0)/(1 + fftLength/2));

评估深度学习网络

绘制实际掩码和预期掩码之间误差的直方图。

图(8)直方图(maskValSequences(:) - estimatedMasks0(:),EdgeColor= .“没有”归一化=“pdf”)包含(“面具错误”) ylabel (“概率密度”

软掩码估计

估计男性和女性的软口罩。通过阈值软掩码来估计男性和女性二进制掩码。

SoftMaleMask = estimatedMasks0;SoftFemaleMask = 1 - SoftMaleMask;

缩短混合STFT以匹配估计掩模的大小。

P_Val_mix0 = P_Val_mix0(:, 1:尺寸(SoftMaleMask 2));

将混合STFT乘以男性软掩模得到估计的男性语音STFT。

P_Male = P_Val_mix0。* SoftMaleMask;

使用ISTFT得到估计的男性音频信号。音频。

maleSpeech_est_soft = istft (P_Male窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”, ConjugateSymmetric = true);maleSpeech_est_soft = maleSpeech_est_soft / max (abs (maleSpeech_est_soft));

确定要分析的范围和相关的时间向量。

范围= windowLength:元素个数(maleSpeech_est_soft) -windowLength;t = * (1 / Fs);

可视化估计和原始的男性语音信号。听听估计软面具男讲话。

声音(maleSpeech_est_soft(范围),Fs)图(9)tiledlayout(2,1) nexttile plot(t,mSpeechValidate(范围))title(“原来男性演讲》)包含(“时间(s)”网格)nexttile情节(t, maleSpeech_est_soft(范围)包含(“时间(s)”)标题(“估计男性讲话(软面具)”网格)

将混合STFT乘以女性软掩模得到估计的女性语音STFT。使用ISTFT得到估计的男性音频信号。音频。

P_Female = P_Val_mix0。* SoftFemaleMask;femaleSpeech_est_soft = istft (P_Female窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”, ConjugateSymmetric = true);femaleSpeech_est_soft = femaleSpeech_est_soft / max (femaleSpeech_est_soft);

可视化估计和原始的女性信号。听一听估计的女性讲话。

声音(femaleSpeech_est_soft(范围),Fs)图(10)tiledlayout(2,1) nexttile plot(t,fSpeechValidate(范围))title(“原始女性讲话”网格)nexttile情节(t, femaleSpeech_est_soft(范围)包含(“时间(s)”)标题(《估计女性讲话(软面具)》网格)

二值掩码估计

通过阈值软掩码来估计男性和女性二进制掩码。

HardMaleMask = SoftMaleMask >= 0.5;HardFemaleMask = SoftMaleMask < 0.5;

将混合STFT乘以男性二进制掩码得到估计的男性语音STFT。使用ISTFT得到估计的男性音频信号。音频。

P_Male = P_Val_mix0。* HardMaleMask;maleSpeech_est_hard = istft (P_Male窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”, ConjugateSymmetric = true);maleSpeech_est_hard = maleSpeech_est_hard / max (maleSpeech_est_hard);

可视化估计和原始的男性语音信号。听估计的二进制掩码男性语音。

sound(maleSpeech_est_hard(range),Fs) figure(11) tiledlayout(2,1) nexttile plot(t,mSpeechValidate(range)) title(“原来男性演讲》网格)nexttile情节(t, maleSpeech_est_hard(范围)包含(“时间(s)”)标题(估计男性语音(二元掩码)网格)

将混合STFT乘以女性二进制掩码得到估计的男性语音STFT。使用ISTFT得到估计的男性音频信号。音频。

P_Female = P_Val_mix0。* HardFemaleMask;femaleSpeech_est_hard = istft (P_Female窗口=赢,OverlapLength = OverlapLength FFTLength = FFTLength FrequencyRange =“单向的”, ConjugateSymmetric = true);femaleSpeech_est_hard = femaleSpeech_est_hard / max (femaleSpeech_est_hard);

可视化估计和原始的女性语音信号。听一听估计的女性讲话。

sound(femaleSpeech_est_hard(range),Fs) figure(12) tiledlayout(2,1) nexttile plot(t,fSpeechValidate(range)) title(“原始女性讲话”网格)nexttile情节(t, femaleSpeech_est_hard(范围)标题(估计女性语音(二元掩码)网格)

分别比较混合,原雌和雄,估计雌和雄一秒段的STFTs。

= 7 e4:7.4e4范围;图(13)stft (mixValidate(范围),Fs,窗口=赢,OverlapLength = 64, FFTLength = FFTLength FrequencyRange =“单向的”);标题(“混合STFT”

图(14)tiledlayout(3,1) nexttile stft(mSpeechValidate(range),Fs,Window=win,OverlapLength=64,FFTLength= FFTLength,FrequencyRange=“单向的”);标题(“男性STFT(实际)”) nexttile stft (maleSpeech_est_soft(范围),Fs,窗口=赢,OverlapLength = 64, FFTLength = FFTLength FrequencyRange =“单向的”);标题(男性STFT(估计-软面具)) nexttile stft (maleSpeech_est_hard(范围),Fs,窗口=赢,OverlapLength = 64, FFTLength = FFTLength FrequencyRange =“单向的”);标题(男性STFT(估计-二进制掩码));

图(15)tiledlayout(3,1) nexttile stft(fspeech hvalidate (range),Fs,Window=win,OverlapLength=64,FFTLength= FFTLength,FrequencyRange=“单向的”);标题(“女性STFT(实际)”) nexttile stft (femaleSpeech_est_soft(范围),Fs,窗口=赢,OverlapLength = 64, FFTLength = FFTLength FrequencyRange =“单向的”);标题(“女性STFT(估计-软面具)”) nexttile stft (femaleSpeech_est_hard(范围),Fs,窗口=赢,OverlapLength = 64, FFTLength = FFTLength FrequencyRange =“单向的”);标题(女性STFT(估计-二进制掩码)

参考文献

[1]“卷积深度神经网络中的概率二元掩模鸡尾酒会源分离”,安德鲁·j·r·辛普森,2015。

Baidu
map