【问题标题】:How to convert received audio to udp packets?如何将接收到的音频转换为 udp 数据包?
【发布时间】:2012-06-06 08:14:20
【问题描述】:
NSMutableDictionary *dictionary=[[NSMutableDictionary alloc]init];
[dictionary setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[dictionary setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[dictionary setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

我使用AVAudioRecorder 对象获取输入,我需要将其转换为 udp 数据包。怎么做?

【问题讨论】:

    标签: iphone ios udp


    【解决方案1】:

    CocoaAsyncSocket 是一个不错的库,其中包含一个名为 AsyncUdpSocket 的类,它是一个围绕低级套接字 API 的 Obj-C 包装器。

    在包含 AsyncUdpSocket 后,只需在 header 中添加:

    AsyncUdpSocket *socket;
    

    主要是:

    NSData *data  = [NSData dataWithContentsOfURL:YourURL];//Convert Recieved Audio into NSData
    [socket sendData:data toHost:@"192.168.x.x" port:5002 withTimeout:-1 tag:1];
    

    测试时不要忘记在您的服务器防火墙上允许 UDP 通信!

    【讨论】:

    • 我想将实况语音原样发送到另一台设备,所以该怎么做。正如你提到的dataWithContentsOfURL,你的意思是我应该将它存储在文件中然后发送它?但我不想要那个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 2015-04-08
    相关资源
    最近更新 更多