Get Started

This short tutorial will teach you the basics of using the Forced Alignment API. It demonstrates how to obtain precise word timings for the words in a speech-to-text transcript.

Assumptions

This tutorial assumes that you have a Rev AI account. If not, sign up for a free account.

Step 1: Get your access token

If you haven't already done so, obtain a Rev AI API 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 an audio file and transcript for forced alignment

Submit an audio file and transcript text file (i.e. a file containing only the words of a transcript) for forced alignment to Rev AI using the command below. Replace the <REVAI_ACCESS_TOKEN> placeholder with the access token obtained in Step 1, and replace the sample file URLs shown below with the URLs to your own audio and transcript files.

Copy
Copied
curl -X POST "https://api.rev.ai/alignment/v1/jobs" \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>" \
     -H "Content-Type: application/json" \
     -d '{"source_config": {"url": "https://www.rev.ai/FTC_Sample_1.mp3"}, "source_transcript_config": {"url": "https://your-bucket.s3.us-west-2.amazonaws.com/transcript.txt"}, "metadata":"This is a forced alignment test"}'

You'll receive a response like this:

Copy
Copied
{
  "id": "Umx5c6F7pH7r",
  "created_on": "2023-06-12T15:54:20.406Z",
  "metadata": "This is a forced alignment test",
  "status": "in_progress",
  "type": "alignment"
}

The id (in this case Umx5c6F7pH7r) will enable you to retrieve your forced alignment result.

Step 3: Retrieve the forced alignment results

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/alignment/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 forced alignment job completes.

Once the job's status changes to completed, you can retrieve the transcript with word timings 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/alignment/v1/jobs/<ID>/transcript" \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>" \
     -H "Accept: application/vnd.rev.transcript.v1.0+json"

Here is a truncated example of the output:

Copy
Copied
{
    "monologues":[
        {
            "speaker":0,
            "elements":[
                {
                    "type":"text","value":"hi","ts":0.24,"end_ts":0.48
                },
                {
                    "type":"text","value":"my","ts":0.54,"end_ts":0.66
                },
                {
                    "type":"text","value":"name's","ts":0.66,"end_ts":0.87
                }
            ]
        }
    ]
}

Next steps

You should now have a basic idea of how to use the Forced Alignment 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.