Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use soxlib for iOS to remove start and end silence

The task is to remove silence by threshold from the start and end of audio recording. I use this sox port to iOS. https://github.com/shieldlock/SoX-iPhone-Lib/

I've found that command line sox tool makes my task by following command:

sox in.wav out.wav silence 1 0.1 1% reverse silence 1 0.1 1% reverse

(taken from here: http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/)

but I cannot to translate it in iOS lib format like this:

sox_create_effect(sox_find_effect("silence"));
args[0] = "2000", assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);

which parameters I need to give for making this task?

like image 377
cohe4ko Avatar asked Nov 01 '22 13:11

cohe4ko


1 Answers

Since sox in.wav out.wav silence 1 0.1 1% reverse silence 1 0.1 1% reverse is a concatenation of two different command lines:

sox in.wav temp.wav silence 1 0.1 1% reverse
sox temp.wav out.wav silence 1 0.1 1% reverse

create two silence effects in your chain. Once effect trims the beginning of the file and pipes a reversed copy to a temp destination, and the next trims from the beginning of the temp and reverses it back to the finished destination.

But what arguments to pass (args)? DISCLAIMER: I have little experience and cannot test this, but I believe it should be these strings:

args[1] = "1";
args[2] = "0.1";
args[3] = "1%";
args[4] = "reverse";

e = sox_create_effect(sox_find_effect("silence"));
args[0] = "2000", assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &inFile->signal, &tempFile->signal) == SOX_SUCCESS);
free(e);

e = sox_create_effect(sox_find_effect("silence"));
args[0] = "2000", assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &tempFile->signal, &outFile->signal) == SOX_SUCCESS);
free(e);

sox_flow_effects(chain, NULL, NULL);
like image 182
Thompson Avatar answered Nov 09 '22 23:11

Thompson