StartMedicalTranscriptionJob 搭配 AWS SDK或 使用 CLI - Amazon Transcribe

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

StartMedicalTranscriptionJob 搭配 AWS SDK或 使用 CLI

下列程式碼範例示範如何使用 StartMedicalTranscriptionJob

.NET
AWS SDK for .NET
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/// <summary> /// Start a medical 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 medical 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="outputBucketName">Location for the output, typically an Amazon S3 location.</param> /// <param name="transcriptionType">Conversation or dictation transcription type.</param> /// <returns>A MedicalTransactionJob instance with information on the new job.</returns> public async Task<MedicalTranscriptionJob> StartMedicalTranscriptionJob( string jobName, string mediaFileUri, MediaFormat mediaFormat, string outputBucketName, Amazon.TranscribeService.Type transcriptionType) { var response = await _amazonTranscribeService.StartMedicalTranscriptionJobAsync( new StartMedicalTranscriptionJobRequest() { MedicalTranscriptionJobName = jobName, Media = new Media() { MediaFileUri = mediaFileUri }, MediaFormat = mediaFormat, LanguageCode = LanguageCode .EnUS, // The value must be en-US for medical transcriptions. OutputBucketName = outputBucketName, OutputKey = jobName, // The value is a key used to fetch the output of the transcription. Specialty = Specialty.PRIMARYCARE, // The value PRIMARYCARE must be set. Type = transcriptionType }); return response.MedicalTranscriptionJob; }
CLI
AWS CLI

範例 1:轉錄儲存為音訊檔案的醫學聽寫

以下 start-medical-transcription-job 範例會轉錄音訊檔案。您可在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-medical-transcription-job \ --cli-input-json file://myfile.json

myfile.json 的內容:

