Amazon Transcribe 示例使用 SDK JavaScript V3 - Amazon SDK for JavaScript
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

帮助我们改进Amazon SDK for JavaScript版本 3 (V3) 文档,方法是使用反馈链接,或者在上创建议题或拉取请求GitHub.

这些区域有:Amazon SDK for JavaScriptV3 API 参考指南详细描述了Amazon SDK for JavaScript版本 3 (V3)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon Transcribe 示例使用 SDK JavaScript V3

以下代码示例向您展示如何通过使用Amazon SDK for JavaScript使用 Amazon Transcribe 使用 V3。

操作展示如何调用 Amazon Transcribe 函数的具体代码节选。

方案展示如何通过调用多个 Amazon Transcribe 函数来完成特定任务的代码示例。

每个示例都包含一个指向 GitHub 的链接,其中包含了有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例显示如何删除 Amazon Transcribe 医疗转录作业。

适用于的 SDK JavaScript V3

创建客户端。

const { TranscribeClient } = require("@aws-sdk/client-transcribe"); // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create anAmazon EC2 service client object. const transcribeClient = new TranscribeClient({ region: REGION }); export { transcribeClient };

删除医疗转录作业。

// Import the required AWS SDK clients and commands for Node.js import { DeleteMedicalTranscriptionJobCommand } from "@aws-sdk/client-transcribe"; import { transcribeClient } from "./libs/transcribeClient.js"; // Set the parameters export const params = { MedicalTranscriptionJobName: "MEDICAL_JOB_NAME", // For example, 'medical_transciption_demo' }; export const run = async () => { try { const data = await transcribeClient.send( new DeleteMedicalTranscriptionJobCommand(params) ); console.log("Success - deleted"); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

以下代码示例显示如何删除 Amazon Transcribe 转录作业。

适用于的 SDK JavaScript V3

创建客户端。

const { TranscribeClient } = require("@aws-sdk/client-transcribe"); // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create anAmazon EC2 service client object. const transcribeClient = new TranscribeClient({ region: REGION }); export { transcribeClient };

删除转录任务。

// Import the required AWS SDK clients and commands for Node.js import { DeleteTranscriptionJobCommand } from "@aws-sdk/client-transcribe"; import { transcribeClient } from "./libs/transcribeClient.js"; // Set the parameters export const params = { TranscriptionJobName: "JOB_NAME", // Required. For example, 'transciption_demo' }; export const run = async () => { try { const data = await transcribeClient.send( new DeleteTranscriptionJobCommand(params) ); console.log("Success - deleted"); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

以下代码示例显示如何列出 Amazon Transcribe 医疗转录作业。

适用于的 SDK JavaScript V3

创建客户端。

const { TranscribeClient } = require("@aws-sdk/client-transcribe"); // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create anAmazon EC2 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();

以下代码示例显示如何列出 Amazon Transcribe 转录作业。

适用于的 SDK JavaScript V3

创建客户端。

const { TranscribeClient } = require("@aws-sdk/client-transcribe"); // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create anAmazon EC2 service client object. const transcribeClient = new TranscribeClient({ region: REGION }); export { transcribeClient };

列出转录任务。

// Import the required AWS SDK clients and commands for Node.js import { ListTranscriptionJobsCommand } from "@aws-sdk/client-transcribe"; import { transcribeClient } from "./libs/transcribeClient.js"; // Set the parameters export const params = { JobNameContains: "KEYWORD", // Not required. Returns only transcription // job names containing this string }; export const run = async () => { try { const data = await transcribeClient.send( new ListTranscriptionJobsCommand(params) ); console.log("Success", data.TranscriptionJobSummaries); return data; // For unit tests. } catch (err) { console.log("Error", err); } }; run();

以下代码示例显示如何启动 Amazon Transcribe 医疗转录作业。

适用于的 SDK JavaScript V3

创建客户端。

const { TranscribeClient } = require("@aws-sdk/client-transcribe"); // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create anAmazon EC2 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();

以下代码示例显示如何启动 Amazon Transcribe 转录作业。

适用于的 SDK JavaScript V3

创建客户端。

const { TranscribeClient } = require("@aws-sdk/client-transcribe"); // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create anAmazon EC2 service client object. const transcribeClient = new TranscribeClient({ region: REGION }); export { transcribeClient };

启动转录任务。

// 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" }, }; 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();