【问题标题】:AVPlayer : change rate with NO pitch correction?AVPlayer:没有音高校正的变化率?
【发布时间】:2016-03-25 16:11:13
【问题描述】:

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

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

【问题讨论】:

    标签: ios audio avplayer


    【解决方案1】:

    不确定这是否可以使用 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
    
    

    【讨论】:

      【解决方案2】:

      其实用 AVPlayer 是可以做到的 --

      let player = AVPlayer(url: fileURL)
      
      // to turn off pitch correction:
      
      player.currentItem?.audioTimePitchAlgorithm = .varispeed
      
      

      【讨论】:

        猜你喜欢
        • 2022-08-17
        • 1970-01-01
        • 1970-01-01
        • 2021-10-26
        • 1970-01-01
        • 2013-09-30
        • 2023-03-29
        相关资源
        最近更新 更多