iOS库,用于播放套接字上的wav文件 [英] iOS Library to Play the wav file coming over the socket

查看:278
本文介绍了iOS库,用于播放套接字上的wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在连接到一个套接字,该套接字正在以1024字节的块传输音频wav文件,我正在寻找一个快速播放该文件的库.只是想知道是否有.

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

}
}

谢谢

推荐答案

可以从Swift初始化Audio Queue框架(C API).可以指定音频队列回调以提供各种格式的原始样本的缓冲区的音频输出.检查格式后,您将必须删除(跳过)WAV文件头.

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.

这篇关于iOS库,用于播放套接字上的wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