user1872371
user1872371

Reputation: 341

Google Text-to-speech doesn't run as CloudFunction

I tried to create a wrapper around Google Text-to-Speech copied verbatim from your help pages. From the logs it seems it tried to create a Jetty Instance(to forward the call to another service?) but fails as it can't assign it a network address by reading from the default. I will include the log output for your reference. Can you suggest changes to the code or a different strategy to use when using Cloudfunctions?

Log Output follows:

   "textPayload": "java.io.IOException: com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 19.821560546s. [buffered_nanos=2713815445, buffered_nanos=17108132243, waiting_for_connection]\n\tat com.gcp.cloudfunctions.Test.service(Test.java:91)\n\tat com.google.cloud.functions.invoker.NewHttpFunctionExecutor.service(NewHttpFunctionExecutor.java:67)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\tat com.google.cloud.functions.invoker.runner.Invoker$NotFoundHandler.handle(Invoker.java:379)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:500)\n\tat org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)\n\tat org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)\n\tat java.base/java.lang.Thread.run(Thread.java:834)\nCaused by: com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 19.821560546s. [buffered_nanos=2713815445, buffered_nanos=17108132243, waiting_for_connection]\n\tat com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:51)\n\tat com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)\n\tat com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)\n\tat com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)\n\tat com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)\n\tat com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:982)\n\tat com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)\n\tat com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1138)\n\tat com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:957)\n\tat com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:748)\n\tat io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:522)\n\tat io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:497)\n\tat io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)\n\tat io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)\n\tat io.grpc.internal.ClientCallImpl$1CloseInContext.runInContext(ClientCallImpl.java:416)\n\tat io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)\n\tat io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)\n\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\t... 1 more\n\tSuppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed\n\t\tat com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57)\n\t\tat com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)\n\t\tat com.google.cloud.texttospeech.v1beta1.TextToSpeechClient.synthesizeSpeech(TextToSpeechClient.java:268)\n\t\tat com.google.cloud.texttospeech.v1beta1.TextToSpeechClient.synthesizeSpeech(TextToSpeechClient.java:241)\n\t\tat com.gcp.cloudfunctions.CloudTextToSpeech.getSpeech(CloudTextToSpeech.java:97)\n\t\tat com.gcp.cloudfunctions.Test.service(Test.java:53)\n\t\tat com.google.cloud.functions.invoker.NewHttpFunctionExecutor.service(NewHttpFunctionExecutor.java:67)\n\t\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\t\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755)\n\t\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547)\n\t\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)\n\t\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)\n\t\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)\n\t\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)\n\t\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)\n\t\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)\n\t\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\t\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\t\tat com.google.cloud.functions.invoker.runner.Invoker$NotFoundHandler.handle(Invoker.java:379)\n\t\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)\n\t\tat org.eclipse.jetty.server.Server.handle(Server.java:500)\n\t\tat org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)\n\t\tat org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)\n\t\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)\n\t\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)\n\t\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)\n\t\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)\n\t\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)\n\t\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)\n\t\tat org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)\n\t\t... 1 more\nCaused by: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 19.821560546s. [buffered_nanos=2713815445, buffered_nanos=17108132243, waiting_for_connection]\n\tat io.grpc.Status.asRuntimeException(Status.java:533)\n\t... 12 more",
   "insertId": "000000-a16ab144-e2f2-4fe6-ae1a-fc939a327991",
   "resource": {
     "type": "cloud_function",
     "labels": {
       "region": "us-central1",
       "function_name": "function-1",
       "project_id": "nice-theater-281908"
     }
   },....

Update:

It turns out that the line causing a DEADLINE_EXCEEDED Error is the culprit. Googling the error showed that it may be because the client does not receive a response from the server in time (before timeout). Here is the line causing the error.

SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);

Any advice on how to work around it or how to increase the timeout for the process? Willing to give anything a shot.

Upvotes: 0

Views: 356

Answers (1)

Brendan
Brendan

Reputation: 1060

SynthesizeSpeech is a synchronous method so you have to wait for the response. Cloud Functions have a default timeout, but you can extend the timeout. You could also try breaking up the text so that it is smaller and thus more likely to finish within the Cloud Function time limit.

Upvotes: 1

Related Questions