Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the code that I've used to trim audio from a pre-existing file. You'll need to change the M4A related constants if you've saved or are saving to another format.</p> <pre><code>- (BOOL)trimAudio { float vocalStartMarker = &lt;starting time&gt;; float vocalEndMarker = &lt;ending time&gt;; NSURL *audioFileInput = &lt;your pre-existing file&gt;; NSURL *audioFileOutput = &lt;the file you want to create&gt;; if (!audioFileInput || !audioFileOutput) { return NO; } [[NSFileManager defaultManager] removeItemAtURL:audioFileOutput error:NULL]; AVAsset *asset = [AVAsset assetWithURL:audioFileInput]; AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetAppleM4A]; if (exportSession == nil) { return NO; } CMTime startTime = CMTimeMake((int)(floor(vocalStartMarker * 100)), 100); CMTime stopTime = CMTimeMake((int)(ceil(vocalEndMarker * 100)), 100); CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime); exportSession.outputURL = audioFileOutput; exportSession.outputFileType = AVFileTypeAppleM4A; exportSession.timeRange = exportTimeRange; [exportSession exportAsynchronouslyWithCompletionHandler:^ { if (AVAssetExportSessionStatusCompleted == exportSession.status) { // It worked! } else if (AVAssetExportSessionStatusFailed == exportSession.status) { // It failed... } }]; return YES; } </code></pre> <p>There's also <a href="http://developer.apple.com/library/ios/#qa/qa1730/_index.html">Technical Q&amp;A 1730</a>, which gives a slightly more detailed approach.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload