Working with Amazon Transcribe and Amazon Translate

[version_1.0] The exercises in this course will have an associated charge in your AWS account. In this exercise, you will use the following resources: The exercise includes instructions to delete all the resources that you create.

Exercise 4: Working with Amazon Transcribe and Amazon Translate

[version_1.0]

Note

The exercises in this course will have an associated charge in your AWS account. In this exercise, you will use the following resources:

  • Amazon Simple Storage Service (Amazon S3) bucket
  • Amazon Transcribe Standard Batch Transcription API operation
  • Amazon Translate Standard Translation API operation

The exercise includes instructions to delete all the resources that you create.

Familiarize yourself with Amazon S3 pricing, Amazon TranscribepPricing, Amazon Translate pricing, and the AWS Free Tier.

In this exercise, you will use Amazon Transcribe to create a transcript for a video application. You will then use Amazon Translate to translate the transcript into Brazilian Portuguese.

The video application loads subtitles from the transcribe.json file. You will use Amazon Transcribe through the AWS Command Line Interface (AWS CLI) to process the supplied video, Raf01_320.mov, and create a corrected transcribe.json file.

Finally, you will use Amazon Translate to correct the translation in the translated.json file by completing and running the supplied transcribe_translate.py Python script.

Task 1: Running the application

In this task, you run the sample video application for the first time.

  • If you didn’t complete the first exercise, install the AWS SDK for Python (Boto3) and extract the exercise source:

    pip install boto3 wget RELATIVEdownloads/exercise-source.zipRELATIVE unzip exercise-source.zip

    Next, you will run the web application.

  • Use a new terminal window to launch the Python web server.

    You will keep the web server running for the remainder of the exercise.

    cd exercise-transcribe-translate python3 -m http.server 8080

    The application should now be running.

  • If you are using AWS Cloud9, you can preview the application by choosing Preview and then choosing Preview Running Application.

  • If you are using your own Python environment, access the application on http://localhost:8080/.

  • In the application, play the video to see the animation for the transcript and translation.

  • The application should display both the placeholder transcription from the transcribe.json file and the placeholder translation from the translated.json file.

    Task 2: Updating the transcript

    In this task, you create the updated transcribe.json. This task is an open challenge.

  • Use the AWS CLI to create a transcription job.

    Note For more information, see start-transcription-job in the AWS CLI documentation.

    The transcription will take a few minutes to run.

  • After the transcription is complete, retrieve the completed transcript by using get-transcription-job.

  • Capture the output into transcribe.json, and refresh the web application.

    Do you see the updated transcription text that was returned from Amazon Transcribe?

    If you are stuck, expand the following solution.

  • Expand for the full solution.
    • Create a bucket to store the video file. The name of the S3 bucket must be globally unique.

      aws s3 mb s3://<unique-bucket-name>
    • Copy the video file to the S3 bucket.

      aws s3 cp Raf01_320.mov s3://<unique-bucket-name>
    • Start the transcription job.

      aws transcribe start-transcription-job \  --transcription-job-name attempt01 \  --media MediaFileUri=s3://<unique-bucket-name>/Raf01_320.mov \  --language-code pt-BR
    • After the job is complete, retrieve the transcription URI.

      aws transcribe get-transcription-job \  --transcription-job-name attempt01 \  --query TranscriptionJob.Transcript.TranscriptFileUri \  --output text
    • Retrieve the transcription URI and overwrite the transcribe.json file.

      curl $(aws transcribe get-transcription-job \  --transcription-job-name attempt01 \  --query TranscriptionJob.Transcript.TranscriptFileUri \  --output text) > transcribe.json

    Task 3: Updating the translation

  • Open the transcribe_translate.py script in an editor.

  • Locate the Replace this code comment.

  • Replace the placeholder code with solution code that sets the translated_text variable with the translation from Amazon Transcribe.

  • Test your updates by running the script with python3 transcribe_translate.py.

  • When you are satisfied with your changes, replace the existing translated.json file.

    python3 transcribe_translate.py > translated.json
  • Refresh the web application.

    Do you see the translated text from Amazon Transcribe at the bottom of the application?

    If you get stuck, see the working solution in the solution-transcribe-translate folder.

  • Task 4: Cleaning up

    Remove the bucket that you created at the start of the exercise.

    # ensure the bucket is empty aws s3 rm s3://<unique-bucket-name>/Raf01_320.mov aws s3 rb s3://<unique-bucket-name>

    ncG1vNJzZmiZp6h6ta%2BMpZirn5Wkr6uxwq2qZ6tjY8K0edaeqq1lYmOurq3ZqKWar6NjsLC5jn18j2VxjKBuma5mhJqbmJ67ppjEmqmnoZ6cfKbExKuaoquVYoFvtNOmow%3D%3D

     Share!