This is my attempt. It doesn’t work. The best workaround is to write the data to file first

var base64 = data.base64EncodedString(options: [])

base64 = base64.replacingOccurrences(of: "=", with: "")
base64 = base64.replacingOccurrences(of: "+", with: "-")
base64 = base64.replacingOccurrences(of: "/", with: "_")

let dataURL = URL(string: "data:audio/mpeg;base64,\(base64)")!
let asset = AVAsset(url: dataURL)
let millis =  Int(CMTimeGetSeconds(asset.duration)*1000) // Returns zero