You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iPad Pro M1 iOS15.0 使用SpeechKit报Code=201 Siri和听写已禁用问题

iOS SpeechKit 语音识别 kLSRErrorDomain Code=201 错误解决

问题出现环境

  • 设备:iPad Pro(3) M1
  • 系统版本:iOS 15.0
  • 项目背景:iOS 平台 Objective-C 项目,调用 Apple SpeechKit 框架实现语音识别功能

错误现象

触发语音识别时,会在 resultHandler 回调中抛出如下错误:
Error Domain=kLSRErrorDomain Code=201 "Siri and Dictation are disabled" UserInfo={NSLocalizedDescription=Siri and Dictation are disabled}
报错截图:
报错截图

相关代码(重置语音识别任务逻辑)

- (void)resetRecognitionTask
{
    // Cancel the previous task if it's running.
    if (self.recognitionTask) {
        //[self.recognitionTask cancel]; // Will cause the system error and memory problems.
        [self.recognitionTask finish];
    }
    self.recognitionTask = nil;
    
    // Configure the audio session for the app.
    NSError *error = nil;
    if (AVAudioSession.sharedInstance.categoryOptions != (AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth)) {
        [AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeMeasurement options:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:&error];
    }
    //[AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDuckOthers error:&error];
    if (error)
    {
        [self stopWithError:error];
        return;
    }
    [AVAudioSession.sharedInstance setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
    if (error)
    {
        [self stopWithError:error];
        return;
    }

    // Create and configure the speech recognition request.
    self.recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
    self.recognitionRequest.taskHint = SFSpeechRecognitionTaskHintConfirmation;
    
    // Keep speech recognition data on device
    if (@available(iOS 13, *)) {
        self.recognitionRequest.requiresOnDeviceRecognition = NO;
    }

    // Create a recognition task for the speech recognition session.
    // Keep a reference to the task so that it can be canceled.
    __weak typeof(self)weakSelf = self;
    self.speechRecognizer = nil;
    self.recognitionTask = [self.speechRecognizer recognitionTaskWithRequest:self.recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
        __strong typeof(self)strongSelf = weakSelf;
        if (result != nil) {
            [strongSelf resultCallback:result];
        }
    }];
}

修复方案

1. 修复代码逻辑错误

现有代码在创建识别任务前将self.speechRecognizer置为nil,空对象调用方法会直接触发异常,删除self.speechRecognizer = nil;这行代码,提前在模块初始化阶段完成SFSpeechRecognizer实例的初始化。

2. 补充权限与可用性校验

在触发语音识别前增加校验逻辑:

  • 调用[SFSpeechRecognizer authorizationStatus]检查应用是否已经获得语音识别权限,未授权时先发起权限申请
  • 调用[SFSpeechRecognizer isAvailable]检查当前设备语音识别功能是否可用
  • 若确定返回201错误,引导用户前往系统设置开启相关开关:打开「设置」>「Siri与搜索」,开启「按下侧边按钮使用Siri」,再进入「键盘」设置页,开启「启用听写」

3. 可选优化

如果业务场景支持离线语音识别,可以将self.recognitionRequest.requiresOnDeviceRecognition改为YES,降低对网络的依赖;不支持离线识别的场景,建议提前校验网络状态,避免无网时触发识别失败。

内容的提问来源于stack exchange,提问作者Jack Will

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 11:06:04