Skip to content

Commit 5f07e16

Browse files
AISDK-190 Update sdks to support notification_config and source_config (#83)
1 parent c98a68d commit 5f07e16

19 files changed

+473
-116
lines changed

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@ History
9494
------------------
9595
* Add topic extraction client
9696
* Add speaker_names to async client for human transcription
97+
98+
2.16.0
99+
------------------
100+
* Add source_config and notification_config job options to support customer provided urls with authentication headers
101+
* Deprecate media_url option, replace with source_config
102+
* Deprecate callback_url option, replace with notification_config

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ job = client.submit_job_url("https://example.com/file-to-transcribe.mp3")
5050
`job` will contain all the information normally found in a successful response from our
5151
[Submit Job](https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob) endpoint.
5252

53-
If you want to get fancy, both send job methods take `metadata`, `callback_url`,
54-
`skip_diarization`, `skip_punctuation`, `speaker_channels_count`, `custom_vocabularies`, `filter_profanity`, `remove_disfluencies`, `delete_after_seconds`, `language`, and `custom_vocabulary_id` as optional parameters, these are described in the request body of
55-
the [Submit Job](https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob) endpoint.
53+
If you want to get fancy, both submit job methods take `metadata`,`notification_config`,
54+
`skip_diarization`, `skip_punctuation`, `speaker_channels_count`,`custom_vocabularies`,
55+
`filter_profanity`, `remove_disfluencies`, `delete_after_seconds`,`language`,
56+
and `custom_vocabulary_id` as optional parameters.
57+
58+
The url submission option also supports authentication headers by using the `source_config` option.
59+
60+
All options are described in the request body of the
61+
[Submit Job](https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob) endpoint.
62+
63+
### Human Transcription
5664

5765
If you want transcription to be performed by a human, both methods allow you to submit human transcription jobs
5866
using `transcriber=human` with `verbatim`, `rush`, `segments_to_transcribe` and `test_mode` as optional parameters.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Copyright 2022 REV
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
"""
15+
16+
from rev_ai import apiclient
17+
from rev_ai.models.customer_url_data import CustomerUrlData
18+
19+
# String containing your access token
20+
access_token = "<your_access_token>"
21+
22+
# Create your api client
23+
client = apiclient.RevAiAPIClient(access_token)
24+
25+
# Create config objects containing the url and auth headers for each option
26+
# These options replace media_url and callback_url and should not be used alongside them
27+
source_url = "https://www.rev.ai/FTC_Sample_1.mp3"
28+
source_auth_headers = {"Authorization": "Bearer <token>"}
29+
callback_url = "https://www.example.com/callback"
30+
callback_auth_headers = {"Authorization": "Bearer <token>"}
31+
32+
# Submitting a job with the authentication header options
33+
job = client.submit_job_url(
34+
source_config=CustomerUrlData(url=source_url, auth_headers=source_auth_headers),
35+
notification_config=CustomerUrlData(url=callback_url, auth_headers=callback_auth_headers))
36+
37+
print("Submitted Job")

examples/async_example.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
# remove_disfluencies=False,
4646
# delete_after_seconds=None,
4747
# language=None,
48-
# custom_vocabulary_id=None)
48+
# custom_vocabulary_id=None,
49+
# notification_config=None)
4950

5051

5152
# Submitting a job with a link to the file you want transcribed
5253
# Change url to your url, custom_vocabularies is optional like above
5354
url = "https://www.rev.ai/FTC_Sample_1.mp3"
54-
job = client.submit_job_url(url,
55+
job = client.submit_job_url(media_url=url,
5556
metadata=None,
5657
callback_url=None,
5758
skip_diarization=False,
@@ -60,7 +61,9 @@
6061
remove_disfluencies=False,
6162
delete_after_seconds=None,
6263
language=None,
63-
custom_vocabulary_id=None)
64+
custom_vocabulary_id=None,
65+
source_config=None,
66+
notification_config=None)
6467

6568
print("Submitted Job")
6669

@@ -73,7 +76,7 @@
7376

7477
# Checks if the job has been transcribed. Please note that this is not the recommended way
7578
# of getting job status in a real application. For recommended methods of getting job status
76-
# please see our documentation on callback_urls here:
79+
# please see our documentation on setting a callback url here:
7780
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
7881
if status == "IN_PROGRESS":
7982
time.sleep(5)

examples/language_identification_example.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@
1818

1919

2020
# String containing your access token
21+
from rev_ai.models.customer_url_data import CustomerUrlData
22+
2123
access_token = "<your_access_token>"
2224

2325
# Create your api client
2426
client = language_identification_client.LanguageIdentificationClient(access_token)
2527

2628
# Submitting a job with a link to the file you want to identify the language of
27-
# Change url to your url
28-
url = "https://www.rev.ai/FTC_Sample_1.mp3"
29-
job = client.submit_job_url(url,
29+
# Change the url specified in source_config to the url of the media to submit
30+
source_config = CustomerUrlData(url="https://www.rev.ai/FTC_Sample_1.mp3")
31+
job = client.submit_job_url(media_url=None,
3032
metadata=None,
3133
callback_url=None,
32-
delete_after_seconds=None)
34+
delete_after_seconds=None,
35+
source_config=source_config,
36+
notification_config=None)
3337

3438
print("Submitted Job")
3539

examples/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
rev-ai==2.15.0
1+
rev-ai==2.16.0
22
pyaudio==0.2.11
33
six==1.12.0

examples/topic_extraction_example.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
text = "<input_text>"
2828
job = client.submit_job_from_text(text,
2929
metadata=None,
30-
callback_url=None,
3130
delete_after_seconds=None,
32-
language=None)
31+
language=None,
32+
notification_config=None)
3333

3434
# If you'd like to submit the transcript of an existing transcription job you can do so by
3535
# uncommenting the lines below
@@ -40,7 +40,6 @@
4040
# transcript_json = transcript
4141
# job = client.submit_job_from_transcript(transcript_json,
4242
# metadata=None,
43-
# callback_url=None,
4443
# delete_after_seconds=None,
4544
# language=None)
4645

@@ -55,7 +54,7 @@
5554

5655
# Checks if the job has been completed. Please note that this is not the recommended way
5756
# of getting job status in a real application. For recommended methods of getting job status
58-
# please see our documentation on callback_urls here:
57+
# please see our documentation on setting a callback url here:
5958
# https://docs.rev.ai/resources/tutorials/get-started-api-webhooks/
6059
if status == "IN_PROGRESS":
6160
time.sleep(2)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.15.0
2+
current_version = 2.16.0
33
commit = True
44
tag = True
55

src/rev_ai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""Top-level package for rev_ai"""
33

4-
__version__ = '2.15.1'
4+
__version__ = '2.16.0'
55

66
from .models import Job, JobStatus, Account, Transcript, Monologue, Element, MediaConfig, \
77
CaptionType, CustomVocabulary, TopicExtractionJob, TopicExtractionResult, Topic, Informant, \

src/rev_ai/apiclient.py

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, access_token):
4444

