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

iOS端Chrome中Web Speech API抛出"service-not-allowed"错误求助

iOS Chrome下Web Speech API触发"service-not-allowed"问题的解决方案

问题原因分析

iOS端Chrome基于WebKit内核,但Web Speech API的云端识别服务依赖谷歌后端服务,iOS系统的网络限制或Chrome内核适配问题,会导致即使授权麦克风权限,也无法正常调用该服务,从而抛出"service-not-allowed"错误——这和本地权限不足的"not-allowed"是完全不同的情况,谷歌官方Demo在iOS Chrome上无法运行也印证了这一点。

可行的解决方案

  • 确认HTTPS环境:Web Speech API要求必须在HTTPS协议下运行(localhost调试除外),确保iOS端访问的是HTTPS地址,HTTP环境下会直接限制API调用。
  • 检查语言代码精度:将recognition.lang设置为更精确的语言区域代码,比如zh-CN而非仅zh,iOS WebKit对语言代码的兼容性要求更严格,模糊的代码可能导致服务调用失败。
  • 验证系统级麦克风权限:进入iOS「设置」→「Chrome」,确认麦克风权限确实处于开启状态,有时候浏览器内的权限提示确认后,系统级权限可能未同步生效。
  • 排查网络访问限制:iOS端若开启了VPN、代理或系统级网络过滤,可能会阻止Chrome连接谷歌的语音识别服务,尝试关闭相关限制后再测试。
  • 切换至第三方语音识别服务:由于iOS Chrome对Web Speech API的支持存在长期兼容性问题,建议改用国内第三方语音识别API(如百度语音、阿里语音等),这类服务对iOS端的适配更完善,且无需依赖谷歌服务。
  • 尝试降级Chrome版本:部分新版本iOS Chrome可能存在API适配bug,可尝试安装旧版本Chrome测试是否能正常调用服务。

补充代码调整建议

针对原代码,可增加语言代码的容错处理,以及更详细的错误分支判断:

function startDictation() {
    try {
        var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
        var recognition = new SpeechRecognition();
    } catch (e) {
        console.error('Speech Recognition API not supported:', e);
        return;
    }

    if (recognition) {
        recognition.continuous = false;
        recognition.interimResults = true;
        // 使用精确的语言代码, fallback 到默认值
        recognition.lang = $('html').attr('lang') || 'zh-CN';

        recognition.onresult = function(e) {
            if (e.results[0].isFinal) {
                $('#searchInput').val(e.results[0][0].transcript);
                console.log('Final transcript:', e.results[0][0].transcript);
            }
        };

        recognition.onerror = (e) => {
            console.error('Speech recognition error:', e.error);
            // 针对service-not-allowed给出提示
            if (e.error === 'service-not-allowed') {
                alert('语音识别服务暂时无法访问,请检查网络或使用其他设备');
            }
            recognition.stop();
        };

        recognition.onend = () => {
            console.log('Speech recognition service disconnected');
        }

        recognition.start();
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 21:46:05