How to record on a low sample (about 1000 Hz) on iPhone

I am writing an application for recording single-channel audio with a built-in microphone on the iPhone 6. Applications work as expected when they are configured to record at a frequency of 8000 Hz. Here is the code

// Set up audio session let session = AVAudioSession.sharedInstance() // Configure audio session do { try session.setCategory(AVAudioSessionCategoryPlayAndRecord) var recordSettings = [String:AnyObject]() recordSettings[AVFormatIDKey] = Int(kAudioFormatLinearPCM) as AnyObject // Set the sampling rate recordSettings[AVSampleRateKey] = 8000.0 as AnyObject recordSettings[AVNumberOfChannelsKey] = 1 as AnyObject recorder = try AVAudioRecorder(url: outputFileURL, settings: recordSettings) recorder?.delegate = self recorder?.isMeteringEnabled = true recorder?.prepareToRecord() return true } catch { throw Error.AVConfiguration } 

To reduce storage requirements, I would like to record at a much lower sampling rate (ideally less than 1000 Hz). If I set the sampling rate to 1000 Hz, the application is recorded at a frequency of 8000 Hz.

According to Apple documentation

The available range for the hardware sampling rate is device dependent. Usually it ranges from 8000 to 48000 hertz.

Question ... is it possible to use AVAudioSession (or another structure) for recording sound with a low sampling rate?

+5
source share
2 answers

Sound recording on iPhone is done using hardware codecs, so the available frame rates are hard-coded and cannot be changed. But if you need to have a sampling frequency of 1 kHz, you can record it at a frequency of 8 kHz, and not just over-perform the recording using the re-sampling library. Personally, I prefer to use ffmpeg for such tasks.

+6
source

I hope you know that in the niquist theorem you cannot expect very useful results from what you are trying to achieve.

That is, in addition , you only focus on low frequencies . In this case, you can use the low pass filter first. It is almost impossible to understand voices with olny frequencies below 500 Hz . It is commonly said that speech requires 3 kHz , which provides a sampling frequency of 6000 .

For an example of what you should expect, try something similar to:

 ffmpeg -i tst.mp3 -ar 1000 tst.wav 

using, for example, some vocals and listen to the result . However, you can probably reach an acceptable compromise using, for example, a sample rate of 3000.

An alternative would be to do some compression on the fly, as @manishg suggested. Since smartphones can do real-time video compression these days, this should be fully feasible with iPhone Hard and Software. But this is a completely different thing than lowering the sampling rate .

+5
source

Source: https://habr.com/ru/post/1263471/


All Articles