gpt4 book ai didi

java - AWS Polly Java 客户端出现错误 : Unable to load region information from any provider in the chain

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:39:46 24 4
gpt4 key购买 nike

我正在使用 AWS 的 JAVA SDK 创建一个 Polly 客户端。像这样:

BasicAWSCredentials awsCreds = new BasicAWSCredentials("<IAM access Key>", "IAM secret key>");

AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.build();


SynthesizeSpeechRequest tssRequest = new SynthesizeSpeechRequest();
tssRequest.setText(<text>);
tssRequest.setVoiceId(<voiceid>);
tssRequest.setOutputFormat(OutputFormat.Mp3);
SynthesizeSpeechResult tssResult = apClient.synthesizeSpeech(tssRequest);

当我运行这段代码时,我收到以下错误消息:

Exception in thread "main" com.amazonaws.SdkClientException: Unable to load region information from any provider in the chain at com.amazonaws.regions.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:56) at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:319) at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:295) at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:38) at com.eoffice.aws.speech.Polly.main(Polly.java:42)

我使用 IAM 策略模拟器检查了凭据。这工作正常,权限没问题。

在 ClientBuilder 中设置区域的方法对于 AmazonPollyClientBuilder 不可见,因此我没有(Java SDK)指定区域的方法。

更新:当我询问 defaultAwsREgionProviderChain 时,我收到相同的错误消息

DefaultAwsRegionProviderChain defaultAwsRegionProviderChain = new DefaultAwsRegionProviderChain();
System.out.println(defaultAwsRegionProviderChain.getRegion());

更新 2:当我在 de .aws 文件夹中创建一个包含以下内容的配置文件时:

[default] region = eu-west-1

它可以工作,但我需要一种不依赖文件系统的方法来设置它。

最佳答案

提供一个名为“AWS_REGION”的系统环境变量就可以了。查看 IBM Bluemix 中配置的屏幕截图

enter image description here

关于java - AWS Polly Java 客户端出现错误 : Unable to load region information from any provider in the chain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41612773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com