Rev.ai makes speech applications easy to build!
Rev.ai Python SDK
See the API docs for more information about the API and more python examples.
You don't need this source code unless you want to modify the package. If you just want to use the package, just run:
pip install --upgrade rev_ai
Install from source with:
python setup.py install
- Python 2.7+ or Python 3.4+
All you need to get started is your Access Token, which can be generated on your AccessToken Settings Page. Create a client with the generated Access Token:
from rev_ai import apiclient # create your client client = apiclient.RevAiAPIClient("ACCESS TOKEN")
Sending a file
Once you've set up your client with your Access Token sending a file is easy!
# you can send a local file job = client.submit_job_local_file("FILE PATH") # or send a link to the file you want transcribed job = client.submit_job_url("https://example.com/file-to-transcribe.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 take
custom_vocabulary_id as optional parameters, these are described in the request body of
the Submit Job endpoint.
Checking your file's status
You can check the status of your transcription job using its
job_details = client.get_job_details(job.id)
job_details 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
jobs = client.get_list_of_jobs() # limit amount of retrieved jobs jobs = client.get_list_of_jobs(limits=3) # get jobs starting after a certain job id jobs = client.get_list_of_jobs(starting_after='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
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 text transcript_text = client.get_transcript_text(job.id) # as json transcript_json = client.get_transcript_json(job.id) # or as a python object transcript_object = client.get_transcript_object(job.id)
Both the json and object forms contain all the formation outlined in the response of the Get Transcript endpoint when using the json response schema. While the text output is a string containing just the text of your transcript
Getting captions output
You can also get captions output from the SDK. We offer both SRT and VTT caption formats.
If you submitted your job as speaker channel audio then you must also provide a
channel_id to be captioned:
captions = client.get_captions(job.id, content_type=CaptionType.SRT, channel_id=None)
Any output format can be retrieved as a stream. In these cases we return the raw http response to you. The output can be retrieved via
text_stream = client.get_transcript_text_as_stream(job.id) json_stream = client.get_transcript_json_as_stream(job.id) captions_stream = client.get_captions_as_stream(job.id)
In order to stream audio, you will need to setup a streaming client and a media configuration for the audio you will be sending.
from rev_ai.streamingclient import RevAiStreamingClient from rev_ai.models import MediaConfig #on_error(error) #on_close(code, reason) #on_connected(id) config = MediaConfig() streaming_client = RevAiStreamingClient("ACCESS TOKEN", config, on_error=ERRORFUNC, on_close=CLOSEFUNC, on_connected=CONNECTEDFUNC)
on_connected are optional parameters that are functions to be called when the websocket errors, closes, and connects respectively. The default
on_error raises the error,
on_close prints out the code and reason for closing, and
on_connected prints out the job ID.
If passing in custom functions, make sure you provide the right parameters. See the sample code for the parameters.
Once you have a streaming client setup with a
MediaConfig and access token, you can obtain a transcription generator of your audio. You can also use a custom vocabulary with your streaming job by supplying the optional
custom_vocabulary_id when starting a connection!
More optional parameters can be supplied when starting a connection, these are
delete_after_seconds. For a description of these optional parameters look at our streaming documentation.
response_generator = streaming_client.start(AUDIO_GENERATOR, custom_vocabulary_id="CUSTOM VOCAB ID")
response_generator is a generator object that yields the transcription results of the audio including partial and final transcriptions. The
start method creates a thread sending audio pieces from the
AUDIO_GENERATOR to our
If you want to end the connection early, you can!
Otherwise, the connection will end when the server obtains an "EOS" message.
Submitting custom vocabularies
In addition to passing custom vocabularies as parameters in the async API client, you can create and submit your custom vocabularies independently and directly to the custom vocabularies API, as well as check on their progress.
Primarily, the custom vocabularies client allows you to submit and preprocess vocabularies for use with the streaming client, in order to have streaming jobs with custom vocabularies!
In this example you see how to construct custom vocabulary objects, submit them to the API, and check on their progress and metadata!
from rev_ai import custom_vocabularies_client from rev_ai.models import CustomVocabulary # Create a client client = custom_vocabularies_client.RevAiCustomVocabulariesClient("ACCESS TOKEN") # Construct a CustomVocabulary object using your desired phrases custom_vocabulary = CustomVocabulary(["Patrick Henry Winston", "Robert C Berwick", "Noam Chomsky"]) # Submit the CustomVocabulary custom_vocabularies_job = client.submit_custom_vocabularies([custom_vocabulary]) # View the job's progress job_state = client.get_custom_vocabularies_information(custom_vocabularies_job['id']) # Get list of previously submitted custom vocabularies custom_vocabularies_jobs = client.get_list_of_custom_vocabularies() # Delete the CustomVocabulary client.delete_custom_vocabulary(custom_vocabularies_job['id'])
For more details, check out the custom vocabularies example in our examples.
For Rev.ai Python SDK Developers
Remember in your development to follow the PEP8 style guide. Your code editor likely has Python PEP8 linting packages which can assist you in your development.
Local testing instructions
Prequisites: virtualenv, tox To test locally use the following commands from the repo root virtualenv ./sdk-test . ./sdk-test/bin/activate tox This will locally run the test suite, and saves significant dev time over waiting for the CI tool to pick it up.
- Initial alpha release
- Revamped official release
- File upload bug fixes
- Better Documentation
- Fix pypi readme formatting
- Add get_list_of_jobs
- Add support for custom vocabularies
- Add examples
- Improve error handling
- Add streaming client
- Support skip_punctuation
- Support .vtt captions output
- Support speaker channel jobs
- Add metadata to streaming client
- Add custom vocabularies to streaming client
- Use v1 of the streaming api
- Add custom vocabulary to async example
- Add filter_profanity to async and streaming clients, examples, and documentation
- Add remove_disfluencies to async client
- Add language selection option for multi-lingual ASR jobs to async client
- Add custom_vocabulary_id to async client
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size rev_ai-2.12.0-py2.py3-none-any.whl (19.1 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View|
|Filename, size rev_ai-2.12.0.tar.gz (26.1 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for rev_ai-2.12.0-py2.py3-none-any.whl