iOS Library to Play the wav file coming over the socket

╄→尐↘猪︶ㄣ 提交于 2019-12-11 16:23:03

问题


I am connecting to a socket which is transmitting audio wav file in 1024 byte chunks and I am looking for a swift library to play that. Just wondering if there is any.

Current state of my code is this.

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)
    }

}
}

Thanks


回答1:


The Audio Queue framework (a C API) can be initialized from Swift. An Audio Queue callback can be specified to provide for audio output of buffers of raw samples of various formats. You will have to remove (skip) the WAV file header after checking the format.



来源:https://stackoverflow.com/questions/56892135/ios-library-to-play-the-wav-file-coming-over-the-socket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!