Allow to control Opus bitrate
Originator: | uson1x | ||
Number: | rdar://49315600 | Date Originated: | March 27 2019 |
Status: | Closed | Resolved: | |
Product: | AVFoundation | Product Version: | iOS 12.1, Xcode 10.1 |
Classification: | Suggestion | Reproducible: |
We are trying to achieve the following: Use AVAudioRecorder to record far-field speech in kAudioFormatOpus format, with 16000 Hz sample rate and resulting bitrate >= 32 kb/s. The bitrate is important for speech recognition, as the quality of recognition depends on it (https://www.researchgate.net/figure/Clean-speech-MOS-scores-with-increasing-bitrate-in-kbit-s_fig3_282605143). Unfrotunately, there is no way to control the bitrate when format is kAudioFormatOpus. AVEncoderBitRateKey, AVEncoderBitRateStrategyKey don't seem to have any effect on bitrate at all. Constant bitrate is not supported and I was not able to find a way to increase quality of Variable Bit Rate so that ffprobe bitrate is reported as >=32kb/s. My request to Apple Developer Technical Support ended up in confirming that there is no way to control bitrate for Opus (DTS ticket #711096424). STEPS TO REPRODUCE 1. Initialize AVAudioRecorder let recordSettings = [AVEncoderBitRateKey: 32000, AVFormatIDKey: kAudioFormatOpus, AVSampleRateKey: 16000.0] as [String: Any] let recordingFormat = AVAudioFormat(settings: recordSettings)! let recorder = try AVAudioRecorder(url: url, format: recordingFormat) 2. Record audio and stop recording 3. Run `ffprobe` on the resulting file: Input #0, caf, from '/Users/ivanparfenchuk/Downloads/EF962693-6997-4851-9FA6-F6C8F4D8ED8E.caf': Duration: 00:02:14.34, start: 0.000000, bitrate: 16 kb/s Stream #0:0: Audio: opus (opus / 0x7375706F), 48000 Hz, mono, fltp 4. bitrate is 16 kb/s, when AVEncoderBitRateKey is 32000 It would be great to have more control over resulting bitrate value, be it CBR or VBR.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Turned out the initializion of AVAudioRecorder was incorrect
This is how you should initialize AVAudioRecorder if you want to set the bitrate
let recordSettings = [AVEncoderBitRateKey: 32000, AVFormatIDKey: kAudioFormatOpus, AVSampleRateKey: 16000.0] as [String: Any] let recorder = try AVAudioRecorder(url: url, settings: recordSettings)
Also, if you want to set the bitrate to be constant, add AVEncoderBitRateStrategyKey: AVAudioBitRateStrategy_Constant to the recordSettings dictionary.