2

I have a AWS Transcribe job that gives me a URI when completed. This URI should be where the transcription text is stored. I want to access that text with the Java SDK, but GetObject does not seem to support this option. How do I access the text from the Transcribe job?

// I am given this
String URI = job.getTranscript().getTranscriptFileUri();
// I want to do this
S3Object transcript = s3.getObject(URI);
Oscar Courchaine
  • 346
  • 3
  • 14

1 Answers1

2

You need to parse the bucket and the object key from the given URI, or you can use the provided class from AWS SDK, the AmazonS3URI. Then do as follows:

String URI = job.getTranscript().getTranscriptFileUri();
AmazonS3URI s3ObjectURI = new AmazonS3URI(URI);
S3Object transcript = s3.getObject(s3ObjectURI.getBucket(), s3ObjectURI.getKey());
Rodel
  • 543
  • 6
  • 15
  • I try this method but throws the next error. com.amazonaws.services.s3.model.AmazonS3Exception: Your key is too long (Service: Amazon S3; Status Code: 400; Error Code: KeyTooLongError; – Israel Perales Dec 12 '20 at 01:38
  • The error you've encountered might be an error after transcribed. Because if transcribed result was accepted by S3 it means the object key is not too long. So getting the S3 object will not throw KeyTooLongError. – Rodel Dec 14 '20 at 08:15
  • Finally i use httpOk library to get the JSON file and parse this JSON to an Java object. `String URI = result.getTranscriptionJob().getTranscript().getTranscriptFileUri(); TranscriptionResponseDTO transcriptionResponseDTO = awsUtil.downloadTranscriptionResponse(URI);` I publish my alternative on the answers – Israel Perales Dec 15 '20 at 02:12