1

I have the following Google Cloud call:

    var builder = new TextToSpeechClientBuilder();
    builder.JsonCredentials = @"...";

    var client = builder.Build();
    var data = client.SynthesizeSpeech(new SynthesisInput { Ssml = text },
        new VoiceSelectionParams { LanguageCode = culture.TwoLetterISOLanguageName },
        new AudioConfig { AudioEncoding = AudioEncoding.Linear16, SampleRateHertz = 8000 }).AudioContent;

It throws the following exception:

Grpc.Core.RpcException: 'Status(StatusCode="ResourceExhausted", Detail="Received message larger than max (4675411 vs. 4194304)")'

The request is less than 2000 bytes, so it seems that the response is too big. The server wants to send the response, but the client can't accept it. How to increase this limit?

UPDATE: Since version 2.2.0 it is possible to set the max response size:

var channelOptions = GrpcChannelOptions.Empty
    .WithKeepAliveTime(TimeSpan.FromMinutes(1))
    .WithEnableServiceConfigResolution(false)
    .WithMaxReceiveMessageSize(1024 * 1024 * 1024);
var builder = new TextToSpeechClientBuilder();
builder.JsonCredentials = jsonCredentials;
builder.GrpcChannelOptions = channelOptions;
zgabi
  • 404
  • 1
  • 4
  • 11
  • In order to increase the the received message limit, you can use `grpc.max_receive_message_length`, such as explained here:[1](https://stackoverflow.com/questions/42629047/how-to-increase-message-size-in-grpc-using-python) or [2](https://stackoverflow.com/questions/48170761/how-do-i-specify-server-options). Also, [this is the documentation](https://grpc.github.io/grpc/core/group__grpc__arg__keys.html#ga813f94f9ac3174571dd712c96cdbbdc1) for the suggested option. Did it work for you? – Alexandre Moraes Oct 05 '20 at 08:09
  • @AlexandreMoraes There is no such method in the C# TextToSpeech api – zgabi Oct 07 '20 at 13:46
  • according to the [documentation](https://grpc.github.io/grpc/csharp/api/Grpc.Core.ChannelOptions.html#Grpc_Core_ChannelOptions_MaxReceiveMessageLength) in C# you can use `MaxReceiveMessageLength`. The code would be as follows: `new ChannelOption(ChannelOptions.MaxReceiveMessageLength,int_value)` such these examples: [link1](https://github.com/grpc/grpc/issues/10657) and [link2](https://github.com/grpc/grpc/issues/15336). Was it what you were looking for? – Alexandre Moraes Oct 08 '20 at 06:37
  • @AlexandreMoraes No, I'm not creating channel object manually. I'm using the TextToSpeechClient(Builder) classes from Google.Cloud.TextToSpeech.V1 package.... it creates interally the channel. – zgabi Oct 09 '20 at 07:55

1 Answers1

2

In order to overcome the error Received message larger than max (4675411 vs. 4194304), you need to set the inbound message size to a greater value. You can do it when instantiating your builder, similarly as when creating a channel. Below, it is how you can do it:

textToSpeechClient = TextToSpeechClient.create(TextToSpeechSettings
 .newBuilder()
 .setTransportChannelProvider(
   TextToSpeechSettings.defaultGrpcTransportProviderBuilder()
    .setMaxInboundMessageSize(8790801)
    .build())
.build());

Here is the documentation for the setMaxInboundMessageSize method.

UPDATE: As I understand you want to use C# and since I could not find a method to set the inbound's message size, such as in Java (above). I have opened a a Public issue within Google. Although, I do not have an ETA for it, you can keep track here.

Alexandre Moraes
  • 3,892
  • 1
  • 6
  • 13
  • In C# the TextToSpeechSettings class has no NewBuilder method. It has only a GetDefault() method, which returns a TextToSpeechSettings object, which has no method to set the MaxInboundMessageSize. – zgabi Oct 13 '20 at 11:08
  • 1
    @zgabi, I have updated the answer with new information. – Alexandre Moraes Oct 14 '20 at 09:42
  • @zgabi, please consider accepting and upvoting the answer, in case you found the information useful. – Alexandre Moraes Oct 15 '20 at 09:16