gpt4 book ai didi

ios - 使用 AVAudioengine (iOS) 播放流媒体音频

转载 作者:行者123 更新时间:2023-11-29 11:26:17 39 4
gpt4 key购买 nike

我想使用 AVAudioEngine 在 iOS 上流式传输音频。目前我不确定该怎么做。

我从网络获取 RTP 数据并想用 AVAudioEngine 播放这个音频数据。

我正在使用 iOS Network.Framework 来接收网络数据。然后我解码语音数据,现在想使用 AVAudioEngine 播放它。

这是我的接收码:

connection.receiveMessage { (data, context, isComplete, error) in
if isComplete {

// decode the raw network data with Audio codec G711/G722
let decodedData = AudioDecoder.decode(enc: data, frames: 160)

// create PCMBuffer for audio data for playback
let format = AVAudioFormat(standardFormatWithSampleRate: 8000, channels: 1)
let buffer = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: 160)!
buffer.frameLength = buffer.frameCapacity

// TODO: now I have to copy the decodedData --> buffer (AVAudioPCMBuffer)

if error == nil {
// recall receive() for next message
self.receive(on: connection)
}
}

如何将 decodedData 复制到我的 AVAudioPCMBuffer?目前,我的 buffer 变量已创建,但不包含任何数据。

背景资料:

我的一般方法是在 PCMBuffer 中缓存一个集合并使用 AVAudioEngine 播放这个集合。

有没有更好的方法直接(立即)使用音频数据?

最佳答案

不确定您是否找到了解决方案,但我能够使用 AVAudioEngine 流式传输音频。我没有使用 AudioDecoder,而是使用 URLSession 流式传输数据包来下载数据包。然后我将这些下载的数据包流式传输到 AudioFileStreamOpen 中,在那里我格式化了音频数据包。最后,我使用 AudioConverterFillComplexBuffer 将这些数据包转换为引擎的 PCM 缓冲区,并将这些缓冲区安排到引擎中进行播放。

这是我完成的项目:https://github.com/tanhakabir/SwiftAudioPlayer我在其中设置了我在播客播放器上使用的完整引擎。这是我写的关于整体架构的简短博客:https://medium.com/chameleon-podcast/creating-an-advanced-streaming-audio-engine-for-ios-9fbc7aef4115

这是我的图书馆基于的博客:https://github.com/syedhali/AudioStreamer

关于ios - 使用 AVAudioengine (iOS) 播放流媒体音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58520714/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com