Tag: avaudiorecorder

iOS – 录制audio播放失败,OSStatus错误-43(找不到文件)

我加载视图时,按以下方式设置AVAudioRecorder实例: AVAudioSession *audioSession = [AVAudioSession sharedInstance]; audioSession.delegate = self; [audioSession setActive:YES error:nil]; [audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; NSString *tempDir = NSTemporaryDirectory(); NSString *soundFilePath = [tempDir stringByAppendingPathComponent:@"sound.m4a"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; NSLog(@"%@", soundFileURL); NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey, [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt:16], AVEncoderBitRateKey, [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, [NSNumber numberWithFloat:8000.0], AVSampleRateKey, [NSNumber numberWithInt:8], AVLinearPCMBitDepthKey, […]

audio会话中断结束后,AVAudioRecorder不能在后台录音

我在我的应用程序录制audio,无论是在前景和背景。 我也处理AVAudioSessionInterruptionNotification中断开始时停止录音,当它结束时再次开始。 虽然在前台它如预期的那样工作,当应用程序在后台录制时,我收到一个电话,它不会在通话结束后再次开始录音。 我的代码如下: – (void)p_handleAudioSessionInterruptionNotification:(NSNotification *)notification { NSUInteger interruptionType = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue]; if (interruptionType == AVAudioSessionInterruptionTypeBegan) { if (self.isRecording && !self.interruptedWhileRecording) { [self.recorder stop]; self.interruptedWhileRecording = YES; return; } } if (interruptionType == AVAudioSessionInterruptionTypeEnded) { if (self.interruptedWhileRecording) { NSError *error = nil; [[AVAudioSession sharedInstance] setActive:YES error:&error]; NSDictionary *settings = @{ AVEncoderAudioQualityKey: @(AVAudioQualityMax), […]

ios – 以编程方式将.m4a转换为.mp3文件

这里我有m4a格式的audio,我需要转换成mp3格式。 为此,我使用了代码 – (void) toMp3{ NSString *m4aFilePath = pathToSave; NSString *mp3FileName = [NSString stringWithFormat:@"Audio%d",[audioArr count]]; mp3FileName = [mp3FileName stringByAppendingString:@".mp3"]; pathToSave = [NSString stringWithFormat:@"%@/%@", DOCUMENTS_FOLDER, mp3FileName]; NSLog(@"pathToSave :%@",pathToSave); @try { int read, write; FILE *pcm = fopen([cafFilePath cStringUsingEncoding:1], "rb"); //source fseek(pcm, 4*1024, SEEK_CUR); //skip file header FILE *mp3 = fopen([pathToSave cStringUsingEncoding:1], "wb"); //output const int PCM_SIZE […]

iOS应用程序在后台录制时audio中断

我的iPad声音应用程序(iOS 7.1)能够在后台录制。 只要在后台录制不中断,一切都可以。 例如,如果有人(愚蠢?)的想法,开始听音乐,而录音的东西。 我试图以不同的方式pipe理这种中断,但没有成功。 问题是, – (void)audioRecorderEndInterruption:(AVAudioPlayer *)p withOptions:(NSUInteger)flags 当应用程序在后台发生中断时,永远不会被触发。 然后,我尝试在另一个解决scheme中实现AVAudioSessionInterruptionNotification和handleInterruption:方法 – (void) viewDidAppear:(BOOL)animated { …… AVAudioSession *session=[AVAudioSession sharedInstance]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:session]; ……. } // interruption handling – (void)handleInterruption:(NSNotification *)notification { try { UInt8 theInterruptionType = [[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] intValue]; NSLog(@"Session interrupted > — %s —\n", theInterruptionType == AVAudioSessionInterruptionTypeBegan ? "Begin Interruption" […]

将我的应用程序生成的所有声音录制在audio文件中(而不是从麦克风)

我有一个像一个乐器的屏幕。 有播放声音文件的button。 我想logging用户在单个audio文件中按下button播放的声音,以便我可以将该文件保存为mp4或其他audio格式。 你能指导我如何以简单的方式来实现这一点? 我可以用AVAudioRecorder录制麦克风 正如我所想,录音方法使用麦克风作为来源,但我希望它使用我的应用程序的“audio输出”等同于作为来源。

AVAudioRecorder averagePowerForChannel总是返回-120.0

我正在尝试使用AVAudioRecorder的averagePowerForChannel方法来监视iPad / iPhone应用程序的麦克风input级别。 我有一个callback轮询平均水平 – 在iPhone上工作正常,并返回合理的水平,但由于某种原因在iPad上,它总是返回-120.0。 这里是我的一些设置代码: – (void) setupMic { if (micInput) { [micInput release]; micInput = nil; } NSURL *newURL = [[NSURL alloc] initFileURLWithPath:@"/dev/null"]; NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] init]; [recordSettings setObject:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey: AVFormatIDKey]; [recordSettings setObject:[NSNumber numberWithFloat:22050.0] forKey: AVSampleRateKey]; // [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey]; [recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey]; [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey]; […]

AVAudioRecorder支持什么格式的声音录制?

我在http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/CoreAudioDataTypesRef/Reference/reference.html#//apple_ref/doc/find了不同的值列表(audio数据格式) UID / TP40004488 audio数据格式标识符audio数据格式的标识符,用于AudioStreamBasicDescription结构中。 kAudioFormatLinearPCM ='lpcm', kAudioFormatAC3 ='ac-3', kAudioFormat60958AC3 ='cac3', kAudioFormatAppleIMA4 ='ima4', kAudioFormatMPEG4AAC ='aac', kAudioFormatMPEG4CELP ='celp', kAudioFormatMPEG4HVXC ='hvxc', kAudioFormatMPEG4TwinVQ ='twvq', kAudioFormatMACE3 ='MAC3', kAudioFormatMACE6 ='MAC6', kAudioFormatULaw ='ulaw', kAudioFormatALaw ='alaw', kAudioFormatQDesign ='QDMC', kAudioFormatQDesign2 ='QDM2', kAudioFormatQUALCOMM ='Qclp', kAudioFormatMPEGLayer1 ='.mp1', kAudioFormatMPEGLayer2 ='.mp2', kAudioFormatMPEGLayer3 ='.mp3', kAudioFormatTimeCode ='时间', kAudioFormatMIDIStream ='midi', kAudioFormatParameterValueStream ='apvs', kAudioFormatAppleLossless ='alac' kAudioFormatMPEG4AAC_HE ='aach', kAudioFormatMPEG4AAC_LD ='aacl', kAudioFormatMPEG4AAC_ELD ='aace', […]

AVAudioRecorder initWithURL文件types文档

AvAudioRecorder有一个init方法: – (instancetype)initWithURL:(NSURL *)url settings:(NSDictionary *)settings error:(NSError **)outError 一个“魔术”的行为是部分logging的 : url 要logging到的文件系统位置。 要logging到的文件types是从此参数的值中包含的文件扩展名推断的。 有没有进一步的文件这个function? 具体来说,支持的文件扩展名是什么? 有什么办法可以支持原始输出吗? 有关: 如何使用不带.caf容器的AVAudioRecorder进行录制? 如何使用AVAudioRecorder数据并将其转换为C ++的原始audio? 如何从iPhone上的caf文件访问/提取原始(无头文件)audio数据?

iOS AVAudioSession中断通知不按预期工作

我想知道什么时候我的AVAudioRecorder无法访问(例如,当音乐开始播放)。 由于audioRecorderEndInterruption将被弃用与iOS 9我专注于AVAudioSession的中断通知(但都没有按预期工作)。 问题是,如果应用程序在中断发生时仍处于前台,中断通知从不会被调用。 例如:用户启动和停止播放音乐,而不将应用程序移动到后台。 要检测我正在使用的任何中断: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionWasInterrupted:) name:AVAudioSessionInterruptionNotification object:nil]; … – (void)audioSessionWasInterrupted:(NSNotification *)notification { if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) { NSLog(@"Interruption notification"); if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) { NSLog(@"InterruptionTypeBegan"); } else { NSLog(@"InterruptionTypeEnded"); } } } 如预期的那样,我得到InterruptionTypeBegan ,但是如果应用程序仍处于前台(即在应用程序放置在后台并返回前台之前不会调用),则不会调用InterruptionTypeEnded 。 在应用程序处于前台时发生中断时,如何接收InterruptionTypeEnded通知?

AVAudioRecorder不适用于iPhone 5S

所以我使用的AVAudioRecorderloggingAVCaptureSession录音video旁边(我知道这很奇怪,但对于我的情况,我需要单独logging)。 除了我的iPhone 5S之外,所有设备上的一切正常。 它logging没有错误,但保存到磁盘的文件已损坏或什么的。 当我访问我的Mac上的文件系统,尝试使用VLC或Quicktime播放m4a文件时,出现“无法检测到文件的格式”错误。 这是我如何初始化我的AVAudioRecorder和录制我的audio: // Prepare the audio session [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil]; [[AVAudioSession sharedInstance] setMode:AVAudioSessionModeVideoRecording error:nil]; // Setup audio recording NSDictionary *recordSettings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC), AVEncoderAudioQualityKey: @(AVAudioQualityLow), AVEncoderBitRateKey: @16, AVNumberOfChannelsKey: @1, AVSampleRateKey: @22050.0f}; NSError *audioRecorderError; NSURL *audioFileURL = [[self.outputFileURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"m4a"]; self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:audioFileURL settings:recordSettings error:&audioRecorderError]; self.audioRecorder.delegate = self; if […]