如何将iPhone的麦克风中的音频流式传输到Mac / PC?是否已有一些框架,或者我可以通过套接字发送音频。我虽然是新的插座。基本上,我希望能够对着iPhone说话,并且计算机将接收iPhone的麦克风输入作为自己的麦克风输入,用于没有麦克风的计算机。我已经有一个应用程序与Mac连接,它运行一个非常简单的服务器,iPhone可以将文本发送到计算机,但iPhone如何从麦克风发送音频,现场音频到它?
答案 0 :(得分: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]];
}