简体   繁体   中英

AWS Transcribe Java SDK: Internal Failure. Please try your request again

I have integrated AWS Java SDK in my applcaition.Unfoutunately am getting "Internal Failure. Please try your request again" as the response.

This is how I have implemeneted it.

Using Maven, added this in 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>

And in code,

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() {

                }
    };
}

The same thing is working with Python SDK. Same region, same wav file, same language, same settings, same output bucket etc. What am doing wrong??

Your flow looks correct. It may be an issue with the audio file you are uploading to AWS. I suggest you check it once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM