AWS Transcribe or Amazon Transcribe uses a deep learning process called automatic speech recognition (ASR) to convert speech to text quickly and accurately. Amazon Transcribe can be used to transcribe customer service calls, to automate closed captioning and subtitling, and to generate metadata for media assets to create a fully searchable archive. Check here.
[su_note note_color=”#f5f5d4″ radius=”6″]| Also Read | Add Amazon Comprehend To Spring Boot [/su_note]
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.759</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-transcribe -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-transcribe</artifactId>
<version>1.11.759</version>
</dependency>
[su_note note_color=”#f5f5d4″ radius=”6″]| Also Read | The right way to code and syntax you need to follow [/su_note]
AmazonTranscribe transcribeClient() {
log.debug("Intialize Transcribe Client");
BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(awsCreds);
return AmazonTranscribeClientBuilder.standard().withCredentials(awsStaticCredentialsProvider)
.withRegion(awsRegion).build();
}
AmazonS3 s3Client() {
log.debug("Intialize AWS S3 Client");
BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(awsCreds);
return AmazonS3ClientBuilder.standard().withCredentials(awsStaticCredentialsProvider).withRegion(awsRegion)
.build();
}
public void uploadFileToAwsBucket(MultipartFile file) {
log.debug("Upload file to AWS Bucket {}", file);
String key = file.getOriginalFilename().replaceAll(" ", "_").toLowerCase();
try {
s3Client().putObject(bucketName, key, file.getInputStream(), null);
} catch (SdkClientException | IOException e) {
e.printStackTrace();
}
}
public void deleteFileFromAwsBucket(String fileName) {
log.debug("Delete File from AWS Bucket {}", fileName);
String key = fileName.replaceAll(" ", "_").toLowerCase();
s3Client().deleteObject(bucketName, key);
}
[su_note note_color=”#f5f5d4″ radius=”6″]| Also Read | Things you need to know to be a Developer [/su_note]
StartTranscriptionJobResult startTranscriptionJob(String key) {
log.debug("Start Transcription Job By Key {}",key);
Media media = new Media().withMediaFileUri(s3Client().getUrl(bucketName, key).toExternalForm());
String jobName = key.concat(RandomString.make());
StartTranscriptionJobRequest startTranscriptionJobRequest = new StartTranscriptionJobRequest()
.withLanguageCode(LanguageCode.EnUS).withTranscriptionJobName(jobName).withMedia(media);
StartTranscriptionJobResult startTranscriptionJobResult = transcribeClient()
.startTranscriptionJob(startTranscriptionJobRequest);
return startTranscriptionJobResult;
}
GetTranscriptionJobResult getTranscriptionJobResult(String jobName) {
log.debug("Get Transcription Job Result By Job Name : {}",jobName);
GetTranscriptionJobRequest getTranscriptionJobRequest = new GetTranscriptionJobRequest()
.withTranscriptionJobName(jobName);
Boolean resultFound = false;
TranscriptionJob transcriptionJob = new TranscriptionJob();
GetTranscriptionJobResult getTranscriptionJobResult = new GetTranscriptionJobResult();
while (resultFound == false) {
getTranscriptionJobResult = transcribeClient().getTranscriptionJob(getTranscriptionJobRequest);
transcriptionJob = getTranscriptionJobResult.getTranscriptionJob();
if (transcriptionJob.getTranscriptionJobStatus()
.equalsIgnoreCase(TranscriptionJobStatus.COMPLETED.name())) {
return getTranscriptionJobResult;
} else if (transcriptionJob.getTranscriptionJobStatus()
.equalsIgnoreCase(TranscriptionJobStatus.FAILED.name())) {
return null;
} else if (transcriptionJob.getTranscriptionJobStatus()
.equalsIgnoreCase(TranscriptionJobStatus.IN_PROGRESS.name())) {
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
log.debug("Interrupted Exception {}", e.getMessage());
}
}
}
return getTranscriptionJobResult;
}
[su_note note_color=”#f5f5d4″ radius=”6″]| Also Read | 5 Best Apps for programming Students [/su_note]
TranscriptionResponseDTO downloadTranscriptionResponse(String uri){
log.debug("Download Transcription Result from Transcribe URi {}", uri);
OkHttpClient okHttpClient = new OkHttpClient()
.newBuilder()
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.build();
Request request = new Request.Builder().url(uri).build();
Response response;
try {
response = okHttpClient.newCall(request).execute();
String body = response.body().string();
void deleteTranscriptionJob(String jobName) {
log.debug("Delete Transcription Job from amazon Transcribe {}",jobName);
DeleteTranscriptionJobRequest deleteTranscriptionJobRequest = new DeleteTranscriptionJobRequest()
.withTranscriptionJobName(jobName);
transcribeClient().deleteTranscriptionJob(deleteTranscriptionJobRequest);
}
[su_note note_color=”#f5f5d4″ radius=”6″]| Also Read | Things you need to know to be a pro developer [/su_note]
public TranscriptionResponseDTO extractSpeechTextFromVideo(MultipartFile file) {
log.debug("Request to extract Speech Text from Video : {}",file);
uploadFileToAwsBucket(file);
String key = file.getOriginalFilename().replaceAll(" ", "_").toLowerCase();
StartTranscriptionJobResult startTranscriptionJobResult = startTranscriptionJob(key);
String transcriptionJobName = startTranscriptionJobResult.getTranscriptionJob().getTranscriptionJobName();
GetTranscriptionJobResult getTranscriptionJobResult = getTranscriptionJobResult(transcriptionJobName);
deleteFileFromAwsBucket(key);
String transcriptFileUriString = getTranscriptionJobResult.getTranscriptionJob().getTranscript().getTranscriptFileUri();
TranscriptionResponseDTO transcriptionResponseDTO = downloadTranscriptionResponse(transcriptFileUriString);
deleteTranscriptionJob(transcriptionJobName);
return transcriptionResponseDTO;
}
The complete code Link is Here >>> Link to Gist
and for the response DTO check Link to Gist
Some references were taken from Edgardo Genini comment on StackOverflow here
[su_note note_color=”#f5f5d4″ radius=”6″]| Also Read | Text Editors for Code [/su_note]
I hope the code helps you, if yes please do share your support by Writing in the comments below. Keep Sharing and visiting back. Thanks
This post was last modified on March 29, 2022 9:57 pm
Struggling with a locked Samsung Galaxy or Note smartphone? Remove KG Lock, a U.S.-based company,…
When you open Adobe Photoshop for the first time, it's easy to click around in…
Social Media Influencer apps for mobile With the increasing number of social media platforms and…
Microsoft Dynamics 365 is a suite of Business Applications from Microsoft that covers the traditional…
While torrents and peer-to-peer (P2P) file sharing have long been popular for data transfer, concerns…
In today's increasingly interconnected world, reliable communication is paramount. But what happens when emergencies strike…
This website uses cookies.
View Comments
Hi nice website https://google.com
Thanks