2013-08-14 16 views
6

Bluetooth kulaklığından gelen sesi kaydetmem ve varsayılan iPhone hoparlörü ile çalmam gereken bir projem var. Çok fazla aradım ve bu kodu aldım.kayıt girişi iPhone

UInt32 allowBluetoothInput = 1; 

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

------------ SES KAYIT BAŞLANGIÇ İÇİN KOD VE

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

------------ DUR ve ben avaudiorecorder kullanarak duyuyorum bundan sonra. Burada eksik olduğum başka bir şey var gibi görünüyor.

-------- ses kaydedici için kod ---------

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

Ben burada eklenecek ihtiyacı olan başka bir şey eksik düşünüyorum. Ben sadece bluetooth kulaklık giriş sesini istiyorum. Herhangi bir yardım takdir edilecektir.

Teşekkürler!

+0

merhaba @Swati, yaptığınız işlevsellik hakkında bilgi sahibi olmalı. Lütfen çevrimiçi olduğunuzda bana yorum yapalım. –

+0

evet lütfen. bugün bugün pazartesi swati'ye sahip olan – Swati

+0

'a sor. Eğer çevrimiçi olduğunuzda timd varsa –

cevap

3

ben sadece sorununuzu inceleyebilir ve Körük kodu ile denemek istiyorum güzel cevabı bir şey var: -

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

Kredi Kodunuza ses oturumu eklemek This

+0

bu gerçekten işe yaradı. Teşekkürler .. Ama ben kayıt çalarken ses çıkışı da bluetooth cihazına gider. Ben cihaz hoparlöründe istiyorum. Bu yapılabilir mi? – Swati

+0

Bu iki satırı ekleyin ve yardım edin AudioServicesCreateSystemSoundID (soundFileURLRef, & soundFileObject) yardımcı olur; AudioServicesPlaySystemSound (soundFileObject); –

+0

Bu iki satırı tam olarak nereye eklemeliyim? Bu soundFileURLRef = CFBundleCopyResourceURL – Swati

0

gider

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

bunu eklemek oynadığımızda hiçbir şey oynamıyor – Swati

+0

dinlenme kodu kodunuzla aynı ben sadece size ses oturumu gönderdim –