0

My iPhone app works well in iOS10 but doesn't work in iOS11. This app records user's voice as .wav file but its header data seems to be different between iOS10 and iOS11. The wave file is outputted using "fmt chunk" in iOS10 but "JUNK chunk" in iOS11. I need to specify fmt chunk in the header. Here is the code to output wave file.

// Create file path.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yMMddHHmmss"];
NSString *fileName = [NSString stringWithFormat:@"%@.wav", [formatter stringFromDate:[NSDate date]]];

self.filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];

// Change Audio category to Record.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];

// Settings for AVAAudioRecorder.
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithUnsignedInt:kAudioFormatLinearPCM], AVFormatIDKey,
                          [NSNumber numberWithFloat:16000.0], AVSampleRateKey,
                          [NSNumber numberWithUnsignedInt:1], AVNumberOfChannelsKey,
                          [NSNumber numberWithUnsignedInt:16], AVLinearPCMBitDepthKey,
                          nil];

self.recorder = [[AVAudioRecorder alloc] initWithURL:[NSURL URLWithString:filePath] settings:settings error:nil];
recorder.delegate = self;

[recorder prepareToRecord];
[recorder record];

I really need your help. Thank you.

  • The JUNK chunk is used to align RIFF chunks to certain boundaries. Not sure why it's added in your case but it's ok that they are added. The fat chunk may be following the 'JUNK' chunk. Did you check that? According to the specification applications should ignore the content of a 'JUNK' chunk. – andih Jan 10 '18 at 09:18

1 Answers1

0

I've solved this issue thanks to this post.

Audio file format issue in objective c

Thank you.