views:

41

answers:

1

What's the best settings for the recorder for recording voice? What should i replace with '?' in below code?

recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue :[NSNumber numberWithInt:?] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:?] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: ?] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:?] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:?] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:?] forKey:AVLinearPCMIsFloatKey];
A: 

this should be a fine starting point for speech, considering the hardware (since this is tagged 'iphone', i am assuming that is the source).

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:12000.0f] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:1 /* mono */ ] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue:[NSNumber numberWithBool:NX_BigEndian == NXHostByteOrder()] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue:[NSNumber numberWithBool:0] forKey:AVLinearPCMIsFloatKey];

if you want to reduce the size of the file, then you may prefer to record at a higher quality, then convert to a compressed format following record.

if you have long recordings to make, then you may want to record to a compressed format (i'd avoid it otherwise because the resource demands are higher).

as it is, these may not be the best for a specific application, but a good balance between size, speed, and quality.

Justin
Error : undeclared 'NX_BigEndian','kAudioFormatLinearPCM'
SajjadZare
you're missing some `#includes`. `grep -r NX_BigEndian /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk`, and `grep -r kAudioFormatLinearPCM /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk`
Justin
Sorry, I can't understand what should i add to my app?
SajjadZare
you include the files that declare these, as returned by the `grep` commands i provided. `grep` is a popular command line utility - i pasted `grep` commands which you enter into a terminal, `grep` then tells you where these patterns are declared in the SDK. the missing includes are: `#include <CoreAudio/CoreAudioTypes.h>` and `#include <architecture/byte_order.h>`
Justin
Thank you, i use this setting but sound recorded with low quality why?
SajjadZare
you're welcome. there are multiple reasons why it could sound 'low quality', some are implementation defined. 16bit at 12kHz should be fine for voice (as a final delivery format). however, the sample rate conversion in use may not be particularly high quality. you could try increasing the sample rate to `44100.0f` - 16 bit/44.1kHz is CD quality (which is overkill for voice), then reducing the sample rate until you have found a good sample rate for your needs. it may also help to test very high values (e.g., 32 bit @ 48kHz), just so you know the highest quality audio the device is capable of.
Justin