Amazon Transcribe 不总是需要使用 S3 存储。它提供了两种存储转录结果的选项:S3 存储和回调函数。
如果你选择使用 S3 存储,你需要创建一个 S3 存储桶,并将转录结果保存在该存储桶中。以下是一个使用 Amazon Transcribe 的 Python 代码示例,将转录结果保存到 S3 存储桶的方法:
import boto3
def transcribe_audio():
transcribe = boto3.client('transcribe')
job_name = 'your-job-name'
job_uri = 's3://your-audio-bucket/your-audio-file.wav'
output_bucket = 'your-output-bucket'
output_key = 'your-output-key'
response = transcribe.start_transcription_job(
TranscriptionJobName=job_name,
Media={'MediaFileUri': job_uri},
OutputBucketName=output_bucket,
OutputKey=output_key
)
print(response)
transcribe_audio()
另一种选项是使用回调函数来接收转录结果。你可以在调用 start_transcription_job 方法时提供一个回调函数的 URL,Amazon Transcribe 将转录结果发送到该 URL。以下是一个使用回调函数的 Python 代码示例:
import boto3
def transcribe_audio():
transcribe = boto3.client('transcribe')
job_name = 'your-job-name'
job_uri = 's3://your-audio-bucket/your-audio-file.wav'
callback_url = 'https://your-callback-url.com'
response = transcribe.start_transcription_job(
TranscriptionJobName=job_name,
Media={'MediaFileUri': job_uri},
OutputBucketName=output_bucket,
OutputKey=output_key,
CallbackSettings={'CallbackUrl': callback_url}
)
print(response)
transcribe_audio()
无论使用哪种存储选项,你都可以根据需求选择最适合的方式来处理转录结果。