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!
There are various questions available for the same topic:
How to trim audio file in iPhone?
And here is one sample code:
http://code4app.net/ios/Trim-Control/51121a886803fa071d000001
Hope this might help you to achieve your functionality.
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)