Get Started

This short tutorial will teach you the basics of using the Sentiment Analysis API. It demonstrates how to analyze the sentiments of a transcript.

Assumptions

This tutorial assumes that

attention

If you have an audio file, you can generate a JSON transcript from it.

Step 1: Get your access token

The first step is to generate an access token, which will enable access to the Rev AI APIs. Follow these steps:

  1. Log in to Rev AI.
  2. Navigate to the Access Token page .
  3. Click the Generate New Access Token link. Confirm the operation in the pop-up dialog box.

Creating an access token

The new access token will be generated and displayed on the screen.

warning

Save your access tokens somewhere safe; you will only be able to see them once. You are allowed a maximum of 2 access tokens at a time.

Step 2: Submit the transcript for sentiment analysis

Assuming that your JSON transcript is in a file, submit the transcript to the Sentiment Analysis API using the command below. Replace the <REVAI_ACCESS_TOKEN> placeholder with the access token obtained in Step 1 and the <FILEPATH> placeholder with the path to the transcript file.

Copy
Copied
curl -X POST "https://api.rev.ai/sentiment_analysis/v1/jobs" \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>" \
     -H "Content-Type: application/json"  \
     -d '{"json":'"$(< <FILEPATH>)"',"metadata":"This is a test"}'

You'll receive a response like this:

Copy
Copied
{
  "id":"XaFhKguSg912",
  "created_on":"2022-02-02T14:16:25.892Z",
  "metadata":"This is a test",
  "status":"in_progress",
  "type":"sentiment_analysis"
}

The id (in this case XaFhKguSg912) will allow you to retrieve the sentiment analysis report.

Step 3: Retrieve the sentiment analysis report

You now need to wait for the job to complete. Wait for approximately 30 seconds and then check the status of your job by querying the API as shown below:

Copy
Copied
curl -X GET https://api.rev.ai/sentiment_analysis/v1/jobs/<ID> \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>"
warning

Polling the API periodically for job status is NOT recommended in a production server. Rather, use webhooks to asynchronously receive notifications once the sentiment analysis job completes.

Once the sentiment analysis job's status changes to completed, you can retrieve the results in JSON format by running the command below. As before, replace the <REVAI_ACCESS_TOKEN> placeholder with the access token obtained in Step 1. You must also replace the <ID> placeholder with the id obtained in Step 2.

Copy
Copied
curl -X GET "https://api.rev.ai/sentiment_analysis/v1/jobs/<ID>/result" \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>" \
     -H "Accept: application/vnd.rev.sentiment.v1.0+json"

Here is an example of the output:

Copy
Copied
{
  "messages": [
    {
      "content": "Hi, my name's Jack Ratzinger.",
      "score": 0,
      "sentiment": "neutral",
      "ts": 0.27,
      "end_ts": 1.5
    },
    {
      "content": "And I'm going to be talking about how to recruit a co-founder and a team for your startup.",
      "score": 0,
      "sentiment": "neutral",
      "ts": 1.53,
      "end_ts": 5.85
    },
    {
      "content": "First, give a quick overview of what we're going to talk about.",
      "score": -0.601,
      "sentiment": "negative",
      "ts": 6.72,
      "end_ts": 8.79
    },
    {
      "content": "We're going to start out by talking about the sorts of folks you might be looking for for your startup.",
      "score": 0.2,
      "sentiment": "neutral",
      "ts": 9.09,
      "end_ts": 13.14
    },
    {
      ...
    }
  ]
}

Next steps

You should now have a basic idea of how to use the Sentiment Analysis API. To learn more, read the API documentation for complete details on the different resources and operations available in this API. You can also read about our other APIs and find code samples and SDK documentation that will help you connect your application with the API.