2020-09-01 14:36:43 -07:00
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
2020-09-02 17:03:58 -07:00
Shows how to use AWS SDK for Python (Boto3) to call Amazon Transcribe to make a
2020-09-01 14:36:43 -07:00
transcription of an audio file.
2020-09-02 17:03:58 -07:00
This script is intended to be used with the instructions for getting started in the
Amazon Transcribe Developer Guide here:
2021-10-25 15:17:52 -07:00
https://docs.aws.amazon.com/transcribe/latest/dg/getting-started.html.
2020-09-01 14:36:43 -07:00
"""
# snippet-start:[transcribe.python.start-transcription-job]
import time
import boto3
def transcribe_file ( job_name , file_uri , transcribe_client ) :
transcribe_client . start_transcription_job (
TranscriptionJobName = job_name ,
2023-10-18 10:35:05 -07:00
Media = { " MediaFileUri " : file_uri } ,
MediaFormat = " wav " ,
LanguageCode = " en-US " ,
2020-09-01 14:36:43 -07:00
)
max_tries = 60
while max_tries > 0 :
max_tries - = 1
job = transcribe_client . get_transcription_job ( TranscriptionJobName = job_name )
2023-10-18 10:35:05 -07:00
job_status = job [ " TranscriptionJob " ] [ " TranscriptionJobStatus " ]
if job_status in [ " COMPLETED " , " FAILED " ] :
2020-09-01 14:36:43 -07:00
print ( f " Job { job_name } is { job_status } . " )
2023-10-18 10:35:05 -07:00
if job_status == " COMPLETED " :
2020-09-01 14:36:43 -07:00
print (
f " Download the transcript from \n "
2023-10-18 10:35:05 -07:00
f " \t { job [ ' TranscriptionJob ' ] [ ' Transcript ' ] [ ' TranscriptFileUri ' ] } . "
)
2020-09-01 14:36:43 -07:00
break
else :
print ( f " Waiting for { job_name } . Current status is { job_status } . " )
time . sleep ( 10 )
def main ( ) :
2023-10-18 10:35:05 -07:00
transcribe_client = boto3 . client ( " transcribe " )
file_uri = " s3://test-transcribe/answer2.wav "
transcribe_file ( " Example-job " , file_uri , transcribe_client )
2020-09-01 14:36:43 -07:00
2023-10-18 10:35:05 -07:00
if __name__ == " __main__ " :
2020-09-01 14:36:43 -07:00
main ( )
# snippet-end:[transcribe.python.start-transcription-job]