I have a .mp3 file that contains just voice and I would like to adjust the speed (slower or faster) while maintaining the same clarity. No chipmunks! Then write out the modified file to disk. In order to do this, I am trying to use the AVAudioEngine Framework but am a complete N00B to the framework. All the examples, I have found, are geared to modifying music or recording voice then playing it audibly. I just want to convert to a different speed and have it spit out the modified file. This was all I could figure out so far, I documented my confusion in the comments of the code.
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)")
}