录制音频时如何将录音设置更改为16Khz和16位? [英] How to change audio recording settings to 16Khz and 16 bit when we record audio?
问题描述
我有如下所示的设置.
我想在录制音频时将音频录制设置更改为16Khz和16位.
I want change audio recording settings to 16Khz and 16 bit when we record audio.
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位采样率录制音频).客户给出了以下回应. (但是,我尝试了您提出的所有建议)
Thanks for giving the replies, i tried those ways but it did not work for me, Because my client is sending the recorded voice(the recorded voice what i am sending in bytes format) to ASR engine (Automatic speech recognition). i am not getting back the same response (i am getting the response audio says "quotation mark") what i send . Client says you are not recording the voice in 16KHz and 16 bit sample rate thats why you are getting that response. But i asked him the bytes what i send to his server, He given that .wav file it is playing perfectly. But if the same one he is sending to ASR engine , the ASR engine not accepts the recorded voice what i am sending(He says that ASR wont accept because you are not recording audio in 16KHz and 16 bit sample rate). Client given the following response. (But, I tried all the ways suggested by you)
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
使用以下答案第二次编辑问题:
稍后提供建议,我将我的设置代码更改为:
Later by giving the suggestions i changed my settings code to:
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];
推荐答案
您现有的设置为44.1kHz和16位,因此(假设以上内容已经有效),您唯一需要更改的行是:
Your existing settings are 44.1kHz and 16 bit so (assuming the above already works) the only line you'd need to change is:
[NSNumber numberWithFloat:44100.0]
收件人:
[NSNumber numberWithFloat:16000.0]
这篇关于录制音频时如何将录音设置更改为16Khz和16位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!