有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

IVONA SpeechCloud Java SDK中凭据文件出现maven错误

我只是尝试在IntelliJ IDEA中实现IVONA SpeechCloud Java SDK(使用特定的示例文件SampleIvonaSpeechCloudCreateSpeech.java,该文件应该能够“按原样”运行),但不断得到一个关于AWS凭据文件的错误,该文件无法加载

这就是它的样子: Screenshot from IntelliJ IDEA

在下载IVONA SpeechCloud Java SDK并使用Maven依赖从现有源代码创建新项目后,我更新了IVONA凭据。属性包含我的个人accessKeysecretKey的文件

我还更新了pom中的<dependencies>字段。包含以下代码的xml文件:

<dependency>
    <groupId>com.ivona</groupId>
    <artifactId>ivona-speechcloud-sdk-java</artifactId>
    <version>1.0.0</version>
</dependency>

有人知道如何修复Unable to load AWS credentials from the /resources/IvonaCredentials.properties file on the classpath错误吗


共 (1) 个答案

  1. # 1 楼答案

    好吧,我在源文件中花了几个小时才弄明白这一点。您可以创建自己的提供程序类,在其中可以将凭据作为字符串参数传入

    这是我的自定义凭证类“IvonaCredentials”

    import com.amazonaws.auth.AWSCredentials;
    import com.amazonaws.auth.AWSCredentialsProvider;
    
    public class IvonaCredentials implements AWSCredentialsProvider{
    
    public IvonaCredentials(String mSecretKey, String mAccessKey) {
        super();
        this.mSecretKey = mSecretKey;
        this.mAccessKey = mAccessKey;
    }
    
    private String mSecretKey;
    private String mAccessKey;
    
    @Override
    public AWSCredentials getCredentials() {
        AWSCredentials awsCredentials = new AWSCredentials() {
    
            @Override
            public String getAWSSecretKey() {
                // TODO Auto-generated method stub
                return mSecretKey;
            }
    
            @Override
            public String getAWSAccessKeyId() {
                // TODO Auto-generated method stub
                return mAccessKey;
            };
        };
        return awsCredentials;
    }
    
    @Override
    public void refresh() {
        // TODO Auto-generated method stub
    
    }
    
    
    
    }
    

    我就是这样称呼我的班级的

    private static void init() {
        speechCloud = new IvonaSpeechCloudClient(new IvonaCredentials("secretKey", "accessKey"));
        speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
    }