我已在自己的应用程序中集成了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文件,相同的语言,相同的设置,相同的输出存储桶等。这是怎么了?
答案 0 :(得分:1)
您的流程看起来正确。您要上传到AWS的音频文件可能有问题。我建议您检查一次。