Справка по настройке параметров AvAudioRecorder - PullRequest
5 голосов
/ 05 августа 2011

Я хочу записать файл .caf, затем отправить его как почтовое вложение и забрать его на моем Mac. Проблема в том, что файл caf не воспроизводится вне моего приложения, только в моем приложении. Какие настройки мне нужно использовать для воспроизведения файла .caf с Quicktime на моем Mac, вот мои настройки. Я сохраняю аудиофайл в папке «Документы iphone».

 NSDictionary *settings =[NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithInt: kAudioFormatAppleLossless],    AVFormatIDKey,
                            [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                            [NSNumber numberWithInt: 2],                         AVNumberOfChannelsKey,
                            [NSNumber numberWithInt:128000],                     AVEncoderBitRateKey,
                            [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                          nil];

Я использую внешнюю платформу для отправки вложения, я отправляю его на веб-сервер, преобразованный в базу

        NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"VoiceMail.caf"];
    attachment1.FileData = [serv convertFileToB64String:filePath2 fileName:@"VoiceMail.caf"];
    attachment1.FileName = @"VoiceMail.caf";
    message.Attachments = [[NSMutableArray alloc] initWithObjects:attachment1, nil];

1 Ответ

9 голосов
/ 06 сентября 2011

Попробуйте эту настройку, это должно работать.

   NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];

    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey]; 
    [recordSetting setValue:[NSNumber numberWithFloat:9500.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
    [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];
    [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
...