如何使用iOS的soxlib删除开始和结束静音 [英] How to use soxlib for iOS to remove start and end silence

查看:143
本文介绍了如何使用iOS的soxlib删除开始和结束静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务是从音频录制的开始和结束按阈值消除静音.我使用此sox端口连接到iOS. https://github.com/shieldlock/SoX-iPhone-Lib/

我发现命令行sox工具通过执行以下命令来完成任务:

  sox in.wav out.wav静音1 0.1 1%反向静音1 0.1 1%反向 

(摘自此处: http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/)

但是我不能将它翻译成iOS lib格式:

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

执行此任务需要给我哪些参数?

解决方案

Sox的文档很差.我在这里分享我的解决方案.
对于您来说,示例中的阈值可能太低.适当调整参数.(在使用C/C ++ API之前,请确保您了解Shell命令行选项.)

  char * options [10];//输入效果.有关详细信息,请参见sox的文档.//相当于静音1 0.3 0.1%反向静音1 0.3 0.1%反向"options [0] = const_cast< char *>("1");options [1] = const_cast< char *>("0.3");options [2] = const_cast< char *>("0.1%");for(int i = 0; i< 2; ++ i){//沉默1 0.3 0.1%e = sox_create_effect(sox_find_effect("silence"));if(sox_effect_options(e,3,options)!= SOX_SUCCESS){on_error("silence1效果选项错误!");}if(sox_add_effect(链,e,& in->信号,& in->信号)!= SOX_SUCCESS){on_error(添加效果错误!");}免费(e);//撤销e = sox_create_effect(sox_find_effect("reverse"));if(sox_effect_options(e,0,NULL)!= SOX_SUCCESS){on_error("silence1效果选项错误!");}if(sox_add_effect(链,e,& in->信号,& in->信号)!= SOX_SUCCESS){on_error(添加效果错误!");}免费(e);}//输出效果 

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?

解决方案

Sox's documentation is poor. I share my solution here.
The threshhold in the example may be too low for you. Adjust the parameters as appropriate. (Make sure you understand the shell command line options before you use the C/C++ API.)

char *options[10];

// input effect. See sox's documentaton for details. 

// equivalent to 'silence 1 0.3 0.1% reverse silence 1 0.3 0.1% reverse'
options[0] = const_cast<char*>("1");
options[1] = const_cast<char*>("0.3");
options[2] = const_cast<char*>("0.1%");
for(int i = 0; i < 2; ++i) {
    // silence 1 0.3 0.1% 
    e = sox_create_effect(sox_find_effect("silence"));
    if(sox_effect_options(e, 3, options) != SOX_SUCCESS) {
        on_error("silence1 effect options error!");
    }   
    if(sox_add_effect(chain, e, &in->signal, &in->signal) != SOX_SUCCESS) {
        on_error("add effect error!");
    }
    free(e);

    // reverse
    e = sox_create_effect(sox_find_effect("reverse"));
    if(sox_effect_options(e, 0, NULL) != SOX_SUCCESS) {
        on_error("silence1 effect options error!");
    }
    if(sox_add_effect(chain, e, &in->signal, &in->signal) != SOX_SUCCESS) {
        on_error("add effect error!");
    }
    free(e);
}

// output effect

这篇关于如何使用iOS的soxlib删除开始和结束静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