文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
StartTranscriptionJob
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 StartTranscriptionJob
。
操作示例是大型程序的代码摘录,必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <summary> /// Start a transcription job for a media file. This method returns /// as soon as the job is started. /// </summary> /// <param name="jobName">A unique name for the transcription job.</param> /// <param name="mediaFileUri">The URI of the media file, typically an Amazon S3 location.</param> /// <param name="mediaFormat">The format of the media file.</param> /// <param name="languageCode">The language code of the media file, such as en-US.</param> /// <param name="vocabularyName">Optional name of a custom vocabulary.</param> /// <returns>A TranscriptionJob instance with information on the new job.</returns> public async Task<TranscriptionJob> StartTranscriptionJob(string jobName, string mediaFileUri, MediaFormat mediaFormat, LanguageCode languageCode, string? vocabularyName) { var response = await _amazonTranscribeService.StartTranscriptionJobAsync( new StartTranscriptionJobRequest() { TranscriptionJobName = jobName, Media = new Media() { MediaFileUri = mediaFileUri }, MediaFormat = mediaFormat, LanguageCode = languageCode, Settings = vocabularyName != null ? new Settings() { VocabularyName = vocabularyName } : null }); return response.TranscriptionJob; }
-
有关 API 的详细信息,请参阅 AWS SDK for .NET API 参考StartTranscriptionJob中的。
-
- CLI
-
- AWS CLI
-
示例 1:转录音频文件
以下
start-transcription-job
示例转录音频文件。aws transcribe start-transcription-job \ --cli-input-json
file://myfile.json
myfile.json
的内容:{ "TranscriptionJobName": "cli-simple-transcription-job", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" } }
有关更多信息,请参阅《Amazon Transcribe 开发者指南》中的入门(AWS 命令行界面)。
示例 2:转录多声道音频文件
以下
start-transcription-job
示例转录多声道音频文件。aws transcribe start-transcription-job \ --cli-input-json
file://mysecondfile.json
mysecondfile.json
的内容:{ "TranscriptionJobName": "cli-channelid-job", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "Settings":{ "ChannelIdentification":true } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-channelid-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "StartTime": "2020-09-17T16:07:56.817000+00:00", "CreationTime": "2020-09-17T16:07:56.784000+00:00", "Settings": { "ChannelIdentification": true } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的转录多声道音频。
示例 3:转录音频文件并识别不同的发言者
以下
start-transcription-job
示例转录音频文件,并在转录输出中识别发言者。aws transcribe start-transcription-job \ --cli-input-json
file://mythirdfile.json
mythirdfile.json
的内容:{ "TranscriptionJobName": "cli-speakerid-job", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "Settings":{ "ShowSpeakerLabels": true, "MaxSpeakerLabels": 2 } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-speakerid-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "StartTime": "2020-09-17T16:22:59.696000+00:00", "CreationTime": "2020-09-17T16:22:59.676000+00:00", "Settings": { "ShowSpeakerLabels": true, "MaxSpeakerLabels": 2 } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的识别发言者。
示例 4:转录音频文件并在转录输出中屏蔽任何不需要的单词
以下
start-transcription-job
示例转录音频文件,并使用您以前创建的词汇表过滤器屏蔽任何不需要的单词。aws transcribe start-transcription-job \ --cli-input-json
file://myfourthfile.json
myfourthfile.json
的内容:{ "TranscriptionJobName": "cli-filter-mask-job", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "Settings":{ "VocabularyFilterName": "your-vocabulary-filter", "VocabularyFilterMethod": "mask" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-filter-mask-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://Amazon-S3-Prefix/your-media-file.file-extension" }, "StartTime": "2020-09-18T16:36:18.568000+00:00", "CreationTime": "2020-09-18T16:36:18.547000+00:00", "Settings": { "VocabularyFilterName": "your-vocabulary-filter", "VocabularyFilterMethod": "mask" } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的过滤转录。
示例 5:转录音频文件并在转录输出中删除任何不需要的单词
以下
start-transcription-job
示例转录音频文件,并使用您以前创建的词汇表过滤器屏蔽任何不需要的单词。aws transcribe start-transcription-job \ --cli-input-json
file://myfifthfile.json
myfifthfile.json
的内容:{ "TranscriptionJobName": "cli-filter-remove-job", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "Settings":{ "VocabularyFilterName": "your-vocabulary-filter", "VocabularyFilterMethod": "remove" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-filter-remove-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "StartTime": "2020-09-18T16:36:18.568000+00:00", "CreationTime": "2020-09-18T16:36:18.547000+00:00", "Settings": { "VocabularyFilterName": "your-vocabulary-filter", "VocabularyFilterMethod": "remove" } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的过滤转录。
示例 6:使用自定义词汇表更准确地转录音频文件
以下
start-transcription-job
示例转录音频文件,并使用您以前创建的词汇表过滤器屏蔽任何不需要的单词。aws transcribe start-transcription-job \ --cli-input-json
file://mysixthfile.json
mysixthfile.json
的内容:{ "TranscriptionJobName": "cli-vocab-job", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "Settings":{ "VocabularyName": "your-vocabulary" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-vocab-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "the-language-of-your-transcription-job", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "StartTime": "2020-09-18T16:36:18.568000+00:00", "CreationTime": "2020-09-18T16:36:18.547000+00:00", "Settings": { "VocabularyName": "your-vocabulary" } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的过滤转录。
示例 7:识别音频文件语言并转录该文件
以下
start-transcription-job
示例转录音频文件,并使用您以前创建的词汇表过滤器屏蔽任何不需要的单词。aws transcribe start-transcription-job \ --cli-input-json
file://myseventhfile.json
myseventhfile.json
的内容:{ "TranscriptionJobName": "cli-identify-language-transcription-job", "IdentifyLanguage": true, "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-identify-language-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/Amazon-S3-prefix/your-media-file-name.file-extension" }, "StartTime": "2020-09-18T22:27:23.970000+00:00", "CreationTime": "2020-09-18T22:27:23.948000+00:00", "IdentifyLanguage": true } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的识别语言。
示例 8:转录音频文件并编辑个人身份信息
以下
start-transcription-job
示例转录音频文件,并在转录输出中编辑任何个人身份信息。aws transcribe start-transcription-job \ --cli-input-json
file://myeighthfile.json
myeigthfile.json
的内容:{ "TranscriptionJobName": "cli-redaction-job", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://Amazon-S3-Prefix/your-media-file.file-extension" }, "ContentRedaction": { "RedactionOutput":"redacted", "RedactionType":"PII" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-redaction-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://Amazon-S3-Prefix/your-media-file.file-extension" }, "StartTime": "2020-09-25T23:49:13.195000+00:00", "CreationTime": "2020-09-25T23:49:13.176000+00:00", "ContentRedaction": { "RedactionType": "PII", "RedactionOutput": "redacted" } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的自动内容编辑。
示例 9:生成个人身份信息 (PII) 经过编辑和未经过编辑的转录
以下
start-transcription-job
示例生成两个音频文件转录,一个转录中的个人身份信息经过编辑,另一个转录没有进行任何编辑。aws transcribe start-transcription-job \ --cli-input-json
file://myninthfile.json
myninthfile.json
的内容:{ "TranscriptionJobName": "cli-redaction-job-with-unredacted-transcript", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://Amazon-S3-Prefix/your-media-file.file-extension" }, "ContentRedaction": { "RedactionOutput":"redacted_and_unredacted", "RedactionType":"PII" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-redaction-job-with-unredacted-transcript", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://Amazon-S3-Prefix/your-media-file.file-extension" }, "StartTime": "2020-09-25T23:59:47.677000+00:00", "CreationTime": "2020-09-25T23:59:47.653000+00:00", "ContentRedaction": { "RedactionType": "PII", "RedactionOutput": "redacted_and_unredacted" } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的自动内容编辑。
示例 10:使用您以前创建的自定义语言模型转录音频文件
以下
start-transcription-job
示例使用您以前创建的自定义语言模型转录音频文件。aws transcribe start-transcription-job \ --cli-input-json
file://mytenthfile.json
mytenthfile.json
的内容:{ "TranscriptionJobName": "cli-clm-2-job-1", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/your-audio-file.file-extension" }, "ModelSettings": { "LanguageModelName":"cli-clm-2" } }
输出:
{ "TranscriptionJob": { "TranscriptionJobName": "cli-clm-2-job-1", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://amzn-s3-demo-bucket/your-audio-file.file-extension" }, "StartTime": "2020-09-28T17:56:01.835000+00:00", "CreationTime": "2020-09-28T17:56:01.801000+00:00", "ModelSettings": { "LanguageModelName": "cli-clm-2" } } }
有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的使用自定义语言模型提高特定领域的转录准确性。
-
有关 API 的详细信息,请参阅AWS CLI 命令参考StartTranscriptionJob
中的。
-
- JavaScript
-
- 适用于 JavaScript (v3) 的软件开发工具包
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 启动转录作业。
// Import the required AWS SDK clients and commands for Node.js import { StartTranscriptionJobCommand } from "@aws-sdk/client-transcribe"; import { transcribeClient } from "./libs/transcribeClient.js"; // Set the parameters export const params = { TranscriptionJobName: "JOB_NAME", LanguageCode: "LANGUAGE_CODE", // For example, 'en-US' MediaFormat: "SOURCE_FILE_FORMAT", // For example, 'wav' Media: { MediaFileUri: "SOURCE_LOCATION", // For example, "https://transcribe-demo.s3-REGION.amazonaws.com/hello_world.wav" }, OutputBucketName: "OUTPUT_BUCKET_NAME", }; export const run = async () => { try { const data = await transcribeClient.send( new StartTranscriptionJobCommand(params), ); console.log("Success - put", data); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
创建客户端。
import { TranscribeClient } from "@aws-sdk/client-transcribe"; // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create an Amazon Transcribe service client object. const transcribeClient = new TranscribeClient({ region: REGION }); export { transcribeClient };
-
有关更多信息,请参阅《AWS SDK for JavaScript 开发人员指南》。
-
有关 API 的详细信息,请参阅 AWS SDK for JavaScript API 参考StartTranscriptionJob中的。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 def start_job( job_name, media_uri, media_format, language_code, transcribe_client, vocabulary_name=None, ): """ Starts a transcription job. This function returns as soon as the job is started. To get the current status of the job, call get_transcription_job. The job is successfully completed when the job status is 'COMPLETED'. :param job_name: The name of the transcription job. This must be unique for your AWS account. :param media_uri: The URI where the audio file is stored. This is typically in an Amazon S3 bucket. :param media_format: The format of the audio file. For example, mp3 or wav. :param language_code: The language code of the audio file. For example, en-US or ja-JP :param transcribe_client: The Boto3 Transcribe client. :param vocabulary_name: The name of a custom vocabulary to use when transcribing the audio file. :return: Data about the job. """ try: job_args = { "TranscriptionJobName": job_name, "Media": {"MediaFileUri": media_uri}, "MediaFormat": media_format, "LanguageCode": language_code, } if vocabulary_name is not None: job_args["Settings"] = {"VocabularyName": vocabulary_name} response = transcribe_client.start_transcription_job(**job_args) job = response["TranscriptionJob"] logger.info("Started transcription job %s.", job_name) except ClientError: logger.exception("Couldn't start transcription job %s.", job_name) raise else: return job
-
有关 API 的详细信息,请参阅适用StartTranscriptionJob于 Python 的AWS SDK (Boto3) API 参考。
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <summary> /// Start a transcription job for a media file. This method returns /// as soon as the job is started. /// </summary> /// <param name="jobName">A unique name for the transcription job.</param> /// <param name="mediaFileUri">The URI of the media file, typically an Amazon S3 location.</param> /// <param name="mediaFormat">The format of the media file.</param> /// <param name="languageCode">The language code of the media file, such as en-US.</param> /// <param name="vocabularyName">Optional name of a custom vocabulary.</param> /// <returns>A TranscriptionJob instance with information on the new job.</returns> public async Task<TranscriptionJob> StartTranscriptionJob(string jobName, string mediaFileUri, MediaFormat mediaFormat, LanguageCode languageCode, string? vocabularyName) { var response = await _amazonTranscribeService.StartTranscriptionJobAsync( new StartTranscriptionJobRequest() { TranscriptionJobName = jobName, Media = new Media() { MediaFileUri = mediaFileUri }, MediaFormat = mediaFormat, LanguageCode = languageCode, Settings = vocabularyName != null ? new Settings() { VocabularyName = vocabularyName } : null }); return response.TranscriptionJob; }
-
有关 API 的详细信息,请参阅 AWS SDK for .NET API 参考StartTranscriptionJob中的。
-