【发布时间】:2020-07-10 16:35:40
【问题描述】:
我有一个仅包含语音的 .mp3 文件,我想在保持相同清晰度的同时调整速度(更慢或更快)。没有花栗鼠!然后将修改后的文件写入磁盘。为了做到这一点,我正在尝试使用 AVAudioEngine 框架,但我是该框架的完整 N00B。我发现所有的例子都是为了修改音乐或录制声音然后播放出来的。我只想转换为不同的速度并让它吐出修改后的文件。到目前为止,我能想到的就是这些,我在代码的 cmets 中记录了我的困惑。
import Foundation
import AVFoundation
import AVKit
print("Change Voice Speed")
let engine = AVAudioEngine()
let speedControl = AVAudioUnitVarispeed()
let originalFile = URL(fileURLWithPath: "/Users/User/Desktop/speech.mp3")
do {
// What do I do with the input file ?
let file = try AVAudioFile(forReading: originalFile)
} catch let error as NSError {
print("There's an error: \(error)")
}
speedControl.rate += 0.1
engine.attach(speedControl)
// Do I need to attach a AVAudioRecorder and record here ?
print("Write New File")
let outputFile = URL(fileURLWithPath: "/Users/User/Desktop/modifiedSpeech.mp3")
// Don't know what settings to put for a .mp3 file are. Also not
// sure if this actually writes the file to disk
do {
try AVAudioFile(forWriting: outputFile, settings: <#T##[String : Any]#>)
} catch let error as NSError {
print("There's an error: \(error)")
}
【问题讨论】:
标签: macos avaudioengine