我使用AVAudioEngine改变了Swift中音频的音调和速率。
我想出了如何更改速度/速率并保持音高不变的方法,但是当我这样做时,会出现一种音频干扰,当您切换速率时,您可以很快听到音频音高的调整(我想因为代码会先更改速率,然后再将音调更改为听起来像原始声音一样
我想摆脱这种影响,并使音高和速率改变同时发生。这有可能吗?
W
var engine : AVAudioEngine = AVAudioEngine()
var speedControl : AVAudioUnitVarispeed = AVAudioUnitVarispeed()
var pitchControl : AVAudioUnitTimePitch = AVAudioUnitTimePitch()
// ...
func changeTempo(to tempo: Float) {
speedControl.rate = tempo
// to keep the same pitch:
let pitchChange = log2(speedControl.rate) * 1200.0
pitchControl.pitch = pitchChange * -1
}
答案 0 :(得分:0)
您似乎忽略了 AVAudioUnitTimePitch
既可以做音高又可以做时间。
https://developer.apple.com/documentation/avfaudio/avaudiounittimepitch