gpt4 book ai didi

swift - AudioKit 4.2.3 碰撞麦克风频率分析 Swift 4.1

转载 作者:搜寻专家 更新时间:2023-10-31 19:27:28 25 4
gpt4 key购买 nike

我刚刚更新到最新的 AudioKit 版本 4.2.3 和 Swift 4.1 我在 audiokit.start() 遇到崩溃,我无法破译。如果您需要更多错误代码,请 lmk。

AURemoteIO::IOThread (21): EXC_BAD_ACCESS (code=1, address=0x100900000)

仅供引用,我还使用 AVAudioRecorder 将麦克风输入记录到文件中,稍后在 ViewController 中使用 AVKit AVAudioPlayer 播放它。但是,由于我在更新之前没有遇到此崩溃,我不认为这些因素是负责任的 - 但与跟踪器输入有关。

import UIKit
import Speech
import AudioKit

class RecordVoiceViewController: UIViewController {

var tracker: AKFrequencyTracker!
var silence: AKBooster!
var mic: AKMicrophone!

let noteFrequencies = [16.35, 17.32, 18.35, 19.45, 20.6, 21.83, 23.12, 24.5, 25.96, 27.5, 29.14, 30.87]
let noteNamesWithSharps = ["C", "C♯","D","D♯","E","F","F♯","G","G♯","A","A♯","B"]
let noteNamesWithFlats = ["C", "D♭","D","E♭","E","F","G♭","G","A♭","A","B♭","B"]

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

AKSettings.audioInputEnabled = true
mic = AKMicrophone()
tracker = AKFrequencyTracker.init(mic, hopSize: 200, peakCount: 2000)
silence = AKBooster(tracker, gain: 0)
}

func startAudioKit(){
AudioKit.output = self.silence
do {
try AudioKit.start()
} catch {
AKLog("Something went wrong.")
}
}
}

有趣的是,当我在没有 hopSize 和 peakCount 的情况下初始化跟踪器时,例如:

  tracker = AKFrequencyTracker.init(mic)

它不会崩溃,但也不会返回正确的频率。我非常感谢任何帮助。谢谢!!!

最佳答案

我遇到过完全相同的问题,但最终找到了临时解决方案。您需要做的就是在 AKMicrophone AKFrequencyTracker 之间添加一个附加层,在我的例子中是AKHighPassFilter.

这是正常工作的代码:

let microphone = AKMicrophone()
let filter = AKHighPassFilter(microphone, cutoffFrequency: 200, resonance: 0)
let tracker = AKFrequencyTracker(filter)
let silence = AKBooster(tracker, gain: 0)

AKSettings.audioInputEnabled = true
AudioKit.output = silence
try! AudioKit.start()

希望这对您有所帮助,祝您好运!

关于swift - AudioKit 4.2.3 碰撞麦克风频率分析 Swift 4.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49845472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com