can anyone tell me how to remove unvoiced or silenced region from audio file?

67 views (last 30 days)
pranjal
pranjal on 26 Dec 2014
Edited: Image Analyst on 16 Jun 2019
I have .wav file having voiced and unvoiced segments.I want to remove unvoiced part of it. so that processing time can be reduced.
  4 Comments
Image Analyst
Image Analyst on 1 Nov 2018
Find the gaps but then when you stitch the segments together, insert a few elements of zeros.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 26 Dec 2014
Edited: Image Analyst on 16 Jun 2019
See my program where I find where the envelope of the standard guitar demo file that ships with MATLAB is below 0.13 and I cut out those portions. Normal sine wave oscillation on a short time scale are retained so as to not alter the sound.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in data and plot it.
[y, Fs] = audioread('guitartune.wav');
subplot(2, 1, 1);
plot(y, 'b-');
grid on;
title('Original Signal + Envelope', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
drawnow;
% Find the envelope by taking a moving max operation, imdilate.
envelope = imdilate(abs(y), true(1501, 1));
% Plot it.
hold on;
plot(envelope, 'r-', 'LineWidth', 2);
plot(-envelope, 'r-', 'LineWidth', 2);
legend('Data', 'Envelope');
% Save the x axis length so we can apply it to the edit plot
% so they are displayed on the same time frame
% So we can see how it got shorter.
xl = xlim();
% Find the quiet parts.
quietParts = envelope < 0.13; % Or whatever value you want.
% Cut out quiet parts and plot.
yEdited = y; % Initialize
yEdited(quietParts) = [];
subplot(2, 1, 2);
plot(yEdited, 'b-', 'LineWidth', 2);
title('Edited Signal, shorter because data was removed', 'FontSize', fontSize);
grid on;
% Make it plot over the same time range as the original
xlim(xl);
  5 Comments
Image Analyst
Image Analyst on 14 May 2016
It was probably trial and error until a value was found that worked well. By the way, there is now an envelope() function in the Signal Processing Toolbox:
[yupper,ylower] = envelope(x) returns the upper and lower envelopes of the input sequence, x, as the magnitude of its analytic signal. The analytic signal of x is found using the discrete Fourier transform as implemented in hilbert. The function initially removes the mean of x and adds it back after computing the envelopes. If x is a matrix, then envelope operates independently over each column of x.
There is also a movmax() function that is like imdilate() in that it takes the max in a moving window.

Sign in to comment.

More Answers (1)

Chad Greene
Chad Greene on 26 Dec 2014
Hi Pranjal,
There are a number of ways to do this, but I cannot think of a perfect solution. The easiest way I can think of is to say the levels must exceed a certain threshold. But, you can't say each individual data point must exceed a certain threshold, you'll need to do some moving max or moving rms or moving spl. Here's a solution with moving max, using Aslak Grinsted's moving function.
First, load some data. I'm going to add a 12000 point stretch of low-volume noise in the middle:
load train
y = [y(1:4200);.01*randn(12000,1);y(4200:end)];
t = (0:length(y)-1)/Fs; % time
The sound signal looks and sounds like this:
plot(t,y,'blue')
box off; axis tight; hold on
xlabel('time (s)')
soundsc(y,Fs) % <- turn your speakers on
Now use moving to get the moving max centered over 35 data points and plot the moving maximum in red:
ymax = moving(y,35,@max);
plot(t,ymax,'red')
Now let's say we only want data whose moving max value exceeds 0.15. Create a clipped array corresponding to ymax>0.15
yclipped = y(ymax>0.15);
tclipped = (0:length(yclipped)-1)/Fs;
figure
plot(tclipped,yclipped,'b')
box off; axis tight
xlabel('time (s)')

Community Treasure Hunt

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

Start Hunting!