我正在连接到一个套接字,该套接字正在以1024字节的块传输音频wav文件,我正在寻找一个快速播放该文件的库。只是想知道是否有。
我的代码的当前状态是这个。
import UIKit
import SwiftSocket
class ViewController: UIViewController {
let port : UInt32 = UInt32(8190)
let host = "localhost"
let BUFF_SIZE = 1024
let SECRET = "MYSECRET"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let client = TCPClient(address: host, port: Int32(port))
switch client.connect(timeout: 1) {
case .success:
switch client.send(data: SECRET.data(using: .utf8) ?? Data() ) {
case .success:
var data = [UInt8]()
while true {
guard let response = client.read(BUFF_SIZE, timeout: 2) else { break }
data += response
// I am looking for a library which can play those bytes here.
}
case .failure(let error):
print(error)
}
case .failure(let error):
print(error)
}
}
}
谢谢
答案 0 :(得分:1)
可以从Swift初始化Audio Queue框架(C API)。可以指定音频队列回调以提供各种格式的原始样本缓冲区的音频输出。检查格式后,您将必须删除(跳过)WAV文件头。