Rev AI Python SDK

2.21.0 · active · verified Thu Apr 16

The Rev AI Python SDK provides convenient access to the Rev AI Speech-to-Text APIs, enabling developers to easily integrate asynchronous and streaming speech recognition capabilities into their Python applications. It handles audio transcription for both local files and remote URLs. The library is actively maintained and receives regular updates, with the current version being 2.21.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Rev AI client, submit a local audio file for transcription, poll for job completion, retrieve the transcript as text, and finally delete the job. Remember to replace the placeholder `AUDIO_FILE_PATH` and set your `REVAI_ACCESS_TOKEN` environment variable.

import os
import time
from rev_ai import apiclient

REVAI_ACCESS_TOKEN = os.environ.get('REVAI_ACCESS_TOKEN', 'YOUR_REVAI_ACCESS_TOKEN')
AUDIO_FILE_PATH = 'path/to/your/audio.mp3'  # Replace with your audio file path

if not REVAI_ACCESS_TOKEN or REVAI_ACCESS_TOKEN == 'YOUR_REVAI_ACCESS_TOKEN':
    print("Please set the REVAI_ACCESS_TOKEN environment variable or replace 'YOUR_REVAI_ACCESS_TOKEN' with your actual token.")
    exit(1)

if not os.path.exists(AUDIO_FILE_PATH):
    print(f"Audio file not found: {AUDIO_FILE_PATH}")
    print("Please replace 'path/to/your/audio.mp3' with a valid audio file path.")
    exit(1)

# Create your client
client = apiclient.RevAiAPIClient(REVAI_ACCESS_TOKEN)

print(f"Submitting job for: {AUDIO_FILE_PATH}")
# Submit a local file for transcription
job = client.submit_job_local_file(AUDIO_FILE_PATH)

job_id = job.id
print(f"Job submitted with ID: {job_id}")

# Polling for job completion (simple example, consider webhooks for production)
while True:
    job_details = client.get_job_details(job_id)
    if job_details.status == 'transcribed':
        print("Job transcribed successfully!")
        break
    elif job_details.status == 'failed':
        print(f"Job failed: {job_details.failure_detail}")
        exit(1)
    else:
        print(f"Job status: {job_details.status}... waiting")
        time.sleep(5) # Wait 5 seconds before checking again

# Retrieve transcript as text
transcript_text = client.get_transcript_text(job_id)
print("\n--- Transcript (Text) ---")
print(transcript_text[:500]) # Print first 500 characters
print("...")

# You can also retrieve as JSON or a Python object
# transcript_json = client.get_transcript_json(job_id)
# transcript_object = client.get_transcript_object(job_id)

# Delete the job (optional, but good practice for cost/data management)
client.delete_job(job_id)
print(f"Job {job_id} deleted.")

view raw JSON →