简体   繁体   English

在 Android 4.2 上运行 google cloud speech api

[英]Running google cloud speech api on Android 4.2

I have a problem running io.grpc:grpc-okhttp on Android 4.2 devices.我在 Android 4.2 设备上运行 io.grpc:grpc-okhttp 时遇到问题。

I have implemented SpeechClient with Credentials, for running Google cloud speech to text.我已经使用 Credentials 实现了 SpeechClient,用于将 Google 云语音运行到文本。 On Android 7.1 device I don't have a problem.在 Android 7.1 设备上我没有遇到问题。 The problems happen on Android 4.2问题发生在 Android 4.2

So in my starting gradle I had所以在我开始时 gradle 我有

implementation 'io.grpc:grpc-okhttp:1.35.0'
implementation 'io.grpc:grpc-android:1.35.0'
implementation 'com.google.cloud:google-cloud-speech:1.24.0'

Problems.问题。

  1. First problem was with TLS security for SSL (which is too old on Android 4.2).第一个问题是 SSL 的 TLS 安全性(在 Android 4.2 上太旧了)。 For this, I added dependency为此,我添加了依赖

    implementation 'org.conscrypt:conscrypt-android:2.5.1'

    and implemented in my DialogFragment (which is running the code)并在我的 DialogFragment 中实现(正在运行代码)

     Security.insertProviderAt(Conscrypt.newProvider(), 1)
  2. After I implemented this, I am getting在我实施这个之后,我得到了

    Duplicate class org.conscrypt.AbstractConscryptEngine found in modules jetified-conscrypt-android-2.5.1-runtime (org.conscrypt:conscrypt-android:2.5.1) and jetified-conscrypt-openjdk-uber-2.2.1 (org.conscrypt:conscrypt-openjdk-uber:2.2.1)

    issues (alot of duplicated classes) So for fixing this, I added问题(很多重复的类)所以为了解决这个问题,我添加了

    configurations { all { exclude group: "org.conscrypt", module: "conscrypt-openjdk-uber" } }
  3. Now I get this error, because com.google.api.client is using Standard.UTF-8 and my device is on Android 17.现在我得到这个错误,因为 com.google.api.client 正在使用 Standard.UTF-8 而我的设备在 Android 17。

com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
        at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:73)
        at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
        at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
        at com.google.api.gax.grpc.ExceptionResponseObserver.onErrorImpl(ExceptionResponseObserver.java:82)
        at com.google.api.gax.rpc.StateCheckingResponseObserver.onError(StateCheckingResponseObserver.java:86)
        at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149)
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)
        at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
     Caused by: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
        at io.grpc.Status.asRuntimeException(Status.java:533)
        at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149) 
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426) 
        at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66) 
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689) 
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577) 
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751) 
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740) 
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) 
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
        at java.lang.Thread.run(Thread.java:856) 
     Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
        at com.google.api.client.util.StringUtils.getBytesUtf8(StringUtils.java:51)
        at com.google.api.client.json.webtoken.JsonWebSignature.signUsingRsaSha256(JsonWebSignature.java:571)
        at com.google.auth.oauth2.JwtCredentials.refresh(JwtCredentials.java:125)
        at com.google.auth.oauth2.JwtCredentials.getRequestMetadata(JwtCredentials.java:163)
        at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:365)
        at com.google.auth.Credentials.blockingGetToCallback(Credentials.java:112)
        at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:341)
        at io.grpc.auth.GoogleAuthLibraryCallCredentials.applyRequestMetadata(GoogleAuthLibraryCallCredentials.java:110)
        at io.grpc.CallCredentials2.applyRequestMetadata(CallCredentials2.java:58)
        at io.grpc.internal.CallCredentialsApplyingTransportFactory$CallCredentialsApplyingTransport.newStream(CallCredentialsApplyingTransportFactory.java:108)
        at io.grpc.internal.ForwardingConnectionClientTransport.newStream(ForwardingConnectionClientTransport.java:49)
        at io.grpc.internal.InternalSubchannel$CallTracingTransport.newStream(InternalSubchannel.java:671)
        at io.grpc.internal.DelayedClientTransport$PendingStream.createRealStream(DelayedClientTransport.java:353)
        at io.grpc.internal.DelayedClientTransport$PendingStream.access$300(DelayedClientTransport.java:341)

