クラウドスピーチAPIによる継続的なテスト... hereから別のサンプルをダウンロードしましたが、クラスClientAuthInterceptorが廃止されているため、少し修正しました。私は、サービスアカウントを使用していて、関連する使用されるコードはこれです:Googleプラットフォームのサービス認証で無効なJWT署名
// This is contained in the MainActivity code.
String fCred = _lu.getBasePath() + "auth.json";
try
{
InputStream isCred = new FileInputStream(fCred);
ManagedChannel channel = ManagedChannelBuilder.forAddress(HOSTNAME, PORT).build();
mStreamingClient = new StreamingRecognizeClient(channel, isCred, RECORDER_SAMPLERATE);
}
catch (IOException openEx)
{
Log.e(MainActivity.class.getSimpleName(), "Error", openEx);
}
// This is contained in the StreamingRecognizeClient class code
public StreamingRecognizeClient(ManagedChannel channel, InputStream credentials, int samplingRate) throws IOException
{
this.mSamplingRate = samplingRate;
this.mChannel = channel;
GoogleCredentials creds = GoogleCredentials.fromStream(credentials);
if (creds.createScopedRequired())
creds = creds.createScoped(OAUTH2_SCOPES);
CallCredentials callCreds = MoreCallCredentials.from(creds);
mSpeechClient = SpeechGrpc.newStub(channel).withCallCredentials(callCreds);
credentials.close();
}
すべてこのコードはアプリの初期化中に呼び出され、ファイルauth.jsonは、Googleのコンソールによって生成された認証ファイルですプロジェクトIDと秘密鍵に関するすべての情報が含まれています。 次に、関数recognBytesがオーディオデータの最初のチャンクで呼び出されます。実際のオーディオデータを送信する前に、あなたが唯一の認識の設定でメッセージを送信する必要があり、これは、この関数によって行われます:この最初の呼び出しの後
private void initializeRecognition() throws InterruptedException, IOException
{
requestObserver = mSpeechClient.streamingRecognize(this);
RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(AudioEncoding.FLAC).setSampleRate(mSamplingRate).build();
StreamingRecognitionConfig streamingConfig = StreamingRecognitionConfig.newBuilder().setConfig(config).setInterimResults(true).setSingleUtterance(true).build();
StreamingRecognizeRequest initial = StreamingRecognizeRequest.newBuilder().setStreamingConfig(streamingConfig).build();
requestObserver.onNext(initial);
}
で述べたように、私は何を得ることは400エラーコードは、あります以下のスタックトレース:リクエストに署名するすべてのプロセスは、Googleのライブラリによって行われるように、私は何ができるかを正確に知らない... は、私はすでににリクエストを送信した
11-30 15:34:12.916 3676-7309/? W/StreamingRecognizeClient: recognize failed: {0}: Status{code=UNAUTHENTICATED, description=null, cause=java.io.IOException: Error getting access token for service account: }
11-30 15:34:12.918 3676-7309/? E/StreamingRecognizeClient: Error to Recognize.
io.grpc.StatusRuntimeException: UNAUTHENTICATED
at me.yurifariasg.StreamingRecognizeClient.onError(StreamingRecognizeClient.java:98)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.IOException: Error getting access token for service account:
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:227)
at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:97)
at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:74)
at io.grpc.auth.GoogleAuthLibraryCallCredentials$1.run(GoogleAuthLibraryCallCredentials.java:113)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
{
"error" : "invalid_grant",
"error_description" : "Invalid JWT Signature."
}
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:225)
... 6 more
試用期間中にGoogleの技術サポートを利用できますが、多少のアドバイスがあります。
ありがとうございました。 012olf164。
私の友人(私がこの質問を投稿した人)は、あらかじめ録音済みのflacオーディオファイルを送信するWORKINGサンプルを作成しました。誰かが興味があれば私は働くコードを要求するでしょう。 Android Studioの小さなプロジェクトです。 –