Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

revai-node-sdk

2.2.2 • Public • Published

Rev.ai Node SDK

Build Status

Documentation

See the API docs for more information about the API.

Examples

Examples can be found in the examples/ directory

Installation

To install the package, run:

npm install revai-node-sdk

Support

We support Node 8, 10, and 12.

Usage

All you need to get started is your Access Token, which can be generated on your Settings Page. Create a client with the given Access Token:

import { RevAiApiClient } from 'revai-node-sdk';
 
// Initialize your client with your revai access token
var accessToken = "Your Access Token";
var client = new RevAiApiClient(accessToken);

Checking balance

var accountInfo = await client.getAccount();

Submitting a job

Once you've set up your client with your Access Token sending a file is easy!

// you can submit a local file
var job = await client.submitJobLocalFile("./path/to/file.mp4");
 
// or submit via a public url
var job = await client.submitJobUrl("https://www.rev.ai/FTC_Sample_1.mp3");
 
// or from audio data, the filename is optional
const stream = fs.createReadStream("./path/to/file.mp3");
var job = await client.submitJobAudioData(stream, "file.mp3");

job will contain all the information normally found in a successful response from our Submit Job endpoint.

If you want to get fancy, both send job methods can take a RevAiJobOptions object which contains fields for metadata, callback_url, skip_diarization,skip_punctuation, speaker_channels_count and custom_vocabularies as optional parameters. These are also described in the request body of the Submit Job endpoint.

Checking your job's status

You can check the status of your transcription job using its id

var jobDetails = await client.getJobDetails(job.id);

jobDetails will contain all information normally found in a successful response from our Get Job endpoint

Checking multiple files

You can retrieve a list of transcription jobs with optional parameters

var jobs = await client.getListOfJobs();
 
// limit amount of retrieved jobs
var jobs = await client.getListOfJobs(3);
 
// get jobs starting after a certain job id
var jobs = await client.getListOfJobs(undefined, 'Umx5c6F7pH7r');

jobs will contain a list of job details having all information normally found in a successful response from our Get List of Jobs endpoint

Deleting a job

You can delete a transcription job using its id

await client.deleteJob(job.id);

All data related to the job, such as input media and transcript, will be permanently deleted. A job can only by deleted once it's completed (either with success or failure).

Getting your transcript

Once your file is transcribed, you can get your transcript in a few different forms:

// as plain text
var transcriptText = await client.getTranscriptText(job.id);
 
// or as an object
var transcriptObject = await client.getTranscriptObject(job.id);

The text output is a string containing just the text of your transcript. The object form of the transcript contains all the information outlined in the response of the Get Transcript endpoint when using the json response schema.

Any of these outputs can we retrieved as a stream for easy file writing:

var textStream = await client.getTranscriptTextStream(job.id);
var transcriptStream = await client.getTranscriptObjectStream(job.id);

Getting captions output

Another way to retrieve your file is captions output. We support both .srt and .vtt outputs. See below for an example showing how you can get captions as a readable stream. If your job was submitted with multiple speaker channels you are required to provide the id of the channel you would like captioned.

var captionsStream = await client.getCaptions(job.id, CaptionType.SRT);
 
// with speaker channels
const channelId = 1;
var captionsStream = await client.getCaptions(job.id, CaptionType.VTT, channelId);

Streaming Audio

In order to stream audio, you will need to setup a streaming client and a media configuration for the audio you will be sending.

import { RevAiStreamingClient } from 'revai-node-sdk';
 
var audioConfig = new AudioConfig() // Initialize audio configuration for the streaming client
var streamingClient = new RevAiStreamingClient("ACCESS TOKEN", audioConfig);

You can set up event responses for your client's streaming sessions. This allows you to handle events such as the connection closing, failing, or successfully connecting! Look at the examples for more details.

streamingClient.on('close', (code, reason) => {
    console.log(`Connection closed, ${code}${reason}`);
});
 
streamingClient.on('connect', connectionMessage => {
    console.log(`Connected with job id: ${connectionMessage.id}`);
})

Now you will be able to start the streaming session by simply calling the streamingClient.start() method! You can supply an optional SessionConfig object to the function as well in order to provide additional information for that session, such as metadata, or a Custom Vocabulary's ID to be used with your streaming session.

const sessionConfig = new SessionConfig('my metadata', 'myCustomVocabularyID');
 
var stream = streamingClient.start(sessionConfig);

You can then stream data to this stream from a local file or other sources of your choosing and the session will end when the data stream to the stream session ends or when you would like to end it, by calling streamingClient.end(). For more details, take a look at our examples.

Submitting Custom Vocabularies

You can now submit any custom vocabularies independently through the new CustomVocabularies client! The main benefit is that users of the SDK can now submit their custom vocabularies for preprocessing and then include these processed custom vocabularies in their streaming jobs.

Below you can see an example of how to create and submit as well as check on the status and other associated information of your submittied custom vocabulary!

For more information check out our examples

import { RevAiCustomVocabulariesClient } from 'revai-node-sdk';
 
// Initialize your client with your revai access token
var accessToken = "Your Access Token";
var client = new RevAiCustomVocabulariesClient(accessToken);
 
// Construct Custom Vocabularies object and submit it through the client
var customVocabularies = [{phrases: ["Noam Chomsky", "Robert Berwick", "Patrick Winston"]}];
var customVocabularySubmission = await client.submitCustomVocabularies(customVocabularies);
 
// Get information regarding the Custom Vocabulary submission and its progress
var customVocabularyInformation = await client.getCustomVocabularyInformation(customVocabularySubmission.id)

Install

npm i revai-node-sdk

DownloadsWeekly Downloads

1,463

Version

2.2.2

License

MIT

Unpacked Size

69.3 kB

Total Files

65

Last publish

Collaborators

  • avatar