どのようにGoogleのTTSのJavaクライアントで「『pick_first』ポリシーが見つかりませんでした」修正するには?

LimelioN:

私はJavaでGoogleのTTSクライアントライブラリを使用して要求をすることはできません。たびに、それは例外の束をスローします。

私は可能な声のリストを取得しよう。

    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) {
        e.printStackTrace();
        System.exit(-2);
    }

    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());
        }
        textToSpeechClient.close();
        System.exit(0);
    }

私が最初にそれが資格証明書ファイルから来たと思いました。しかし、それは、ファイルが正しく配置されていません。

そして、私はこれを取得します。

avr. 02, 2019 11:36:46 PM io.grpc.internal.ManagedChannelImpl$1 uncaughtException
SEVERE: [Channel<1>: (texttospeech.googleapis.com:443)] 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>(AutoConfiguredLoadBalancerFactory.java:93)
        at io.grpc.internal.AutoConfiguredLoadBalancerFactory.newLoadBalancer(AutoConfiguredLoadBalancerFactory.java:64)
        at io.grpc.internal.ManagedChannelImpl.exitIdleMode(ManagedChannelImpl.java:357)
        at io.grpc.internal.ManagedChannelImpl$ChannelTransportProvider$1ExitIdleModeForTransport.run(ManagedChannelImpl.java:455)
        at io.grpc.SynchronizationContext.drain(SynchronizationContext.java:101)
        at io.grpc.SynchronizationContext.execute(SynchronizationContext.java:130)
        at io.grpc.internal.ManagedChannelImpl$ChannelTransportProvider.get(ManagedChannelImpl.java:459)
        (...) a whole bunch of other lines

どのようにこのエラーを修正するには?

私は、最新のGoogleクラウド - テキスト読み上げのライブラリを使用していることに注意してください。(バージョン0.85.0-β)。

dhontecillas:

io.grpcライブラリには、あなたの中のファイルからクラスを登録しますMETA-INF/services

だから、という名前のファイルを作成しio.grpc.LoadBalancerProviderたコンテンツでそのフォルダ内を:

io.grpc.internal.PickFirstLoadBalancerProvider

ライブラリは、クラスにその方法を見つける必要があります。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=185504&siteId=1