Reputation: 21
This is similar to the trim function of iTunes,pass two following parameters to get a trim audio that i want.
eg. begin time:00:23.12
stop time:01:33.54
Much appreciated if any help!
Upvotes: 2
Views: 2942
Reputation: 1497
If you are reading this in 2016 and you're looking for a solution.It's working for me(swift 2.3):
let exporter = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A)
exporter!.outputURL = soundFile1
exporter!.outputFileType = AVFileTypeAppleM4A
let duration = CMTimeGetSeconds(avAsset1.duration)
print(duration)
if (duration < 5.0) {
print("sound is not long enough")
return
}
// e.g. the first 30 seconds
let startTime = CMTimeMake(0, 1)
let stopTime = CMTimeMake(30,1)
let exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime)
print(exportTimeRange)
exporter!.timeRange = exportTimeRange
print(exporter!.timeRange)
Upvotes: 1