1

iPhoneのBluetoothヘッドセットからの録音入力で使用されるコードを試しましたが 、これらのコードでは音声を録音できますが、Bluetoothデバイスのマイクからは録音できません。pl zは私を助けてくれます。

 // 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];
}
4

1 に答える 1

0

はい、上記の概念は正しく、私にとって非常に役立ちます(ただし、追加または変更はほとんど行われていません)が、スピーカー(デバイススピーカー)へのルーティングには新しいセッションを作成する必要がありました

Bluetooth から入力を取得するために、次のようなセッションを作成します

    //// 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);

そして、その時点でBluetoothデバイススピーカーにないサウンドを再生したいときはいつでも、新しく作成されたセッションでセッションをオーバーライドします

- (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

}

于 2013-08-23T05:03:48.883 に答える