我有如下所示的设置。
我想在录制音频时将音频录制设置更改为 16Khz 和 16 位。
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir
stringByAppendingPathComponent:@"sound.wav"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
} else
{
[audioRecorder prepareToRecord];
}
如何设置这些设置?
编辑问题:
感谢您的回复,我尝试了这些方法,但它对我不起作用,因为我的客户正在将录制的语音(我以字节格式发送的录制的语音)发送到 ASR 引擎(自动语音识别)。我没有收到我发送的相同回复(我收到的回复音频显示“引号”)。客户说您没有以 16KHz 和 16 位采样率录制声音,这就是您得到响应的原因。但是我问他我发送到他的服务器的字节,他给了那个 .wav 文件,它正在完美地播放。但是如果他发送给 ASR 引擎的同一个,ASR 引擎不接受我发送的录制的声音(他说 ASR 不会接受,因为你没有以 16KHz 和 16 位采样率录制音频)。客户给出以下响应。(但,
Filename: sv_SE_356985580762248932.wav
Folder: E:\developApp\TestappName\Mortionsn_dev\2nd-iteration\test_wfiles
File Type: 44100Hz, 16-bit, Stereo
Uncompressed Size: 1.63 MB (1,713,696 bytes)
File Format: Windows PCM
Windows PCM
Size on Disk: 1.63 MB (1,717,892 bytes)
Last Written (local): 3/11/2013 00:21:00.000
Length: 0:09.714
428,424 samples
使用以下答案第二次编辑问题:
后来通过提出建议,我将设置代码更改为:
NSMutableDictionary *recordSettings = [NSMutableDictionary dictionary];
[recordSettings setValue: [NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSettings setValue: [NSNumber numberWithFloat:16000.0] forKey:AVSampleRateKey];//8000.0
[recordSettings setValue: [NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSettings setValue: [NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSettings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
[recordSettings setValue: [NSNumber numberWithInt: AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];