我正在使用AVPlayer的 rate 属性来更改音频样本的播放速度。它似乎总是应用音调校正,但我不需要音调校正,因此当它加速时它会像记录或旧的磁带播放器那样变得更高。在AVPLayer中有没有办法完全关闭音高修正?
我目前正在使用Swift 3,但也欢迎Objective C答案。
答案 0 :(得分: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
答案 1 :(得分:0)
实际上,使用AVPlayer可以实现-
let player = AVPlayer(url: fileURL)
// to turn off pitch correction:
player.currentItem?.audioTimePitchAlgorithm = .varispeed