【问题标题】:Novocaine : Saved audio file does not workNovocaine:保存的音频文件不起作用
【发布时间】:2014-11-04 23:49:58
【问题描述】:

我从 Novocaine 的示例项目中输出了一个 m4a 文件。但我无法在 iTunes 中打开该文件。文件可能已损坏。

NSArray *pathComponents = [NSArray arrayWithObjects:
                               [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], 
                               @"My Recording.m4a", 
                               nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"URL: %@", outputFileURL);

self.fileWriter = [[AudioFileWriter alloc]
                   initWithAudioFileURL:outputFileURL 
                   samplingRate:self.audioManager.samplingRate
                   numChannels:self.audioManager.numInputChannels];


__block int counter = 0;
self.audioManager.inputBlock = ^(float *data, UInt32 numFrames, UInt32 numChannels) {
    [wself.fileWriter writeNewAudio:data numFrames:numFrames numChannels:numChannels];
    counter += 1;
    if (counter > 800) { // roughly 5 seconds of audio
        wself.audioManager.inputBlock = nil;
    }
};

我没有更改代码,只是删除了注释。

如果您知道可能的解决方案或建议,我想知道您是否可以分享给我。

诺卡因https://github.com/alexbw/novocaine

【问题讨论】:

    标签: ios core-audio novocaine


    【解决方案1】:

    这里讨论了这个问题: https://github.com/alexbw/novocaine/issues/59

    原始代码用这一行终止记录(在处理程序块内):

    wself.audioManager.inputBlock = nil;
    

    我通过在之后立即添加此行来使其工作:

    [wself.fileWriter stop];
    

    AudioFileWriter的stop方法是私有的,所以也需要添加到public接口中。

    【讨论】:

    • 太棒了!谢谢)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    相关资源
    最近更新 更多