Skip to content

Commit 020da79

Browse files
committed
add parameters
1 parent 172ffac commit 020da79

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

src/rev_ai/apiclient.py

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,95 +337,125 @@ def get_list_of_jobs(self, limit=None, starting_after=None):
337337

338338
return [Job.from_json(job) for job in response.json()]
339339

340-
def get_transcript_text(self, id_):
340+
def get_transcript_text(self, id_, group_channels_by=None, group_channels_threshold_ms=None):
341341
"""Get the transcript of a specific job as plain text.
342342
343343
:param id_: id of job to be requested
344+
:param group_channels_by: optional, group channels by speaker or time
345+
:param group_channels_threshold_ms: optional, group channels by time threshold in milliseconds
344346
:returns: transcript data as text
345347
:raises: HTTPError
346348
"""
347349
if not id_:
348350
raise ValueError('id_ must be provided')
351+
352+
url = self._build_transcript_url(self, id_,
353+
group_channels_by=group_channels_by,
354+
group_channels_threshold_ms=group_channels_threshold_ms)
349355

350356
response = self._make_http_request(
351357
"GET",
352-
urljoin(self.base_url, 'jobs/{}/transcript'.format(id_)),
358+
url,
353359
headers={'Accept': 'text/plain'}
354360
)
355361

356362
return response.text
357363

358-
def get_transcript_text_as_stream(self, id_):
364+
def get_transcript_text_as_stream(self, id_, group_channels_by=None, group_channels_threshold_ms=None):
359365
"""Get the transcript of a specific job as a plain text stream.
360366
361367
:param id_: id of job to be requested
368+
:param group_channels_by: optional, group channels by speaker or time
369+
:param group_channels_threshold_ms: optional, group channels by time threshold in milliseconds
362370
:returns: requests.models.Response HTTP response which can be used to stream
363371
the payload of the response
364372
:raises: HTTPError
365373
"""
366374
if not id_:
367375
raise ValueError('id_ must be provided')
368376

377+
url = self._build_transcript_url(self, id_,
378+
group_channels_by=group_channels_by,
379+
group_channels_threshold_ms=group_channels_threshold_ms)
380+
369381
response = self._make_http_request(
370382
"GET",
371-
urljoin(self.base_url, 'jobs/{}/transcript'.format(id_)),
383+
url,
372384
headers={'Accept': 'text/plain'},
373385
stream=True
374386
)
375387

376388
return response
377389

378-
def get_transcript_json(self, id_):
390+
def get_transcript_json(self, id_, group_channels_by=None, group_channels_threshold_ms=None):
379391
"""Get the transcript of a specific job as json.
380392
381393
:param id_: id of job to be requested
394+
:param group_channels_by: optional, group channels by speaker or time
395+
:param group_channels_threshold_ms: optional, group channels by time threshold in milliseconds
382396
:returns: transcript data as json
383397
:raises: HTTPError
384398
"""
385399
if not id_:
386400
raise ValueError('id_ must be provided')
387401

402+
url = self._build_transcript_url(self, id_,
403+
group_channels_by=group_channels_by,
404+
group_channels_threshold_ms=group_channels_threshold_ms)
405+
388406
response = self._make_http_request(
389407
"GET",
390-
urljoin(self.base_url, 'jobs/{}/transcript'.format(id_)),
408+
url,
391409
headers={'Accept': self.rev_json_content_type}
392410
)
393411

394412
return response.json()
395413

396-
def get_transcript_json_as_stream(self, id_):
414+
def get_transcript_json_as_stream(self, id_, group_channels_by=None, group_channels_threshold_ms=None):
397415
"""Get the transcript of a specific job as streamed json.
398416
399417
:param id_: id of job to be requested
418+
:param group_channels_by: optional, group channels by speaker or time
419+
:param group_channels_threshold_ms: optional, group channels by time threshold in milliseconds
400420
:returns: requests.models.Response HTTP response which can be used to stream
401421
the payload of the response
402422
:raises: HTTPError
403423
"""
404424
if not id_:
405425
raise ValueError('id_ must be provided')
406426

427+
url = self._build_transcript_url(self, id_,
428+
group_channels_by=group_channels_by,
429+
group_channels_threshold_ms=group_channels_threshold_ms)
430+
407431
response = self._make_http_request(
408432
"GET",
409-
urljoin(self.base_url, 'jobs/{}/transcript'.format(id_)),
433+
url,
410434
headers={'Accept': self.rev_json_content_type},
411435
stream=True
412436
)
413437

414438
return response
415439

416-
def get_transcript_object(self, id_):
440+
def get_transcript_object(self, id_, group_channels_by=None, group_channels_threshold_ms=None):
417441
"""Get the transcript of a specific job as a python object`.
418442
419443
:param id_: id of job to be requested
444+
:param group_channels_by: optional, group channels by speaker or time
445+
:param group_channels_threshold_ms: optional, group channels by time threshold in milliseconds
420446
:returns: transcript data as a python object
421447
:raises: HTTPError
422448
"""
423449
if not id_:
424450
raise ValueError('id_ must be provided')
425451

452+
url = self._build_transcript_url(self, id_,
453+
group_channels_by=group_channels_by,
454+
group_channels_threshold_ms=group_channels_threshold_ms)
455+
426456
response = self._make_http_request(
427457
"GET",
428-
urljoin(self.base_url, 'jobs/{}/transcript'.format(id_)),
458+
url,
429459
headers={'Accept': self.rev_json_content_type}
430460
)
431461

@@ -814,3 +844,20 @@ def _create_job_options_payload(
814844

815845
def _create_captions_query(self, speaker_channel):
816846
return '' if speaker_channel is None else '?speaker_channel={}'.format(speaker_channel)
847+
848+
def _build_transcript_url(self, id_, group_channels_by=None, group_channels_threshold_ms=None):
849+
"""Build the get transcript url.
850+
851+
:param id_: id of job to be requested
852+
:param group_channels_by: optional, group channels by speaker or time
853+
:param group_channels_threshold_ms: optional, group channels by time threshold in milliseconds
854+
:returns: url for getting the transcript
855+
"""
856+
params = []
857+
if group_channels_by is not None:
858+
params.append('group_channels_by={}'.format(group_channels_by))
859+
if group_channels_threshold_ms is not None:
860+
params.append('group_channels_threshold_ms={}'.format(group_channels_threshold_ms))
861+
862+
query = '?{}'.format('&'.join(params))
863+
return urljoin(self.base_url, 'jobs/{}/transcript{}'.format(id_, query))

0 commit comments

Comments
 (0)