2012-03-22 52 views
8

如何將音頻從iPhone的麥克風傳輸到Mac/PC?是否已經有一些框架,或者我可以通過套接字發送音頻。儘管我對套接字很陌生。基本上,我希望能夠對iPhone說話,並且計算機將接收iPhone的麥克風輸入作爲自己的麥克風輸入,用於沒有麥克風的計算機。我已經有了一個應用程序,它可以連接到運行非常簡單的服務器的Mac,而iPhone可以將文本發送到計算機,但iPhone如何從麥克風發送音頻,現場音頻到它?如何通過套接字或框架將音頻從iPhone的麥克風傳輸到Mac/PC?

回答

4

您需要AVCaptureSession和AVCaptureDevice的組合才能從麥克風讀取 - 請參閱AV Foundation編程指南。 http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureAudioDataOutput_Class/Reference/Reference.html#//apple_ref/occ/cl/AVCaptureAudioDataOutput

對於鏈接使用sokets

@interface Client : NSObject { 
    NSInputStream *_inputStream; 
    NSOutputStream *_outputStream; 
} 

@implementation Client 

- (void)initNetworkCommunication { 
    CFReadStreamRef readStream; 
    CFWriteStreamRef writeStream; 
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 50000, &readStream, &writeStream); 

    _inputStream = (__bridge NSInputStream *)readStream; 
    _outputStream = (__bridge NSOutputStream *)writeStream; 

    [_inputStream setDelegate:self]; 
    [_outputStream setDelegate:self]; 

    [_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
    [_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 

    [_inputStream open]; 
    [_outputStream open]; 
} 

// send data to server 


- (IBAction)onSendButtonTapped:(id)sender { 
    NSString *command = self.commandField.text; 
    NSData *data = [[NSData alloc] initWithData:[command dataUsingEncoding:NSUTF8StringEncoding]]; 
    [_outputStream write:[data bytes] maxLength:[data length]]; 
} 
相關問題