Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can achieve the combining of two files by recording the audio in .wav extension and the code is as follows,</p> <pre><code>NSURL *originalFileName = [NSURL alloc]; NSURL *RecordingPath =[NSURL fileURLWithPath:[appDelegate.RecordingPath stringByAppendingPathComponent: [NSString stringWithFormat:@"RecordingFile.wav"]]]; NSLog(@"LocalRecoding Path :%@",RecordingPath); originalFileName=RecordingPath; NSURL *temporaryFileName = [NSURL alloc]; temporaryFileName = [NSURL fileURLWithPath:[appDelegate.RecordingPath stringByAppendingPathComponent: [NSString stringWithFormat: @"tempRecordingFile.%@", @"wav"]]]; long totalAudioLen = 0; long totalDataLen = 0; long longSampleRate = 11025.0; int channels = 2; long byteRate = 16 * 11025.0 * channels/8; NSData * wav1Data = [NSData dataWithContentsOfFile:[originalFileName path]]; NSData * wav2Data = [NSData dataWithContentsOfFile:[temporaryFileName path]]; if([wav1Data length]&gt;0 &amp;&amp; [wav2Data length] &gt;0) { int wav1DataSize = [wav1Data length] - 44; NSLog(@"WAV I:%d",wav1DataSize); int wav2DataSize = [wav2Data length] - 44; NSLog(@"WAV II:%d",wav2DataSize); NSData *Wave1= [NSMutableData dataWithData:[wav1Data subdataWithRange:NSMakeRange(44, wav1DataSize)]]; NSData *Wave2 =[NSMutableData dataWithData:[wav2Data subdataWithRange:NSMakeRange(44, wav2DataSize)]]; NSLog(@"WAV 1:%d",[Wave1 length]); NSLog(@"WAV 2:%d",[Wave2 length]); totalAudioLen=[Wave1 length]+[Wave2 length]; totalDataLen = totalAudioLen + 44; Byte *header = (Byte*)malloc(44); header[0] = 'R'; // RIFF/WAVE header header[1] = 'I'; header[2] = 'F'; header[3] = 'F'; header[4] = (Byte) (totalDataLen &amp; 0xff); header[5] = (Byte) ((totalDataLen &gt;&gt; 8) &amp; 0xff); header[6] = (Byte) ((totalDataLen &gt;&gt; 16) &amp; 0xff); header[7] = (Byte) ((totalDataLen &gt;&gt; 24) &amp; 0xff); header[8] = 'W'; header[9] = 'A'; header[10] = 'V'; header[11] = 'E'; header[12] = 'f'; // 'fmt ' chunk header[13] = 'm'; header[14] = 't'; header[15] = ' '; header[16] = 16; // 4 bytes: size of 'fmt ' chunk header[17] = 0; header[18] = 0; header[19] = 0; header[20] = 1; // format = 1 header[21] = 0; header[22] = (Byte) channels; header[23] = 0; header[24] = (Byte) (longSampleRate &amp; 0xff); header[25] = (Byte) ((longSampleRate &gt;&gt; 8) &amp; 0xff); header[26] = (Byte) ((longSampleRate &gt;&gt; 16) &amp; 0xff); header[27] = (Byte) ((longSampleRate &gt;&gt; 24) &amp; 0xff); header[28] = (Byte) (byteRate &amp; 0xff); header[29] = (Byte) ((byteRate &gt;&gt; 8) &amp; 0xff); header[30] = (Byte) ((byteRate &gt;&gt; 16) &amp; 0xff); header[31] = (Byte) ((byteRate &gt;&gt; 24) &amp; 0xff); header[32] = (Byte) (2 * 8 / 8); // block align header[33] = 0; header[34] = 16; // bits per sample header[35] = 0; header[36] = 'd'; header[37] = 'a'; header[38] = 't'; header[39] = 'a'; header[40] = (Byte) (totalAudioLen &amp; 0xff); header[41] = (Byte) ((totalAudioLen &gt;&gt; 8) &amp; 0xff); header[42] = (Byte) ((totalAudioLen &gt;&gt; 16) &amp; 0xff); header[43] = (Byte) ((totalAudioLen &gt;&gt; 24) &amp; 0xff); NSData *headerData = [NSData dataWithBytes:header length:44]; //Merge the sound data of the original file with the temp file and create a new sound file with the //update header. NSMutableData * soundFileData = [NSMutableData alloc]; [soundFileData appendData:[headerData subdataWithRange:NSMakeRange(0, 44)]]; [soundFileData appendData:Wave1]; [soundFileData appendData:Wave2]; //delete the original file NSFileManager * fm = [NSFileManager defaultManager]; [fm removeItemAtPath:[originalFileName path] error:nil]; //create a new file with merged audio with the original file name. NSURL *mergedFilePath = [NSURL alloc]; mergedFilePath = [NSURL fileURLWithPath:[appDelegate.RecordingPath stringByAppendingPathComponent: [NSString stringWithFormat:[originalFileName lastPathComponent]]]]; [[NSFileManager defaultManager] createFileAtPath:[mergedFilePath path] contents:soundFileData attributes:nil]; NSLog(@"COMBINED FILE PATH :%@",mergedFilePath); } </code></pre>
    singulars
    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.
    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