noise reduction of voice sample
20 ビュー (過去 30 日間)
古いコメントを表示
I have a voice samples. i will try to reduce the noises but my code is not working.
% Load the audio file
[y, Fs] = audioread('voice_sample.wav');
% Perform spectral subtraction
y_clean = spectralSubtraction(y, Fs);
% Write the cleaned audio to a new file
audiowrite('voice_sample_cleaned.wav', y_clean, Fs);
% Function for spectral subtraction
function y_clean = spectralSubtraction(y, Fs)
% Compute the short-time Fourier transform (STFT) of the audio signal
win_size = round(0.03*Fs); % Window size of 30ms
hop_size = round(0.01*Fs); % Hop size of 10ms
nfft = 2^nextpow2(win_size); % Number of FFT points
[S, f, t] = spectrogram(y, win_size, hop_size, nfft, Fs);
% Compute the power spectrum of the noisy speech
Pyy = abs(S).^2;
% Compute the power spectrum of the noise
noise_start = 1; % Starting frequency bin of the noise
noise_end = round(2000 / (Fs/nfft)); % Ending frequency bin of the noise (assumed to be below 2 kHz)
Pnn = mean(Pyy(:,noise_start:noise_end), 2);
% Compute the power spectrum of the speech
Pyy_est = max(Pyy - Pnn, 0);
% Reconstruct the cleaned audio signal
y_clean = real(ifft(S .* sqrt(Pyy_est ./ Pyy), 'symmetric'));
end
0 件のコメント
回答 (1 件)
Drishti
2024 年 10 月 11 日
Hi Sanusha,
I understand that you are trying to reduce noise from the audio signal, but the provided code is not working.
On debugging the code, I found that ‘y_clean’ variable is of dimension ‘1024 x 1147’ which signifies that ‘1147’ audio channels are present in the provided audio signal.
After referring to the MathWorks Documentation of ‘audiowrite’ function, I discovered that ‘audiowrite’ function does not support large number of audio channels like ‘1147’, hence the provided code throws an error as ‘Unsupported number of channels.’
For more information, you can refer to the MATLAB Documentation of ‘audiowrite’ function.
This issue can be resolved by converting the ‘y_clean’ channel into mono channel form by averaging the channels to maintain the balance of all available channels.
You can refer to the implementation below for better understanding:
% Ensure y_clean is a column vector if the input is mono
if size(y_clean, 2) > 1
y_clean = mean(y_clean, 2);
end
I hope this resolves the issue.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Audio Processing Algorithm Design についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!