gpt4 book ai didi

iphone - 使用 AVAudioRecorder 重新录制

转载 作者:行者123 更新时间:2023-11-29 13:19:25 25 4
gpt4 key购买 nike

我可以使用下面的设置进行录制 - 第一次可以,但是当我再次尝试时文件总是 8192 字节,即不正确的录制。

-(void) startRecording
{

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 11025.0f], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityLow], AVEncoderAudioQualityKey,
nil];

NSString *filenameBasedOnTime = [[NSDate date] description];

if (_recordedFileURL) _recordedFileURL = nil;

_recordedFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:filenameBasedOnTime]];

NSError* error;

if (_audioRecorder) _audioRecorder = nil;

_audioRecorder = [[AVAudioRecorder alloc] initWithURL:_recordedFileURL settings:settings error:&error];
_audioRecorder.delegate = self;

if (error)
{
return;
}

[_audioRecorder prepareToRecord];
_audioRecorder.meteringEnabled = YES;
[_audioRecorder record];
}

-(void) stopRecord
{
[_audioRecorder stop];
}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
[self saveRecording];
}

-(void) saveRecording
{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_recordedFileURL.relativeString]];

NSLog(@"Recording data size = %i", [data length]);
}

如果有帮助,它会在 UIPopoverController 中调用...

最佳答案

自从发现问题是我漏了

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];

从这里iPhone SDK: AVAudioRecorder will not record after calling [AVPlayer play]

关于iphone - 使用 AVAudioRecorder 重新录制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14741844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com