这来自音频套件示例代码。如果你把它放到你的视图类中,它应该可以工作。这对我有用。
var mic: AKMicrophone!
var tracker: AKFrequencyTracker!
var silence: AKBooster!
@IBOutlet weak var audioInputPlot: EZAudioPlot!
override func viewDidLoad() {
super.viewDidLoad()
AKSettings.audioInputEnabled = true
mic = AKMicrophone()
tracker = AKFrequencyTracker(mic)
silence = AKBooster(tracker, gain: 0)
setupPlot()
}
func setupPlot() {
let plot = AKNodeOutputPlot(mic, frame: audioInputPlot.bounds)
plot.plotType = .rolling
plot.shouldFill = true
plot.shouldMirror = true
plot.color = UIColor.blue
audioInputPlot.addSubview(plot)
}