attenuate part of the audio

3 次查看(过去 30 天)
Sofía García
Sofía García 2021-1-11
I have a very important job for this Friday and at work I have to mix two audios and for this I have to attenuate the last second of the first audio and increase the first second of the second audio. Can someone tell me what function / code I have to use?

回答(1 个)

Mathieu NOE
Mathieu NOE 2021-1-11
hello Sofia
here some example below :
%% example 1 : fading out the last 1 second of the wav file
[Y1,Fs]=audioread('demo.wav'); %
Y1 = Y1(:); % make sure the vector is column oriented
samples = length(Y1);
time_fade_out = 1; % in seconds
ind = samples+1-time_fade_out*Fs:samples; % samples index of the last second of the wav file
% let's do a progressive linear fade out
gain = linspace(1,0,length(ind));
gain = gain(:); % make sure the vector is column oriented
% apply this gain on the last section of the file data
Y1(ind) = Y1(ind).*gain; % ! dot product
figure, plot(Y1);
%% example 2 : fading in the first 1 second of the wav file
[Y1,Fs]=audioread('demo.wav'); %
Y1 = Y1(:); % make sure the vector is column oriented
samples = length(Y1);
time_fade_in = 1; % in seconds
ind = 1:time_fade_in*Fs; % samples index of the first second of the wav file
% let's do a progressive linear fade in
gain = linspace(0,1,length(ind));
gain = gain(:); % make sure the vector is column oriented
% apply this gain on the last section of the file data
Y1(ind) = Y1(ind).*gain; % ! dot product
figure, plot(Y1);

类别

Help CenterFile Exchange 中查找有关 Speech Recognition 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by