Rev.ai Node SDK
See the API docs for more information about the API.
Examples can be found in the
To install the package, run:
npm install revai-node-sdk
We support Node 8, 10, and 12.
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:
;// Initialize your client with your revai access tokenvar accessToken = "Your Access Token";var client = accessToken;
var accountInfo = await client;
Submitting a job
Once you've set up your client with your Access Token sending a file is easy!
// you can submit a local filevar job = await client;// or submit via a public urlvar job = await client;// or from audio data, the filename is optionalconst stream = fs;var job = await client;
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
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
var jobDetails = await client;
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;// limit amount of retrieved jobsvar jobs = await client;// get jobs starting after a certain job idvar jobs = await client;
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
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 textvar transcriptText = await client;// or as an objectvar transcriptObject = await client;
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;var transcriptStream = await client;
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;// with speaker channelsconst channelId = 1;var captionsStream = await client;
In order to stream audio, you will need to setup a streaming client and a media configuration for the audio you will be sending.
;var audioConfig = // Initialize audio configuration for the streaming clientvar streamingClient = "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.
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 = 'my metadata' 'myCustomVocabularyID';var stream = streamingClientstartsessionConfig;
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
;// Initialize your client with your revai access tokenvar accessToken = "Your Access Token";var client = accessToken;// Construct Custom Vocabularies object and submit it through the clientvar customVocabularies = phrases: "Noam Chomsky" "Robert Berwick" "Patrick Winston";var customVocabularySubmission = await client;// Get information regarding the Custom Vocabulary submission and its progressvar customVocabularyInformation = await client