【问题标题】:How to use soxlib for iOS to remove start and end silence如何使用 iOS 的 soxlib 删除开始和结束静音
【发布时间】:2013-10-09 13:14:48
【问题描述】:

任务是从录音的开始和结束按阈值去除静音。 我使用这个 sox 端口到 iOS。 https://github.com/shieldlock/SoX-iPhone-Lib/

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

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

(取自这里: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(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);

为了完成这项任务,我需要提供哪些参数?

【问题讨论】:

    标签: c++ ios objective-c sox


    【解决方案1】:

    因为sox in.wav out.wav silence 1 0.1 1% reverse silence 1 0.1 1% reverse 是两个不同命令行的串联:

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

    在你的连锁中创造两个沉默效果。一旦 effect 修剪文件的开头并将反向副本通过管道传输到 temp 目标,next 将从 temp 的开头修剪并将其反转回完成的目标。

    但是要传递什么参数 (args)?免责声明:我没有什么经验,无法对此进行测试,但我认为应该是这些字符串:

    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);
    

    【讨论】:

    • 谢谢,我会测试一下
    • @kdogisthebest 运气好吗?
    • @Thompson 沉默和反转是两个独立的效果。请看下面我的回答。还是谢谢。
    【解决方案2】:

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

    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
    

    【讨论】:

    • 很好的答案。我正在尝试使用“pad”命令。它用于添加静音。在终端中运行良好,但在代码中运行良好。你能帮我吗?
    猜你喜欢
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多