Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Disclaimer
  • Corona Virus Stats (Covid-19)
  • Work with us
  • FB
  • LinkedIn
  • Twitter
  • Instagram.com
Tekraze

Tekraze

Dive Into Technology

  • Guides
    • Developer Guide
    • PC Guide
    • Web Guide
    • Android Guide
    • Music
    • Tutorials
  • Feed
    • Tech News
    • Shared Tech
    • Gaming Videos
    • Unboxing videos
  • Forums
    • Android Apps
    • Angular Npm Packages
    • Useful Site Links
    • Tech Queries
    • Windows OS Help
    • Web Guide and Help
    • Android Os And Rooting
    • Jhipster Discussion
    • Git & GitHub forum
    • Open Source Forum
  • Work with us
  • Toggle search form
  • Future Skills - A Nasscom Initiative 1
    Future Skills – A Nasscom Initiative Tech News
  • The hottest new Tech you need to know Tekraze
    The Hottest New Tech You Need Now Guest posts
  • jio Coin
    22 Fake Cryptocurrency Apps under JioCoin name into Google Play store Tech News
  • Self Driven Startups and Embedded Tech Evolving Progressively in Past Decade 2
    Self Driven Startups and Embedded Tech Evolving Progressively in Past Decade Tech News
  • Triller App taking TikTok over AppStore
    Triller the app that is overtaking TikTok in the App Store? Tech News
  • Top Programming Languages That Largest Companies Are Hiring Developers For In 2018 3
    Top Programming Languages That Largest Companies Are Hiring Developers For In 2018 Tech News
  • India's richest man takes on Amazon, Walmart in e-commerce gamble 4
    India’s richest man takes on Amazon, Walmart in e-commerce gamble Tech News
  • Startups changing cleantech 🔌 Tech Feed
ADD AWS Transcribe to Spring Boot APP Tekraze

Add AWS Transcribe to Spring boot App

Posted on April 22, 2020March 29, 2022 By Balvinder Singh 2 Comments on Add AWS Transcribe to Spring boot App

Table of Contents

  • To Add AWS Transcribe to Spring Boot App follow
  • Steps for Integration
    • 1.Create A transcribe Account and setup credentials
    • 2.Setup SDK for Transcribe and S3(Required for upload)
    • 3. Create A java Service file to add content
    • 4. Initialize Clients for Transcribe and S3
    • 5. File upload/delete methods for S3. Skip if you want to use the file present on S3
    • 6. Start Transcription Process method
    • 7. Get Transcription Job Results Method
    • 8. Download Transcription Result method to fetch result from URI
    • 9. Delete the Transcription Job Method. To delete after processing is done, or it will automatically get deleted after 90 days.
    • 10. Combined method ExtractSpeechToText to Get Result of Transcription As a DTO
    • 11. Now, you can use the above methods to get your video/audio file processed and get the text from Speech.

To Add AWS Transcribe to Spring Boot App follow

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.

| Also Read | Add Amazon Comprehend To Spring Boot

Steps for Integration

1.Create A transcribe Account and setup credentials

2.Setup SDK for Transcribe and S3(Required for upload)

<!-- 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&lt;/version>
</dependency>
| Also Read | The right way to code and syntax you need to follow

3. Create A java Service file to add content

4. Initialize Clients for Transcribe and S3

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();
}

5. File upload/delete methods for S3. Skip if you want to use the file present on S3

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);
}
| Also Read | Things you need to know to be a Developer

6. Start Transcription Process method

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;
}

7. Get Transcription Job Results Method

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;
}
| Also Read | 5 Best Apps for programming Students

8. Download Transcription Result method to fetch result from URI

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

9. Delete the Transcription Job Method. To delete after processing is done, or it will automatically get deleted after 90 days.

void deleteTranscriptionJob(String jobName) {
log.debug("Delete Transcription Job from amazon Transcribe {}",jobName);
DeleteTranscriptionJobRequest deleteTranscriptionJobRequest = new DeleteTranscriptionJobRequest()
.withTranscriptionJobName(jobName);
transcribeClient().deleteTranscriptionJob(deleteTranscriptionJobRequest);
}
| Also Read | Things you need to know to be a pro developer

10. Combined method ExtractSpeechToText to Get Result of Transcription As a DTO

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;
}

11. Now, you can use the above methods to get your video/audio file processed and get the text from Speech.

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

| Also Read | Text Editors for Code

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

Content Protection by DMCA.com
Developer Guide Tags:Amazon, aws, code, SDK, spring boot

Post navigation

Previous Post: Add Amazon Comprehend to Spring Boot Project
Next Post: Tips to Take Care of Laptop in Summer

Related Posts

  • Banner image for how to deploy a static react app on Akash Decloud Network
    Easily Deploy a Static React App on Akash Network Cloud Developer Guide
  • Synaptic package manager in linux basics linux guide part 3 banner
    Synaptic package manager in Linux infographics basic Linux tools guide part 3 Developer Guide
  • How Bounty Hunting changed from web2 to web3 Bounty X hunter
    How Bounty Hunting changed from Web2 to Web3 with Bounty X Hunter Developer Guide
  • Laptop Showing Web application Development
    18 new Web Application Development Trends in 2023 Tech News
  • How to Encrypt Decrypt Files in Linux Tekraze
    How to Encrypt and Decrypt Files in Linux Tutorials
  • How to start with Competitive Programming ? 5
    How to start with Competitive Programming ? Developer Guide

Comments (2) on “Add AWS Transcribe to Spring boot App”

  1. Hi nice website https://google.com says:
    May 14, 2020 at 8:33 pm

    Hi nice website https://google.com

    Reply
    1. Balvinder Singh says:
      May 15, 2020 at 3:19 pm

      Thanks

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Advertisements

Subscribe to updates

Enter your email below to subscribe





Posts by Categories

Advertisements
  • A New Book in the Hood Javascript Grammar by JS Tut Banner
    A New Book in the Hood Javascript Grammar by JS Tut Developer Guide
  • Best Headless CMS examples
    Top 5 Best Headless CMS in 2022 Developer Guide
  • How To install Eclipse IDE - Video 6
    How To install Eclipse IDE – Video Tutorials
  • 7 Best Blog You must Visit 7
    7 Best Blog You must Visit Web Guide
  • Linux Terminology basics you need to know
    Developer Terminology – you need to know Developer Guide
  • Benefits of Providing Cyber Security Training to Your Employees Banner
    13 Benefits of Providing Cyber Security Training to Employees Emerging Startups
  • Backend Vs Front End - difference you need to Know 8
    Backend Vs Front End – difference you need to Know Developer Guide
  • beautify your wordpress blog tekraze
    Beautify your WordPress Blog Content Developer Guide

Affliate Links

Sell with Payhip

Earn with Magenet

Sell and Buy with Adsy

GainRock affiliate Program

Automatic Backlinks

Advertise with Anonymous Ads

accessily tekraze verificationIndian Blog Directory

Copyright © 2023 Tekraze.

Powered by PressBook News WordPress theme