Question:题:

  1. How to resolve this issue and run Speech with "ApiStreamObserver? I tried reverting back "io.grpc:grpc-" libraries to version 1.0 or something, but then I have other problems...如何解决此问题并使用“ApiStreamObserver”运行语音?我尝试将“io.grpc:grpc-”库恢复到 1.0 版或其他版本,但后来我遇到了其他问题...

I have resolved this issue and commited example project on Github我已经解决了这个问题并在 Github 上提交了示例项目

https://github.com/DjToMeK27/CloudGoogleSpeechToText/tree/main https://github.com/DjToMeK27/CloudGoogleSpeechToText/tree/main

What I did in this project我在这个项目中做了什么

  1. Downloaded https://github.com/GoogleCloudPlatform/android-docs-samples/blob/master/README.md下载https://github.com/GoogleCloudPlatform/android-docs-samples/blob/master/README.md
  2. Changed classes in project SpeechRecognitionClient in android-docs-samples-master\speech在 android-docs-samples-master\speech 中更改了项目 SpeechRecognitionClient 中的类
    • Changed AudioRecord in AudoEmitter.kt to support API 16更改了 AudoEmitter.kt 中的 AudioRecord 以支持 API 16
  3. Imported org.conscrypt:conscrypt-android:2.5.1 library导入 org.conscrypt:conscrypt-android:2.5.1 库
    • Had to exclude group org.conscrypt from google-cloud-speech (in build.gradle)必须从 google-cloud-speech 中排除组 org.conscrypt(在 build.gradle 中)
  4. Added init { Security.insertProviderAt(Conscrypt.newProvider(), 1) } For Android 4.1 to run proper TLS for GRC to work添加了 init { Security.insertProviderAt(Conscrypt.newProvider(), 1) } 对于 Android 4.1 运行正确的 TLS 以使 GRC 工作
  5. I downloaded https://github.com/googleapis project我下载了 https://github.com/googleapis项目
    • Changed all StandardCharsets found in google-http-client to Charset.forName())将在 google-http-client 中找到的所有 StandardCharsets 更改为 Charset.forName())
    • And also changed some tests to work并且还改变了一些测试工作
    • https://imgur.com/a/iU7yjCZ (files changes) https://imgur.com/a/iU7yjCZ (文件改动)
  6. I have build this project and added.jar files, which I included here我已经构建了这个项目并添加了 .jar 文件,我将其包含在此处
  7. And now it works!现在它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Text To Speech API 强制发音为单词 - Google Cloud Text To Speech API force pronunciation as word 使用本机 JavaScript 向 Google Cloud 文本转语音 API 进行身份验证 - Authenticate to Google Cloud text-to-speech API using native JavaScript 尝试访问谷歌云语音时 JSON 有效载荷出错 api - Error in JSON payload while trying to access google cloud speech api Firebase 具有用于文本到语音的谷歌应用程序凭据的云功能 API - Firebase cloud functions with google application credentials for text to speech API 如何在 c# 中为 Google Cloud Txt-To-Speech API 设置代理设置 - How can I setup proxy settings in c# for Google Cloud Txt-To-Speech API 使用 Dialogflow 和 Google Cloud Speech 在 web 应用程序中构建我自己的对话语音 AI API - Building my own conversational voice AI with Dialogflow & Google Cloud Speech API in web apps TransportError:从 Python 2.7 调用 Google Cloud Speech API 时出现 HTTPSConnectionPool 错误 - TransportError: HTTPSConnectionPool error calling Google Cloud Speech API from Python 2.7 Google Cloud Speech to Text 准确性问题 - Google Cloud Speech to Text Accuracy Issue 谷歌语音 API Python 无响应 - Google Speech API Python not responding 如何允许团队成员使用我的 Google Cloud Speech-to-Text API 帐户? - How do I allow a team member to use my Google Cloud Speech-to-Text API account?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM