Amazon Transcribe examples - AWS SDK for JavaScript

Help us improve the AWS SDK for JavaScript version 3 (V3) documentation by providing feedback using the Feedback link, or create an issue or pull request on GitHub.

The AWS SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the AWS SDK for JavaScript version 3 (V3).

Amazon Transcribe examples

In this example, a series of Node.js modules are used to create,list, and delete transcription jobs using the following methods of the TranscribeService client class:

For more information about Amazon Transcribe users, see the Amazon Transcribe developer guide.

Prerequisite tasks

To set up and run this example, you must first complete these tasks:

  • Set up the project environment to run these Node TypeScript examples, and install the required AWS SDK for JavaScript and third-party modules. Follow the instructions on GitHub.

  • Create a shared configurations file with your user credentials. For more information about providing a credentials JSON file, see Loading credentials in Node.js from the shared credentials file.

Important

These examples demonstrate how to import/export client service objects and command using ECMAScript6 (ES6).

Starting an Amazon Transcribe job

This example demonstrates how to start a Amazon Transcribe transcription job using the AWS SDK for JavaScript. For more information, see StartTranscriptionJobCommand.

Create a libs directory, and create a Node.js module with the file name transcribeClient.js. Copy and paste the code below into it, which creates the Amazon Transcribe client object. Replace REGION with your AWS Region.

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

This example code can be found here on GitHub.

Create a Node.js module with the file name transcribe-create-job.js. Make sure to configure the SDK as previously shown, including installing the required clients and packages. Create a parameters object, specifying the required parameters. Start the job using the StartMedicalTranscriptionJobCommand command.

Note

Replace MEDICAL_JOB_NAME with a name for the transcription job. For OUTPUT_BUCKET_NAME specify the Amazon S3 bucket where the output is saved. For JOB_TYPE specify types of job. For SOURCE_LOCATION specify the location of the source file. For SOURCE_FILE_LOCATION specify the location of the input media file.

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

To run the example, enter the following at the command prompt.

node transcribe-create-job.js

This sample code can be found here on GitHub.

List Amazon Transcribe jobs

This example shows how list the Amazon Transcribe transcription jobs using the AWS SDK for JavaScript. For more information about what other setting you can modify, see ListTranscriptionJobCommand.

Create a libs directory, and create a Node.js module with the file name transcribeClient.js. Copy and paste the code below into it, which creates the Amazon Transcribe client object. Replace REGION with your AWS Region.

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

This example code can be found here on GitHub.

Create a Node.js module with the file name transcribe-list-jobs.js. Make sure to configure the SDK as previously shown, including installing the required clients and packages. Create a parameters object with the required parameters.

Note

Replace KEY_WORD with a keyword that the returned jobs name must contain.

// 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 const params = { JobNameContains: "KEYWORD", // Not required. Returns only transcription // job names containing this string }; 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();

To run the example, enter the following at the command prompt.

node transcribe-list-jobs.js

This sample code can be found here on GitHub.

Deleting a Amazon Transcribe job

This example shows how to delete an Amazon Transcribe transcription job using the AWS SDK for JavaScript. For more information about optional, see DeleteTranscriptionJobCommand.

Create a libs directory, and create a Node.js module with the file name transcribeClient.js. Copy and paste the code below into it, which creates the Amazon Transcribe client object. Replace REGION with your AWS Region.

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

This example code can be found here on GitHub.

Create a Node.js module with the file name transcribe-delete-job.js. Make sure to configure the SDK as previously shown, including installing the required clients and packages. Specify the AWS Region, and the name of the job you want to delete.

Note

Replace JOB_NAME with the name of the job to delete.

// 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 const params = { TranscriptionJobName: "JOB_NAME", // Required. For example, 'transciption_demo' }; 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();

To run the example, enter the following at the command prompt.

node transcribe-delete-job.js

This sample code can be found here on GitHub.