iOS8 AVAudioEngine如何通过Multipeer Connectivity发送麦克风数据? [英] iOS8 AVAudioEngine how to send microphone data over Multipeer Connectivity?

查看:519
本文介绍了iOS8 AVAudioEngine如何通过Multipeer Connectivity发送麦克风数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Multipeer Connectivity(iOS 8)发送麦克风音频数据,并通过接收对等体的扬声器播放。我还设置了AVAudioEngine,我可以听到(上方)扬声器输出的麦克风数据,但我不知道如何通过网络发送AVAudioPCMBuffer。这是我的代码片段:

I want to send microphone audio data over Multipeer Connectivity (iOS 8) and play it through the speaker of the receiving peer. I've also setup the AVAudioEngine and I can hear the microphone data from the (upper) speaker output, but I don't know how to send AVAudioPCMBuffer over the network. Here's my code snippet:

AVAudioInputNode *inputNode =[self.engine inputNode];
AVAudioMixerNode *mainMixer = [self.engine mainMixerNode];
[self.engine connect:inputNode to:mainMixer format:[inputNode inputFormatForBus:0]];

[mainMixer installTapOnBus:0 bufferSize:4096 format:[mainMixer outputFormatForBus:0] 
    block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {

    //==== How to send the PCMBuffer ?? ======//
}];

NSError *error = nil;
[self.engine startAndReturnError:&error];

if(error)
{
    NSLog(@"error: %@", [error localizedDescription]);
}

我是以NSData还是NSStream发送的?

Do I send it as NSData or NSStream ?

感谢您的帮助。 Thx。

Appreciate for the help. Thx.

推荐答案

我还没有尝试过这个解决方案:

I haven't tried this solution:

- (NSOutputStream *)startStreamWithName:(NSString *)streamName
                                 toPeer:(MCPeerID *)peerID
                                  error:(NSError **)error

您可以使用 property buffer.floatChannelData 。现在,您可以将此float数组打包到 NSOutputStream 中并发送它。

You can receive a float array by using the property buffer.floatChannelData. Now you can pack this float array into NSOutputStream and send it.

在客户端,您可以尝试接收流:

On client side you can try to receive a stream:

- (void)session:(MCSession *)session
didReceiveStream:(NSInputStream *)stream
       withName:(NSString *)streamName
       fromPeer:(MCPeerID *)peerID
{
    stream.delegate = self;
    [stream scheduleInRunLoop:[NSRunLoop mainRunLoop] 
                      forMode:NSDefaultRunLoopMode];
    [stream open];
}

但在尝试此操作之前,您可以尝试发送随机值(因此< a href =http://en.wikipedia.org/wiki/White_noise =nofollow>白噪声)而不是float数组,所以你可以确定发送这些的时间段缓冲区(我们谈论的是实时)足够广泛。

But before you try this, you could try to send random values (therefore white noise) instead of the float array, so you can make sure, that the time slot for sending these buffers (we are talking about real-time) is wide enough.

更新15.10.2014
我找到了你需要的东西:
http:// robots。 thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity

这篇关于iOS8 AVAudioEngine如何通过Multipeer Connectivity发送麦克风数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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