2013-08-22 93 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 

}

相關問題