OGeek|极客世界-中国程序员成长平台

标题: ios - AVPlayer : change rate with NO pitch correction? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:30
标题: ios - AVPlayer : change rate with NO pitch correction?

我正在使用 AVPlayer 的 rate 属性来更改音频样本的播放速度。它似乎总是应用音高校正,但我不想要音高校正,这样当它加速时它会像唱片或旧磁带播放器一样变得更高。有没有办法在 AVPLayer 中完全关闭音高校正?

我目前正在使用 Swift 3,但也欢迎使用 Objective C 的答案。



Best Answer-推荐答案


不确定这是否可以使用 AVPlayer,但如果您只是使用它来播放音频,您可以使用 AVAudioEngine 轻松做到这一点:

var audioPlayer = AVAudioPlayerNode()
var engine = AVAudioEngine()
var speedControl = AVAudioUnitVarispeed()

// engine setup:

do {

    let file = try AVAudioFile(forReading: "myFile.mp3")

    engine.attach(audioPlayer)
    engine.attach(speedControl)

    engine.connect(audioPlayer, to: speedControl, format: nil)
    engine.connect(speedControl, to: engine.mainMixerNode, format: nil)

    audioPlayer.scheduleFile(file, at: nil)

    try engine.start()

} catch {
    print(error)
}

// changing rate without pitch correction:

speedControl.rate = 0.91

关于ios - AVPlayer : change rate with NO pitch correction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36223632/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4