相关疑难解决方法(0)

如何使用 Google TTS java 客户端修复“找不到策略‘pick_first’”?

我无法在 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);
    }
Run Code Online (Sandbox Code Playgroud)

我首先认为它来自凭据文件。但事实并非如此,该文件的位置正确。

我明白了。

avr. 02, 2019 11:36:46 PM …
Run Code Online (Sandbox Code Playgroud)

java google-text-to-speech

8
推荐指数
3
解决办法
3041
查看次数

标签 统计

google-text-to-speech ×1

java ×1