簡體   English   中英

AWS Transcribe Java SDK:內部故障。 請重試您的請求

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

我在我的應用程序中集成了 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 的音頻文件可能有問題。 我建議你檢查一次。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM