【问题标题】:Available formats of the Voice Processing Unit on mac os xmac os x 上语音处理单元的可用格式
【发布时间】:2013-08-22 14:09:29
【问题描述】:

我在 mac os x 上使用 vpio 音频单元进行捕获和播放。

一切顺利,直到我在 vpio 单元上设置输入/输出格式。

我想要的格式是这样的:

AudioStreamBasicDescription audio_format ;
audio_format.mSampleRate     = 8000.0 ;
audio_format.mBitsPerChannel     = 16 ;
audio_format.mChannelsPerFrame = 1 ;
audio_format.mBytesPerFrame      = (audio_format.mBitsPerChannel >> 3)  * audio_format.mChannelsPerFrame ;
audio_format.mFramesPerPacket    = 1 ;
audio_format.mBytesPerPacket     = audio_format.mBytesPerFrame * audio_format.mFramesPerPacket ;
audio_format.mFormatID       = kAudioFormatLlinearPCM ;
audio_format.mFormatFlags    = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked ;

我可以在 vpio 的(输入总线/输出范围)上设置这种格式,但我不能在 vpio 的(输出总线/输入范围)上设置它 我会得到错误代码(kAudioUnitErr_FormatNotSupported)。 但是当我改用AUHAL unit 时,我可以同时设置格式 在 AUHAL(输入总线/输出范围)和 AUHAL(输出总线/输入范围)上。

我想知道这两个单元之间的区别是什么?

经过一番尝试,我终于在vpio的(输出总线/输入范围)上找到了一种可用的格式,就像这样:

AudioStreamBasicDescription audio_format ;
audio_format.mSampleRate     = 8000.0 ;
audio_format.mBitsPerChannel     = 32 ;
audio_format.mChannelsPerFrame   = 1 ;
audio_format.mBytesPerFrame      = (audio_format.mBitsPerChannel >> 3)  * audio_format.mChannelsPerFrame ;
audio_format.mFramesPerPacket    = 1 ;
audio_format.mBytesPerPacket     = audio_format.mBytesPerFrame * audio_format.mFramesPerPacket ;
audio_format.mFormatID       = kAudioFormatLlinearPCM ;
audio_format.mFormatFlags    = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked ;

但让我感到困惑的是 vpio 的(输入总线/输出范围)和(输出总线/输入范围)上的格式不匹配。我想知道如何获得the available formats information of the vpio unit?我在 Apple 网站上找不到任何有关可用格式的文档。

有人可以回答我的问题吗?

感谢和尊重。

【问题讨论】:

    标签: macos core-audio audiounit


    【解决方案1】:

    我刚刚找到了一个聪明的工程师来解决这个 VoiceProcessing 音频单元:

    How to use "kAudioUnitSubType_VoiceProcessingIO" subtype of core audio API in mac os?

    简短的回答是:在初始化单元之前设置格式。多么直观!

    【讨论】:

      【解决方案2】:

      我和你有同样的问题。当我尝试将音频格式设置为语音处理音频单元时,我收到错误 -10865,这意味着音频格式属性不可写。

      如果我理解正确,您无法在此音频单元上设置任何格式。如果您需要 8000 Hz 采样率的音频,则需要重新采样。

      可以的

      1. 通过创建音频单元图并在语音处理单元前面添加Converter Audio Unit
      2. 通过使用外部库(例如 ffmpeg 中的 swresample)重新采样音频

      祝你发展顺利。

      【讨论】:

        【解决方案3】:

        我使用以下设置来获得最佳文件大小和音质,以便在我的项目中录制语音。

          // Setup audio session
            AVAudioSession *session = [AVAudioSession sharedInstance];
            [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
        
            // Define the recorder setting
            NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
        
            [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
            [recordSetting setValue:[NSNumber numberWithFloat:8000.0] forKey:AVSampleRateKey];
            [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
            [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey];
        
           // Initiate and prepare the recorder
            recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
            recorder.delegate = self;
            recorder.meteringEnabled = YES;
            [recorder prepareToRecord];
        

        【讨论】:

        • 感谢您的回答,但这不是我想知道的。我在问如何获得语音处理 IO 单元的可用格式。
        • @JunLiu.. 听不懂... 语音处理 IO 单元... 能否请您解释一下。
        • 对不起我的英语很糟糕。语音处理IO单元是一个音频单元,它连接到mac/iOS设备的音频输入和输出,并提供语音处理功能。您可以在AUComponent中查看更多信息.h
        猜你喜欢
        • 1970-01-01
        • 2011-07-31
        • 2011-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多