2

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!

Fisea
  • 21
  • 1
  • 4

2 Answers2

2

There are various questions available for the same topic:

iOS Audio Trimming

How to trim audio file in iPhone?

How to trim audio data?

How to crop audio in ios

And here is one sample code:

http://code4app.net/ios/Trim-Control/51121a886803fa071d000001

Hope this might help you to achieve your functionality.

Community
  • 1
  • 1
Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • I couldn't find any answer for how to delete from an audio file, for example if I want to delete from second 3 till 10. can u check this question please: https://stackoverflow.com/questions/53928988/swift-how-to-delete-part-of-audio – mahdi Dec 26 '18 at 11:06
1

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)
HariKarthick
  • 1,369
  • 1
  • 19
  • 47