gpt4 book ai didi

ios - 为什么我的 iOS 设备检测不到我的声音?

转载 作者:可可西里 更新时间:2023-11-01 05:43:45 24 4
gpt4 key购买 nike

在我看来我写了

- (void)viewDidLoad 
{
[super viewDidLoad];

NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];

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

NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:@selector(levelTimerCallback:)
userInfo:nil
repeats:YES];
} else {
NSLog(@"%@",[error description]);
}
}

另一种实现方式是

- (void)levelTimerCallback:(NSTimer *)timer 
{
[recorder updateMeters];

const double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;

if (lowPassResults < 0.95)
NSLog(@"Mic blow detected");
else
NSLog(@"Person spoked");
}

当我使用我的 mac 麦克风在模拟器上运行我的代码时它可以工作,当我说话时出现“人说话”的情况,但是当我在真实的 IOS 设备上运行我的应用程序时它没有检测到任何声音,尽管我已在“设置”中为我的应用打开允许使用麦克风

我该怎么办?

最佳答案

请在您的 viewDidLoad 中使用以下行

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

这适用于您的 iOS 设备。

关于ios - 为什么我的 iOS 设备检测不到我的声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31262172/

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