4545
def submit_job_url(
4646
self,
47-
media_url,
47+
media_url=None,
4848
metadata=None,
4949
callback_url=None,
5050
skip_diarization=False,
@@ -61,18 +61,20 @@ def submit_job_url(
6161
rush=None,
6262
test_mode=None,
6363
segments_to_transcribe=None,
64-
speaker_names=None):
64+
speaker_names=None,
65+
source_config=None,
66+
notification_config=None):
6567
"""Submit media given a URL for transcription.
66-
The audio data is downloaded from the URL.
67-
68+
The audio data is downloaded from the URL
6869
:param media_url: web location of the media file
70+
.. deprecated:: 2.16.0
71+
Use source_config instead
6972
:param metadata: info to associate with the transcription job
70-
:param callback_url: callback url to invoke on job completion as
71-
a webhook
72-
:param skip_diarization: should Rev AI skip diaization when
73-
transcribing this file
74-
:param skip_punctuation: should Rev AI skip punctuation when
75-
transcribing this file
73+
:param callback_url: callback url to invoke on job completion as a webhook
74+
.. deprecated:: 2.16.0
75+
Use notification_config instead
76+
:param skip_diarization: should Rev AI skip diarization when transcribing this file
77+
:param skip_punctuation: should Rev AI skip punctuation when transcribing this file
7678
:param speaker_channels_count: the number of speaker channels in the
7779
audio. If provided the given audio will have each channel
7880
transcribed separately and each channel will be treated as a single
@@ -102,19 +104,23 @@ def submit_job_url(
102104
Sections of transcript needed to be transcribed.
103105
:param speaker_names: Only available with "human" transcriber.
104106
Human readable names of speakers in the file.
107+
:param source_config: CustomerUrlData object containing url of the source media and
108+
optional authentication headers to use when accessing the source url
109+
:param notification_config: CustomerUrlData object containing the callback url to
110+
invoke on job completion as a webhook and optional authentication headers to use when
111+
calling the callback url
105112
:returns: raw response data
106113
:raises: HTTPError
107114
"""
108-
if not media_url:
109-
raise ValueError('media_url must be provided')
110-
payload = self._create_job_options_payload(media_url, metadata,
111-
callback_url, skip_diarization,
112-
skip_punctuation, speaker_channels_count,
115+
payload = self._create_job_options_payload(media_url, metadata, callback_url,
116+
skip_diarization, skip_punctuation,
117+
speaker_channels_count,
113118
custom_vocabularies, filter_profanity,
114119
remove_disfluencies, delete_after_seconds,
115120
language, custom_vocabulary_id, transcriber,
116121
verbatim, rush, test_mode,
117-
segments_to_transcribe, speaker_names)
122+
segments_to_transcribe, speaker_names,
123+
source_config, notification_config)
118124

