5
$\begingroup$

I have some audios that contain short spaces of silence with different periods of time.

Looking for information, I found this question.

The audio example is this.

Is there a way the program can do the following sequence below?

1 - Identify periods of silence

2 - Measure the silence period in seconds

3 - Convert all periods of silence to 1 second

a = Audio@"https://wolfr.am/mSeG89Up";
Column[{AudioPlot@a, AudioPlot@AudioTrim@a}]
$\endgroup$
13
$\begingroup$

Import the subject audio:

aud = Import["http://home.ustc.edu.cn/~xiaozh/SE/del_silences.wav"]

Identify silences:

silences = AudioIntervals[aud, #RMSAmplitude < 0.005 &];

Split the Audio object at the identified beginning and ends of the silence:

splitAuds = AudioSplit[aud, Flatten[silences]];

Lengthen the silences (by replacing them with silence of the correct length - there's no need to waste computation for AudioTimeStretch if we know we want silence):

lengthenedSilences = MapIndexed[If[OddQ[#2[[1]]], 
  Audio[ConstantArray[0., QuantityMagnitude[AudioSampleRate[aud]]], 
    SampleRate -> AudioSampleRate[aud]],#1] &, splitAuds];

*Note that I'm using the nice alternating pattern of noise and silence to decide what to replace.

Now reassemble the Audio object:

result = AudioJoin[lengthenedSilences]

*You can of course play with the threshold used at the beginning to better define what "silence" is.

$\endgroup$
  • $\begingroup$ It was fantastic. I just updated your answer by refining the RMSAmplitude value. I did this because some breathing pauses should not be changed. With this refinement, I successfully achieved my goals. I was very happy with your help. $\endgroup$ – LCarvalho Nov 24 '17 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.