{ "MedicalTranscriptionJobName": "simple-dictation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "DICTATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "simple-dictation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-20T00:35:22.256000+00:00", "CreationTime": "2020-09-20T00:35:22.218000+00:00", "Specialty": "PRIMARYCARE", "Type": "DICTATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的批次轉錄概觀

範例 2:轉錄儲存為音訊檔案的臨床醫師與病患對話

以下 start-medical-transcription-job 範例會轉錄包含臨床醫師與病患對話的音訊檔案。您可以在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-medical-transcription-job \ --cli-input-json file://mysecondfile.json

mysecondfile.json 的內容:

{ "MedicalTranscriptionJobName": "simple-dictation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "CONVERSATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "simple-conversation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-20T23:19:49.965000+00:00", "CreationTime": "2020-09-20T23:19:49.941000+00:00", "Specialty": "PRIMARYCARE", "Type": "CONVERSATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的批次轉錄概觀

範例 3:轉錄臨床醫師與病患對話的多聲道音訊檔案

以下 start-medical-transcription-job 範例會轉錄音訊檔案中每個聲道的音訊,並將每個聲道的個別轉錄合併成單一轉錄輸出。您可在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-medical-transcription-job \ --cli-input-json file://mythirdfile.json

mythirdfile.json 的內容:

{ "MedicalTranscriptionJobName": "multichannel-conversation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "CONVERSATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "Settings":{ "ChannelIdentification": true } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "multichannel-conversation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-20T23:46:44.081000+00:00", "CreationTime": "2020-09-20T23:46:44.053000+00:00", "Settings": { "ChannelIdentification": true }, "Specialty": "PRIMARYCARE", "Type": "CONVERSATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的聲道識別

範例 4:轉錄臨床醫生與病患對話的音訊檔案,並識別轉錄輸出中的發言者

以下 start-medical-transcription-job 範例會轉錄音訊檔案,並標記轉錄輸出中每一位發言者的語音。您可在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-medical-transcription-job \ --cli-input-json file://myfourthfile.json

myfourthfile.json 的內容:

{ "MedicalTranscriptionJobName": "speaker-id-conversation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "CONVERSATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "Settings":{ "ShowSpeakerLabels": true, "MaxSpeakerLabels": 2 } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "speaker-id-conversation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-21T18:43:37.265000+00:00", "CreationTime": "2020-09-21T18:43:37.157000+00:00", "Settings": { "ShowSpeakerLabels": true, "MaxSpeakerLabels": 2 }, "Specialty": "PRIMARYCARE", "Type": "CONVERSATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的識別發言者

範例 5:轉錄儲存為音訊檔案且最多有兩個轉錄替代選項的醫學對話

以下 start-medical-transcription-job 範例會從單一音訊檔案建立最多兩個替代轉錄。每個轉錄都有相關聯的可信度等級。根據預設,Amazon Transcribe 會傳回最高可信度等級的轉錄。您可以指定 Amazon Transcribe 傳回可信度較低的其他轉錄。您可在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-medical-transcription-job \ --cli-input-json file://myfifthfile.json

myfifthfile.json 的內容:

{ "MedicalTranscriptionJobName": "alternatives-conversation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "CONVERSATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "Settings":{ "ShowAlternatives": true, "MaxAlternatives": 2 } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "alternatives-conversation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-21T19:09:18.199000+00:00", "CreationTime": "2020-09-21T19:09:18.171000+00:00", "Settings": { "ShowAlternatives": true, "MaxAlternatives": 2 }, "Specialty": "PRIMARYCARE", "Type": "CONVERSATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的替代轉錄

範例 6:轉錄最多有兩個替代轉錄的醫學聽寫的音訊檔案

以下 start-medical-transcription-job 範例會轉錄音訊檔案,並使用詞彙篩選器來為任何不希望出現的字詞加上遮罩。您可以在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-medical-transcription-job \ --cli-input-json file://mysixthfile.json

mysixthfile.json 的內容:

{ "MedicalTranscriptionJobName": "alternatives-conversation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "DICTATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "Settings":{ "ShowAlternatives": true, "MaxAlternatives": 2 } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "alternatives-dictation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-21T21:01:14.592000+00:00", "CreationTime": "2020-09-21T21:01:14.569000+00:00", "Settings": { "ShowAlternatives": true, "MaxAlternatives": 2 }, "Specialty": "PRIMARYCARE", "Type": "DICTATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的替代轉錄

範例 7:使用自訂詞彙以更準確的方式轉錄醫學聽寫的音訊檔案

以下 start-medical-transcription-job 範例會轉錄音訊檔案,並使用您先前建立的醫學自訂詞彙來提高轉錄準確度。您可在 OutputBucketName 參數中指定轉錄輸出的位置。

aws transcribe start-transcription-job \ --cli-input-json file://myseventhfile.json

mysixthfile.json 的內容:

{ "MedicalTranscriptionJobName": "vocabulary-dictation-medical-transcription-job", "LanguageCode": "language-code", "Specialty": "PRIMARYCARE", "Type": "DICTATION", "OutputBucketName":"DOC-EXAMPLE-BUCKET", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "Settings":{ "VocabularyName": "cli-medical-vocab-1" } }

輸出:

{ "MedicalTranscriptionJob": { "MedicalTranscriptionJobName": "vocabulary-dictation-medical-transcription-job", "TranscriptionJobStatus": "IN_PROGRESS", "LanguageCode": "language-code", "Media": { "MediaFileUri": "s3://DOC-EXAMPLE-BUCKET/your-audio-file.extension" }, "StartTime": "2020-09-21T21:17:27.045000+00:00", "CreationTime": "2020-09-21T21:17:27.016000+00:00", "Settings": { "VocabularyName": "cli-medical-vocab-1" }, "Specialty": "PRIMARYCARE", "Type": "DICTATION" } }

如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的醫學自訂詞彙

JavaScript
SDK for JavaScript (v3)
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

建立用戶端。

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

開始醫學轉錄作業。

// Import the required AWS SDK clients and commands for Node.js import { StartMedicalTranscriptionJobCommand } from "@aws-sdk/client-transcribe"; import { transcribeClient } from "./libs/transcribeClient.js"; // Set the parameters export const params = { MedicalTranscriptionJobName: "MEDICAL_JOB_NAME", // Required OutputBucketName: "OUTPUT_BUCKET_NAME", // Required Specialty: "PRIMARYCARE", // Required. Possible values are 'PRIMARYCARE' Type: "JOB_TYPE", // Required. Possible values are 'CONVERSATION' and 'DICTATION' LanguageCode: "LANGUAGE_CODE", // For example, 'en-US' MediaFormat: "SOURCE_FILE_FORMAT", // For example, 'wav' Media: { MediaFileUri: "SOURCE_FILE_LOCATION", // The S3 object location of the input media file. The URI must be in the same region // as the API endpoint that you are calling.For example, // "https://transcribe-demo.s3-REGION.amazonaws.com/hello_world.wav" }, }; export const run = async () => { try { const data = await transcribeClient.send( new StartMedicalTranscriptionJobCommand(params), ); console.log("Success - put", data); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱搭配 AWS SDK 使用此服務。本主題也包含入門的相關資訊,以及先前SDK版本的詳細資訊。