119125
response = self._make_http_request(
120126
"POST",
@@ -143,18 +149,18 @@ def submit_job_local_file(
143149
rush=None,
144150
test_mode=None,
145151
segments_to_transcribe=None,
146-
speaker_names=None):
152+
speaker_names=None,
153+
notification_config=None):
147154
"""Submit a local file for transcription.
148155
Note that the content type is inferred if not provided.
149156
150157
:param filename: path to a local file on disk
151158
:param metadata: info to associate with the transcription job
152-
:param callback_url: callback url to invoke on job completion as a
153-
webhook
154-
:param skip_diarization: should Rev AI skip diaization when
155-
transcribing this file
156-
:param skip_punctuation: should Rev AI skip punctuation when
157-
transcribing this file
159+
:param callback_url: callback url to invoke on job completion as a webhook
160+
.. deprecated:: 2.16.0
161+
Use notification_config instead
162+
:param skip_diarization: should Rev AI skip diarization when transcribing this file
163+
:param skip_punctuation: should Rev AI skip punctuation when transcribing this file
158164
:param speaker_channels_count: the number of speaker channels in the
159165
audio. If provided the given audio will have each channel
160166
transcribed separately and each channel will be treated as a single
@@ -184,19 +190,24 @@ def submit_job_local_file(
184190
Sections of transcript needed to be transcribed.
185191
:param speaker_names: Only available with "human" transcriber.
186192
Human readable names of speakers in the file.
193+
:param notification_config: CustomerUrlData object containing the callback url to
194+
invoke on job completion as a webhook and optional authentication headers to use when
195+
calling the callback url
187196
:returns: raw response data
188-
:raises: HTTPError
197+
:raises: HTTPError, ValueError
189198
"""
190199
if not filename:
191200
raise ValueError('filename must be provided')
192201

193-
payload = self._create_job_options_payload(None, metadata, callback_url, skip_diarization,
194-
skip_punctuation, speaker_channels_count,
202+
payload = self._create_job_options_payload(None, metadata, callback_url,
203+
skip_diarization, skip_punctuation,
204+
speaker_channels_count,
195205
custom_vocabularies, filter_profanity,
196206
remove_disfluencies, delete_after_seconds,
197207
language, custom_vocabulary_id, transcriber,
198208
verbatim, rush, test_mode,
199-
segments_to_transcribe, speaker_names)
209+
segments_to_transcribe, speaker_names, None,
210+
notification_config)
200211

201212
with open(filename, 'rb') as f:
202213
files = {
@@ -426,7 +437,8 @@ def get_account(self):
426437
return Account.from_json(response.json())
427438

428439
def _create_job_options_payload(
429-
self, media_url,
440+
self,
441+
media_url=None,
430442
metadata=None,
431443
callback_url=None,
432444
skip_diarization=None,
@@ -443,7 +455,9 @@ def _create_job_options_payload(
443455
rush=None,
444456
test_mode=None,
445457
segments_to_transcribe=None,
446-
speaker_names=None):
458+
speaker_names=None,
459+
source_config=None,
460+
notification_config=None):
447461
payload = {}
448462
if media_url:
449463
payload['media_url'] = media_url
@@ -456,8 +470,7 @@ def _create_job_options_payload(
456470
if callback_url:
457471
payload['callback_url'] = callback_url
458472
if custom_vocabularies:
459-
payload['custom_vocabularies'] =\
460-
utils._process_vocabularies(custom_vocabularies)
473+
payload['custom_vocabularies'] = utils._process_vocabularies(custom_vocabularies)
461474
if speaker_channels_count:
462475
payload['speaker_channels_count'] = speaker_channels_count
463476
if filter_profanity:
@@ -483,6 +496,10 @@ def _create_job_options_payload(
483496
if speaker_names:
484497
payload['speaker_names'] =\
485498
utils._process_speaker_names(speaker_names)
499+
if source_config:
500+
payload['source_config'] = source_config.to_dict()
501+
if notification_config:
502+
payload['notification_config'] = notification_config.to_dict()
486503
return payload
487504

488505
def _create_captions_query(self, speaker_channel):

0 commit comments

Comments
 (0)