From 11606590b66e88a1919d95d43e2859f972ad1cce Mon Sep 17 00:00:00 2001 From: Hristo Stoychev Date: Thu, 2 Nov 2023 15:28:35 +0200 Subject: [PATCH 1/2] Add support for diarization_type, speakers_count, remove_atmospherics --- src/rev_ai/apiclient.py | 13 +++++++++++++ src/rev_ai/models/asynchronous/job.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/rev_ai/apiclient.py b/src/rev_ai/apiclient.py index 9f0b3d99..51fa1df1 100644 --- a/src/rev_ai/apiclient.py +++ b/src/rev_ai/apiclient.py @@ -71,6 +71,7 @@ def submit_job_url( skip_postprocessing=False, remove_atmospherics=False, speakers_count=None, + diarization_type=None, summarization_config: SummarizationOptions = None, translation_config: TranslationOptions = None): """Submit media given a URL for transcription. @@ -124,6 +125,7 @@ def submit_job_url( :param speakers_count: Use to specify the total number of unique speakers in the audio. :param summarization_config: Use to request transcript summary. :param translation_config: Use to request transcript translation. + :param diarization_type: Use to specify diarization type. :returns: raw response data :raises: HTTPError """ @@ -137,6 +139,10 @@ def submit_job_url( segments_to_transcribe, speaker_names, source_config, notification_config, skip_postprocessing, + remove_atmospherics, + speakers_count, + diarization_type, + skip_postprocessing, summarization_config=summarization_config, translation_config=translation_config) @@ -172,6 +178,7 @@ def submit_job_local_file( skip_postprocessing=False, remove_atmospherics=False, speakers_count=None, + diarization_type=None, summarization_config: SummarizationOptions = None, translation_config: TranslationOptions = None): """Submit a local file for transcription. @@ -220,6 +227,7 @@ def submit_job_local_file( :param remove_atmospherics: Atmospherics such as , , etc. will not appear in the transcript. :param speakers_count: Use to specify the total number of unique speakers in the audio. + :param diarization_type: Use to specify diarization type. :param summarization_config: Use to request transcript summary. :param translation_config: Use to request transcript translation. :returns: raw response data @@ -237,6 +245,8 @@ def submit_job_local_file( verbatim, rush, test_mode, segments_to_transcribe, speaker_names, None, notification_config, skip_postprocessing, + remove_atmospherics, speakers_count, + diarization_type, summarization_config=summarization_config, translation_config=translation_config) @@ -714,6 +724,7 @@ def _create_job_options_payload( skip_postprocessing=False, remove_atmospherics=None, speakers_count=None, + diarization_type=None, summarization_config: SummarizationOptions = None, translation_config: TranslationOptions = None): payload = {} @@ -764,6 +775,8 @@ def _create_job_options_payload( payload['remove_atmospherics'] = remove_atmospherics if speakers_count: payload['speakers_count'] = speakers_count + if diarization_type: + payload['diarization_type'] = diarization_type if summarization_config: payload['summarization_config'] = summarization_config.to_dict() if translation_config: diff --git a/src/rev_ai/models/asynchronous/job.py b/src/rev_ai/models/asynchronous/job.py index e4c523ed..930ab270 100644 --- a/src/rev_ai/models/asynchronous/job.py +++ b/src/rev_ai/models/asynchronous/job.py @@ -30,6 +30,7 @@ def __init__( segments_to_transcribe=None, remove_atmospherics=None, speakers_count=None, + diarization_type=None, summarization: Summarization = None, translation: Translation = None): """ @@ -62,6 +63,7 @@ def __init__( :param remove_atmospherics: Atmospherics such as , , etc. will noT appear in the transcript. :param speakers_count: Use to specify the total number of unique speakers in the audio. + :param diarization_type: Use to specify diarization type. """ self.id = id_ self.created_on = created_on @@ -88,6 +90,7 @@ def __init__( self.segments_to_transcribe = segments_to_transcribe self.remove_atmospherics = remove_atmospherics self.speakers_count = speakers_count + self.diarization_type = diarization_type self.summarization = summarization self.translation = translation @@ -126,6 +129,7 @@ def from_json(cls, json): segments_to_transcribe=json.get('segments_to_transcribe'), remove_atmospherics=json.get('remove_atmospherics'), speakers_count=json.get('speakers_count'), + diarization_type=json.get('diarization_type'), summarization=Summarization.from_json(json.get('summarization')), translation=Translation.from_json(json.get('translation')) ) From 15085faceee1923f22ed07a2cc196dd3ed290aa9 Mon Sep 17 00:00:00 2001 From: Kirill Bykov Date: Mon, 17 Jun 2024 10:10:54 -0500 Subject: [PATCH 2/2] Bringing the PR up to date. --- examples/requirements.txt | 2 +- src/rev_ai/__init__.py | 2 +- src/rev_ai/apiclient.py | 75 +++++++++++++++++++++++++-------------- tests/test_job.py | 45 ++++++++++++++++++----- 4 files changed, 88 insertions(+), 36 deletions(-) diff --git a/examples/requirements.txt b/examples/requirements.txt index 3cd40cde..6cca85ae 100644 --- a/examples/requirements.txt +++ b/examples/requirements.txt @@ -1,3 +1,3 @@ -rev-ai==2.19.4 +rev-ai==2.19.5 pyaudio==0.2.11 six==1.12.0 \ No newline at end of file diff --git a/src/rev_ai/__init__.py b/src/rev_ai/__init__.py index 1bc5c7aa..34da121f 100644 --- a/src/rev_ai/__init__.py +++ b/src/rev_ai/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Top-level package for rev_ai""" -__version__ = '2.19.4' +__version__ = '2.19.5' from .models import Job, JobStatus, Account, Transcript, Monologue, Element, MediaConfig, \ CaptionType, CustomVocabulary, TopicExtractionJob, TopicExtractionResult, Topic, Informant, \ diff --git a/src/rev_ai/apiclient.py b/src/rev_ai/apiclient.py index 51fa1df1..34bd483a 100644 --- a/src/rev_ai/apiclient.py +++ b/src/rev_ai/apiclient.py @@ -123,26 +123,36 @@ def submit_job_url( :param remove_atmospherics: Atmospherics such as , , etc. will not appear in the transcript. :param speakers_count: Use to specify the total number of unique speakers in the audio. + :param diarization_type: Use to specify diarization type. :param summarization_config: Use to request transcript summary. :param translation_config: Use to request transcript translation. - :param diarization_type: Use to specify diarization type. :returns: raw response data :raises: HTTPError """ - payload = self._create_job_options_payload(media_url, metadata, callback_url, - skip_diarization, skip_punctuation, - speaker_channels_count, - custom_vocabularies, filter_profanity, - remove_disfluencies, delete_after_seconds, - language, custom_vocabulary_id, transcriber, - verbatim, rush, test_mode, - segments_to_transcribe, speaker_names, - source_config, notification_config, - skip_postprocessing, - remove_atmospherics, - speakers_count, - diarization_type, - skip_postprocessing, + payload = self._create_job_options_payload(media_url=media_url, + metadata=metadata, + callback_url=callback_url, + skip_diarization=skip_diarization, + skip_punctuation=skip_punctuation, + speaker_channels_count=speaker_channels_count, + custom_vocabularies=custom_vocabularies, + filter_profanity=filter_profanity, + remove_disfluencies=remove_disfluencies, + delete_after_seconds=delete_after_seconds, + language=language, + custom_vocabulary_id=custom_vocabulary_id, + transcriber=transcriber, + verbatim=verbatim, + rush=rush, + test_mode=test_mode, + segments_to_transcribe=segments_to_transcribe, + speaker_names=speaker_names, + source_config=source_config, + notification_config=notification_config, + skip_postprocessing=skip_postprocessing, + remove_atmospherics=remove_atmospherics, + speakers_count=speakers_count, + diarization_type=diarization_type, summarization_config=summarization_config, translation_config=translation_config) @@ -236,17 +246,30 @@ def submit_job_local_file( if not filename: raise ValueError('filename must be provided') - payload = self._create_job_options_payload(None, metadata, callback_url, - skip_diarization, skip_punctuation, - speaker_channels_count, - custom_vocabularies, filter_profanity, - remove_disfluencies, delete_after_seconds, - language, custom_vocabulary_id, transcriber, - verbatim, rush, test_mode, - segments_to_transcribe, speaker_names, None, - notification_config, skip_postprocessing, - remove_atmospherics, speakers_count, - diarization_type, + payload = self._create_job_options_payload(media_url=None, + metadata=metadata, + callback_url=callback_url, + skip_diarization=skip_diarization, + skip_punctuation=skip_punctuation, + speaker_channels_count=speaker_channels_count, + custom_vocabularies=custom_vocabularies, + filter_profanity=filter_profanity, + remove_disfluencies=remove_disfluencies, + delete_after_seconds=delete_after_seconds, + language=language, + custom_vocabulary_id=custom_vocabulary_id, + transcriber=transcriber, + verbatim=verbatim, + rush=rush, + test_mode=test_mode, + segments_to_transcribe=segments_to_transcribe, + speaker_names=speaker_names, + source_config=None, + notification_config=notification_config, + skip_postprocessing=skip_postprocessing, + remove_atmospherics=remove_atmospherics, + speakers_count=speakers_count, + diarization_type=diarization_type, summarization_config=summarization_config, translation_config=translation_config) diff --git a/tests/test_job.py b/tests/test_job.py index f2b952c9..03bdfbcb 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -120,7 +120,10 @@ def test_submit_job_url_with_success(self, mock_session, make_mock_response): 'delete_after_seconds': 0, 'language': LANGUAGE, 'transcriber': TRANSCRIBER, - 'skip_postprocessing': True + 'skip_postprocessing': True, + 'remove_atmospherics': True, + 'speakers_count': 123, + 'diarization_type': "premium" } response = make_mock_response(url=JOB_ID_URL, json_data=data) mock_session.request.return_value = response @@ -130,7 +133,12 @@ def test_submit_job_url_with_success(self, mock_session, make_mock_response): NOTIFICATION_URL, True, True, 1, CUSTOM_VOCAB, True, True, 0, LANGUAGE, CUSTOM_VOCAB_ID, - TRANSCRIBER, skip_postprocessing=True) + TRANSCRIBER, + skip_postprocessing=True, + remove_atmospherics=True, + speakers_count=123, + diarization_type="premium" + ) assert res == Job(JOB_ID, CREATED_ON, @@ -143,7 +151,11 @@ def test_submit_job_url_with_success(self, mock_session, make_mock_response): remove_disfluencies=True, delete_after_seconds=0, language=LANGUAGE, - transcriber=TRANSCRIBER) + transcriber=TRANSCRIBER, + remove_atmospherics=True, + speakers_count=123, + diarization_type="premium" + ) mock_session.request.assert_called_once_with( "POST", JOBS_URL, @@ -161,7 +173,10 @@ def test_submit_job_url_with_success(self, mock_session, make_mock_response): 'language': LANGUAGE, 'custom_vocabulary_id': CUSTOM_VOCAB_ID, 'transcriber': TRANSCRIBER, - 'skip_postprocessing': True + 'skip_postprocessing': True, + 'remove_atmospherics': True, + 'speakers_count': 123, + 'diarization_type': "premium" }, headers=client.default_headers) @@ -283,7 +298,10 @@ def test_submit_job_local_file_with_success(self, mocker, mock_session, make_moc 'delete_after_seconds': 0, 'language': LANGUAGE, 'transcriber': TRANSCRIBER, - 'skip_postprocessing': True + 'skip_postprocessing': True, + 'remove_atmospherics': True, + 'speakers_count': 123, + 'diarization_type': "premium" } response = make_mock_response(url=JOB_ID_URL, json_data=data) mock_session.request.return_value = response @@ -294,7 +312,11 @@ def test_submit_job_local_file_with_success(self, mocker, mock_session, make_moc NOTIFICATION_URL, True, True, 1, CUSTOM_VOCAB, True, True, 0, LANGUAGE, CUSTOM_VOCAB_ID, - TRANSCRIBER, skip_postprocessing=True) + TRANSCRIBER, skip_postprocessing=True, + remove_atmospherics=True, + speakers_count=123, + diarization_type="premium" + ) assert res == Job(JOB_ID, CREATED_ON, @@ -308,7 +330,11 @@ def test_submit_job_local_file_with_success(self, mocker, mock_session, make_moc remove_disfluencies=True, delete_after_seconds=0, language=LANGUAGE, - transcriber=TRANSCRIBER) + transcriber=TRANSCRIBER, + remove_atmospherics=True, + speakers_count=123, + diarization_type="premium" + ) mock_session.request.assert_called_once_with( "POST", JOBS_URL, @@ -329,7 +355,10 @@ def test_submit_job_local_file_with_success(self, mocker, mock_session, make_moc 'language': LANGUAGE, 'custom_vocabulary_id': CUSTOM_VOCAB_ID, 'transcriber': TRANSCRIBER, - 'skip_postprocessing': True + 'skip_postprocessing': True, + 'remove_atmospherics': True, + 'speakers_count': 123, + 'diarization_type': "premium" }, sort_keys=True) ) },