'AVAudioPCMBuffer as Base64
How can the data from an AVAudioPCMBuffer be obtained as a Base64 encoded string, with Swift?
I'm asking as I'd like to send data from the microphone input on an iOS device to a WebSocket.
Solution 1:[1]
Maybe you can convert the AVAudioPCMBuffer to Data and from Data to a base64 string.
private func encodeBuffer(_ buffer: AVAudioPCMBuffer) {
let audioBuffer = buffer.audioBufferList.pointee.mBuffers
if let audioDataReference = audioBuffer.mData
{
let bufferData = Data(bytes: audioDataReference,
count: Int(audioBuffer.mDataByteSize))
let encodedString = bufferData.base64EncodedString()
// do what you need with the base 64 string
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shawn Frank |
