Skip to content

How to fix “Could not find policy ‘pick_first'” with Google TTS java client?

I can’t make a request using Google TTS Client library in java. Each time it throws a bunch of exceptions.

I just try to get a list of available voices.

    GoogleCredentials creds = null;
    TextToSpeechClient textToSpeechClient = null;
    try {
        creds = GoogleCredentials.fromStream(new FileInputStream(credsFile));
        TextToSpeechSettings settings = TextToSpeechSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(creds)).build();
        textToSpeechClient = TextToSpeechClient.create(settings);
    } catch (IOException e) {

    if (cmd.hasOption('l')) {
        ListVoicesRequest request = ListVoicesRequest.getDefaultInstance();
        ListVoicesResponse response = textToSpeechClient.listVoices(request);
        List<Voice> voices = response.getVoicesList();
        System.out.println("Available voices :");
        for (Voice v : voices) {
            System.out.printf(" - %s, [%d]: %s/%s", v.getName(), v.getLanguageCodesCount(), v.getLanguageCodes(0), v.getSsmlGender());

I first thought it came from the credentials file. But it’s not, the file is correctly located.

And I get this.

avr. 02, 2019 11:36:46 PM io.grpc.internal.ManagedChannelImpl$1 uncaughtException
SEVERE: [Channel<1>: (] Uncaught exception in the SynchronizationContext. Panic!
java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.
        at io.grpc.internal.AutoConfiguredLoadBalancerFactory$AutoConfiguredLoadBalancer.<init>(
        at io.grpc.internal.AutoConfiguredLoadBalancerFactory.newLoadBalancer(
        at io.grpc.internal.ManagedChannelImpl.exitIdleMode(
        at io.grpc.internal.ManagedChannelImpl$ChannelTransportProvider$
        at io.grpc.SynchronizationContext.drain(
        at io.grpc.SynchronizationContext.execute(
        at io.grpc.internal.ManagedChannelImpl$ChannelTransportProvider.get(
        (...) a whole bunch of other lines

How to fix this error ?

Note that I’m using the latest google-cloud-texttospeech library (version 0.85.0-beta).



If you’re using Gradle with the ShadowJar plugin, this is all you need to get it to merge the contents of service files from the various gRPC libraries:

shadowJar {

Discovered from a thread here.