我有一个项目,我必须录制来自蓝牙耳机的声音并使用默认的 iPhone 扬声器播放。我已经搜索了很多并得到了这个代码。
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);
------------ 录音机启动和停止代码 ------------
- (IBAction)Record: (id)sender
{
UIButton *btn = (UIButton *)sender;
if([btn isSelected])
{
[audioRecorder stop];
[btn setSelected:NO];
[btn setTitle:@"Start Recording" forState:UIControlStateNormal];
}
else
{
[audioRecorder record];
[btn setSelected:YES];
[btn setTitle:@"Stop Recording" forState:UIControlStateNormal];
}
}
之后我正在使用avaudiorecorder。我在这里似乎还缺少其他东西。
-------- 录音机代码 ---------
NSURL *soundFileURL = [NSURL fileURLWithPath:AUDIO_FILE];
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)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[audioRecorder prepareToRecord];
}
我想我错过了需要在此处添加的其他内容。我只想要蓝牙耳机输入音频。任何帮助,将不胜感激。
提前致谢!!