gpt4 book ai didi

java - AWS Transcribe Java SDK : Internal Failure. 请重试您的请求

转载 作者:行者123 更新时间:2023-11-30 05:23:33 24 4
gpt4 key购买 nike

我已将 AWS Java SDK 集成到我的应用程序中。不幸的是,我收到“内部故障。请重试您的请求”作为响应。

这就是我实现它的方式。

使用 Maven,在 pom.xml 中添加此内容

<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>transcribe</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.10.12</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

在代码中,

String localAudioPath = "/home/****.wav";
String key = config.awsSecretAccessKey;
String keyId = config.awsAccessKeyId;
String regionString = config.awsRegion; //"ap-south-1"
String outputBucketName = config.awsOutputBucket;
Region region = Region.of(regionString);


String inputLanguage = "en-US";
LanguageCode languageCode = LanguageCode.fromValue(inputLanguage);


AwsCredentials credentials = AwsBasicCredentials.create(keyId, key);
AwsCredentialsProvider transcribeCredentials=StaticCredentialsProvider.create(credentials);

AWSCredentialsProvider s3AwsCredentialsProvider = getS3AwsCredentialsProvider(key, keyId);

String jobName = subJob.getId()+"_"+subJob.getProgram_name().replace(" ", "");
String fileName = jobName + ".wav";

AmazonS3 s3 =
AmazonS3ClientBuilder.standard().withRegion(regionString).withClientConfiguration(new
ClientConfiguration()).withCredentials(s3AwsCredentialsProvider).build();
s3.putObject(outputBucketName, fileName, new File(localAudioFilePath));

String fileUri = s3.getUrl(outputBucketName, fileName).toString();

System.out.println(fileUri);
Media media = Media.builder().mediaFileUri(fileUri).build();

String mediaFormat = MediaFormat.WAV.toString();
jobName = jobName +"_"+ System.currentTimeMillis();

Settings settings = Settings.builder()
.showSpeakerLabels(true)
.maxSpeakerLabels(10)
.build();

StartTranscriptionJobRequest request = StartTranscriptionJobRequest.builder()
.languageCode(languageCode)
.media(media)
.mediaFormat(mediaFormat)
.settings(settings)
.transcriptionJobName(jobName)
.build();

TranscribeAsyncClient client = TranscribeAsyncClient.builder()
.region(region)
.credentialsProvider(transcribeClientCredentialsProvider)
.build();

CompletableFuture<StartTranscriptionJobResponse> response =
client.startTranscriptionJob(request);

System.out.println(response.get().toString());

GetTranscriptionJobRequest jobRequest =
GetTranscriptionJobRequest.builder().transcriptionJobName(jobName).build();

while( true ){
CompletableFuture<GetTranscriptionJobResponse> transcriptionJobResponse =
client.getTranscriptionJob(jobRequest);


GetTranscriptionJobResponse response1 = transcriptionJobResponse.get();
if (response1 != null && response1.transcriptionJob() != null) {
if (response1.transcriptionJob().transcriptionJobStatus() ==
TranscriptionJobStatus.FAILED) {

//It comes here and gives response1.failureReason = "Internal Failure. Please try your request again".
break;
}
}
}

private AWSCredentialsProvider getS3AwsCredentialsProvider(String key, String keyId) {
return new AWSCredentialsProvider() {
@Override
public AWSCredentials getCredentials() {
return new AWSCredentials() {
@Override
public String getAWSAccessKeyId() {
return keyId;
}

@Override
public String getAWSSecretKey() {
return key;
}
};
}

@Override
public void refresh() {

}
};
}

使用 Python SDK 也有同样的效果。相同的地区、相同的 wav 文件、相同的语言、相同的设置、相同的输出存储桶等。我做错了什么?

最佳答案

您的流程看起来正确。这可能是您上传到 AWS 的音频文件存在问题。我建议你检查一次。

关于java - AWS Transcribe Java SDK : Internal Failure. 请重试您的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099643/

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