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

Android应用中Google Cloud Speech-to-Text V2设cmn-Hans-CN时遭CANCELLED错误

Google Cloud Speech-to-Text V2 中文流式识别CANCELLED错误问题

在Android(Java)应用中使用Google Cloud Speech-to-Text V2服务,设置languageCode为ja-JP或en-US时,流式识别功能可正常运行。但仅将语言代码切换为cmn-Hans-CN(或zh-CN)时,调用会立即失败并抛出CANCELLED错误。已确认相同代码与配置在ja-JP和en-US语言下可正常工作,尝试过cmn-Hans-CN和zh-CN两种语言代码均立即触发取消,且已验证网络连接与凭证有效。

环境与配置信息:

  • 模型:chirp_2
  • 端点:us-central1-speech.googleapis.com:443
  • SDK:com.google.cloud:speech-v2:latest
  • 平台:Android(Java)

相关代码片段:

// Build recognition config
RecognitionConfig config = RecognitionConfig.newBuilder()
    .setModel("chirp_2")
    .setLanguageCode("cmn-Hans-CN")  // ← 此处触发失败
    .build();
StreamingRecognitionConfig streamingConfig =
    StreamingRecognitionConfig.newBuilder()
        .setConfig(config)
        .build();

// Start streaming
try (SpeechClient client = SpeechClient.create(
         SpeechSettings.newBuilder()
             .setEndpoint("us-central1-speech.googleapis.com:443")
             .build())) {
    ClientStream<StreamingRecognizeRequest> stream =
        client.streamingRecognizeCallable()
              .splitCall(responseObserver);
    // First request with config
    stream.send(StreamingRecognizeRequest.newBuilder()
          .setStreamingConfig(streamingConfig)
          .build());
    // Then send audio data...
} catch (Exception e) {
    Log.e("SpeechTest", "Streaming failed", e);
}

错误日志:

com.google.api.gax.rpc.CancelledException: io.grpc.StatusRuntimeException: CANCELLED: The operation was cancelled.     at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:…)     at com.google.cloud.speech.v2.StreamingRecognizeClient.streamingRecognizeCallable(StreamingRecognizeClient.java:…)     … 05-14 16:42:40.052 26220 26279 E MyApp: com.google.api.gax.rpc.CancelledException: io.grpc.StatusRuntimeException: CANCELLED: The operation was cancelled.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 03:23:12