记录输入从iPhone蓝牙耳机来 [英] record input coming from bluetooth headset in iPhone

查看:148
本文介绍了记录输入从iPhone蓝牙耳机来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目中,我有记录从蓝牙耳机传来的声音,并默认iPhone扬声器播放。我寻觅了很多,得到这个code。

I have a project in which I have to record the voice coming from bluetooth headset and play with default iPhone speaker. I have searched a lot and got this code.

UInt32 allowBluetoothInput = 1;

    AudioSessionSetProperty (
                             kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                             sizeof (allowBluetoothInput),
                             &allowBluetoothInput
                             );

------------ code。对于录音机启动和停止------------

------------ CODE FOR AUDIO RECORDER START AND STOP ------------

- (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。似乎有别的东西我很想念这里。

and i am using avaudiorecorder after this. There seems to be something else I am missing in here.

-------- code音频录音机---------

-------- Code for audio recorder ---------

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

我觉得我失去了别的一些东西,需要在这里添加。我只想蓝牙耳机输入音频。任何帮助将是AP preciated。

I think i am missing something else which needs to be added here. I just want the bluetooth headset input audio. Any help would be appreciated.

先谢谢了!

推荐答案

我只是检查您的问题,并得到了你想要尝试与娄code很好的回答了一句: -

i just review your issue and got nice answer something you want try with Bellow code:-

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

幸得<一个href=\"http://stackoverflow.com/questions/2375837/how-to-route-iphone-audio-to-the-bluetooth-headset\">This

这篇关于记录输入从iPhone蓝牙耳机来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