Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stream audio from the microphone of an iPhone to a Mac/PC via sockets or a framework?

How can I stream audio from the microphone of an iPhone to a Mac/PC? Is there already some framework for this, or can I just send audio over sockets. I'm new to sockets though. Basically, I want to be able to speak into the iPhone, and the computer will receive the iPhone's mic input as its own mic input for computers that do not have microphones. I already have an app that makes a bonjour connection to a Mac, which runs a very simple server, and the iPhone can send text to the computer, but how could the iPhone send audio, live audio from the mic, to it?

like image 814
Chris Avatar asked Mar 22 '12 02:03

Chris


People also ask

How can I use my iPhone as audio input on my computer?

Put your iPhone in AirPlay mode. In the PC's Sound settings, find the Microphone option, and press it. After that, launch the app on your iPhone. In the Settings of the app choose the USB option as transfer mode.

Is there a Microphone setting on iPhone?

Go to Settings > Privacy > Microphone. Make sure that the app is enabled.

Where is the Microphone on my iPhone?

Locate microphone and speakers The receiver/microphone is located on the bottom of the device. The speakers are located on the bottom of the device.


1 Answers

You'll need a combination of AVCaptureSession and AVCaptureDevice to read from the microphone - see the AV Foundation Programming Guide. http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureAudioDataOutput_Class/Reference/Reference.html#//apple_ref/occ/cl/AVCaptureAudioDataOutput

For link to use 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]];
}
like image 151
Олег Чебулаев Avatar answered Sep 20 '22 07:09

Олег Чебулаев