Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use this code</p> <pre><code>MPMediaItem *item = // obtain the media item NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Get raw PCM data from the track NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; NSMutableData *data = [[NSMutableData alloc] init]; const uint32_t sampleRate = 16000; // 16k sample/sec const uint16_t bitDepth = 16; // 16 bit/sample/channel const uint16_t channels = 2; // 2 channel/sample (stereo) NSDictionary *opts = [NSDictionary dictionary]; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:assetURL options:opts]; AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:asset error:NULL]; NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey, [NSNumber numberWithFloat:(float)sampleRate], AVSampleRateKey, [NSNumber numberWithInt:bitDepth], AVLinearPCMBitDepthKey, [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved, [NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey, [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey, nil]; AVAssetReaderTrackOutput *output = [[AVAssetReaderTrackOutput alloc] initWithTrack: [[asset tracks] objectAtIndex:0] outputSettings:settings]; [asset release]; [reader addOutput:output]; [reader startReading]; // read the samples from the asset and append them subsequently while ([reader status] != AVAssetReaderStatusCompleted) { CMSampleBufferRef buffer = [output copyNextSampleBuffer]; if (buffer == NULL) continue; CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(buffer); size_t size = CMBlockBufferGetDataLength(blockBuffer); uint8_t *outBytes = malloc(size); CMBlockBufferCopyDataBytes(blockBuffer, 0, size, outBytes); CMSampleBufferInvalidate(buffer); CFRelease(buffer); [data appendBytes:outBytes length:size]; free(outBytes); </code></pre>
    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