【问题标题】:Get stream of raw samples from audio signal using AudioToolbox - Swift使用 AudioToolbox - Swift 从音频信号中获取原始样本流
【发布时间】:2017-02-02 19:26:46
【问题描述】:

我想用我的 iPhone 录制一个音频信号,然后我想一个接一个地访问这个信号的样本。我在网上找到了一些类似的例子,但我从来没有找到一个例子(在 Swift 中)来实际读取和操作所有原始样本。如何使用 Swift 做到这一点?

【问题讨论】:

  • 这个范围很广,很难理解。如果您能更具体地说明您想做什么并向我们展示一些代码,那就太好了...

标签: ios swift audio signal-processing audiotoolbox


【解决方案1】:

我解决了我的问题,我终于能够创建一个浮点数组来存储和操作音频样本,执行以下操作:

   let file: AVAudioFile!
    do {
        file = try AVAudioFile(forReading: mySourceURL!)
    } catch {
        print("Error:", error)
        return
    }
    let totSamples = file.length
    let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: 1, interleaved: false)
    let buffer = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: AVAudioFrameCount(totSamples))
    try! file.read(into: buffer)
    var floatArray = Array(UnsafeBufferPointer(start: buffer.floatChannelData?[0], count:Int(buffer.frameLength)))

mySourceURL!是记录信号的 URL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 2011-02-20
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2018-05-16
    相关资源
    最近更新 更多