2013-08-22 64 views
1

我曾尝试使用的代码 record input coming from bluetooth headset in iPhone 虽然与这些代码我能够记录声音,但不能从蓝牙设备mic.its从设备(iphone )麦克风 我将如何将录制的声音发送给演讲者。 PLž帮助我和任何帮助赞赏如何记录从蓝牙设备麦克风的声音和在设备扬声器播放

// create and set up the audio session 
    AVAudioSession* audioSession = [AVAudioSession sharedInstance]; 
    [audioSession setDelegate:self]; 
    [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil]; 
    [audioSession setActive: YES error: nil]; 

// set up for bluetooth microphone input 
UInt32 allowBluetoothInput = 1; 
OSStatus stat = AudioSessionSetProperty (
         kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, 
         sizeof (allowBluetoothInput), 
         &allowBluetoothInput 
         ); 
NSLog(@"status = %x", stat); // problem if this is not zero 

// check the audio route 
UInt32 size = sizeof(CFStringRef); 
CFStringRef route; 
OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route); 
NSLog(@"route = %@", route);  
// if bluetooth headset connected, should be "HeadsetBT" 
// if not connected, will be "ReceiverAndMicrophone" 

// now, play a quick sound we put in the bundle (bomb.wav) 
CFBundleRef mainBundle = CFBundleGetMainBundle(); 
CFURLRef  soundFileURLRef; 
SystemSoundID soundFileObject; 
soundFileURLRef = CFBundleCopyResourceURL (mainBundle,CFSTR ("bomb"),CFSTR ("wav"),NULL); 

NSError *error = nil; 

audioRecorder = [[AVAudioRecorder alloc] 
       initWithURL:soundFileURLRef 
       settings:recordSettings 
       error:&error]; 
if (error) 
{ 
    NSLog(@"error: %@", [error localizedDescription]); 
} else { 
    [audioRecorder prepareToRecord]; 
} 

回答

0

是上述概念是正确的,对我来说非常有帮助的(但做了一点补充或修改),但路由到扬声器(设备扬声器)需要新的会话创建

采取从蓝牙输入我们有像

//// create and set up the audio session 
AVAudioSession* audioSession = [AVAudioSession sharedInstance]; 
[audioSession setDelegate:self]; 
[audioSession setCategory: AVAudioSessionCategoryRecord error: nil]; 
[audioSession setActive: YES error: nil]; 

// set up for bluetooth microphone input 
UInt32 allowBluetoothInput = 1; 
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,sizeof (allowBluetoothInput),&allowBluetoothInput); 

,并当过ü要在那个时候不发青的声音BluetoothDevice类扬声器覆盖会话使用newily创建会话建立一个

- (IBAction)playAudio:(id)sender { 



[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; 
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride); 




UInt32 size = sizeof(CFStringRef); 
CFStringRef route; 
OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route); 
NSLog(@"route = %@", route); 
    //here u can diffrent route set up based on session audiosessionid 

}

相关问题