1
$\begingroup$

I have an audio file named del_silences.wav. I want to delete the silence intervals. But using AudioTrim, the audio almost has no change:

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

enter image description here

But I want to delete the red region:

enter image description here

So how to delete the silence intervals that start and end in audio file?

Ps:I define this function,but it has some limits

myAudioTrim[audio_, val_] := Module[{interval = AudioIntervals[audio, #RMSAmplitude < val &]}, 
    If[Length[interval] >= 2, 
       AudioTrim[audio, Flatten[interval[[{1, -1}]]][[2 ;; -2]]], 
       AudioTrim[audio, {interval[[1, 2]], Duration@audio}]]]

a = Audio@"https://wolfr.am/mSeG89Up";
AudioPlot@myAudioTrim[a, 0.01]

enter image description here

But it has problem,for example:

mono = AudioPad[AudioGenerator["Sin", .1], {0.05, 0}];
AudioPlot[mono]
AudioPlot@myAudioTrim[mono, 0.01]

enter image description here

It doesn't delete all the silence.Then I find the problem is the AudioIntervals:

AudioIntervals[AudioPad[AudioGenerator["Sin", .1], {0.05, 0}], #RMSAmplitude < 0.01 &]

{{0., 0.02322}}
expect {{0.,0.05}}

AudioIntervals[AudioPad[AudioGenerator["Sin", .01], {0.005, 0}], #RMSAmplitude < 0.01 &]

{}
expect {{0.,0.005}}

even using PartitionGranularity it can not get the result.

AudioIntervals[AudioPad[AudioGenerator["Sin", .01], {0.005, 0}], 
               #RMSAmplitude < 0.01 &, 
               PartitionGranularity -> Quantity[0.1, "Milliseconds"]]
(*{}*)

What happened,how to improve this function?

$\endgroup$
  • $\begingroup$ What's wrong with running AudioPlot@AudioTrim[data, {1.1, 9.9}]? $\endgroup$ – Feyre Oct 30 '16 at 9:04
  • $\begingroup$ You can identify the silences using AudioIntervals (which can take a volume threshold), and use the output in AudioTrim. $\endgroup$ – Szabolcs Oct 30 '16 at 9:49
  • $\begingroup$ @Szabolcs Yeah,I got it.Thank you for your suggestion. $\endgroup$ – partida Oct 30 '16 at 9:52
3
$\begingroup$

we can define a function:

myAudioTrim[audio_, val_] := AudioTrim[audio, Flatten[
AudioIntervals[audio, #RMSAmplitude < val &][[{1, -1}]]][[2 ;; -2]]]

And then,we can plot the result:

a = Audio@"E:\\test.wav"; 
AudioPlot@myAudioTrim[a, 0.01]

enter image description here

$\endgroup$

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.