[英]Streaming audio from a microphone on a Mac to an iPhone
I'm working on a personal project where the iPhone connects to a server-type application running on a Mac. 我正在开发一个个人项目,iPhone连接到运行在Mac上的服务器类型的应用程序。 The iPhone send and receives textual/ASCII data via standard sockets. iPhone通过标准套接字发送和接收文本/ ASCII数据。 I now need to stream the microphone from the Mac to the iPhone. 我现在需要将麦克风从Mac流式传输到iPhone。 I've done some work with AudioServices before but wanted to check my thoughts here before getting too deep. 我之前已经完成了一些与AudioServices的合作,但是想要在太深入之前检查我的想法。
I'm thinking I can: 我想我可以:
1. Create an Audio Queue in the standard Cocoa application on the Mac. 1.在Mac上的标准Cocoa应用程序中创建音频队列。
2. In my Audio Queue Callback function, rather than writing it to a file, write it to another socket I open for audio streaming. 2.在我的音频队列回调函数中,不是将其写入文件,而是将其写入我为音频流打开的另一个套接字。
3. On the iPhone, receive the raw sampled/encoded audio data from the TCP stream and dump it into an Audio Queue Player which outputs to headphone/speaker. 3.在iPhone上,从TCP流接收原始采样/编码音频数据并将其转储到音频队列播放器中,该播放器输出到耳机/扬声器。
I know this is no small task and I've greatly simplified what I need to do but could it be as easy as that? 我知道这不是一项小任务,我已经大大简化了我需要做的事情,但它可以像那样简单吗?
Thanks for any help you can provide, 感谢您的任何帮助,您可以提供,
Stateful 有状态
This looks broadly sensible, but you'll almost certainly need to do a few more things: 这看起来很明智,但你几乎肯定需要做更多的事情:
Depending on your data rates, it might be worthwhile going for the lower-level (BSD) socket API and potentially even using readv()/writev(). 根据您的数据速率,可能值得使用较低级别(BSD)套接字API,甚至可能使用readv()/ writev()。
If all you want is an "online radio" service and you don't care about the protocol used, it might be easier to use AVPlayer/MPMoviePlayer to play audio from a URL instead. 如果你想要的只是一个“在线广播”服务而你并不关心所使用的协议,那么使用AVPlayer / MPMoviePlayer来播放来自URL的音频可能会更容易。 This involves implementing a server which speaks Apple's HTTP streaming protocol; 这涉及实现一个讲Apple的HTTP流协议的服务器; I believe Apple has some sample code that does this. 我相信Apple有一些示例代码可以做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.