From 938f6df386c0f50568f7a6c04ed4ae58e440af04 Mon Sep 17 00:00:00 2001 From: JayZed Date: Sun, 28 Jan 2024 21:09:37 -0500 Subject: [PATCH] Added separate values to whisperai provider for connection and read timeouts Added "response" key with default value of 5 to pair with existing "timeout" key which has a default of 3600 sec. Both values can be updated in WhisperAI settings dialog by user. More information about these timeouts here: https://reqbin.com/code/python/3zdpeao1/python-requests-timeout-example --- bazarr/app/config.py | 1 + bazarr/app/get_providers.py | 1 + frontend/src/pages/Settings/Providers/list.ts | 6 ++++++ libs/subliminal_patch/providers/whisperai.py | 12 ++++++++---- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bazarr/app/config.py b/bazarr/app/config.py index d1967cc38..560069f40 100644 --- a/bazarr/app/config.py +++ b/bazarr/app/config.py @@ -228,6 +228,7 @@ validators = [ # whisperai section Validator('whisperai.endpoint', must_exist=True, default='http://127.0.0.1:9000', is_type_of=str), + Validator('whisperai.response', must_exist=True, default=5, is_type_of=int, gte=1), Validator('whisperai.timeout', must_exist=True, default=3600, is_type_of=int, gte=1), Validator('whisperai.loglevel', must_exist=True, default='INFO', is_type_of=str, is_in=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']), diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py index 2b6d5f5f7..278b38288 100644 --- a/bazarr/app/get_providers.py +++ b/bazarr/app/get_providers.py @@ -311,6 +311,7 @@ def get_providers_auth(): }, 'whisperai': { 'endpoint': settings.whisperai.endpoint, + 'response': settings.whisperai.response, 'timeout': settings.whisperai.timeout, 'ffmpeg_path': _FFMPEG_BINARY, 'loglevel': settings.whisperai.loglevel, diff --git a/frontend/src/pages/Settings/Providers/list.ts b/frontend/src/pages/Settings/Providers/list.ts index f4f6dc471..b811a852a 100644 --- a/frontend/src/pages/Settings/Providers/list.ts +++ b/frontend/src/pages/Settings/Providers/list.ts @@ -442,6 +442,12 @@ export const ProviderList: Readonly = [ defaultValue: "http://127.0.0.1:9000", name: "Whisper ASR Docker Endpoint", }, + { + type: "text", + key: "response", + defaultValue: 5, + name: "Connection/response timeout in seconds", + }, { type: "text", key: "timeout", diff --git a/libs/subliminal_patch/providers/whisperai.py b/libs/subliminal_patch/providers/whisperai.py index 1cf6e5ff0..33421f201 100644 --- a/libs/subliminal_patch/providers/whisperai.py +++ b/libs/subliminal_patch/providers/whisperai.py @@ -213,18 +213,22 @@ class WhisperAIProvider(Provider): video_types = (Episode, Movie) - def __init__(self, endpoint=None, timeout=None, ffmpeg_path=None, loglevel=None): + def __init__(self, endpoint=None, response=None, timeout=None, ffmpeg_path=None, loglevel=None): set_log_level(loglevel) if not endpoint: raise ConfigurationError('Whisper Web Service Endpoint must be provided') + if not response: + raise ConfigurationError('Whisper Web Service Connection/response timeout must be provided') + if not timeout: - raise ConfigurationError('Whisper Web Service Timeout must be provided') + raise ConfigurationError('Whisper Web Service Transcription/translation timeout must be provided') if not ffmpeg_path: raise ConfigurationError("ffmpeg path must be provided") self.endpoint = endpoint + self.response = int(response) self.timeout = int(timeout) self.session = None self.ffmpeg_path = ffmpeg_path @@ -248,7 +252,7 @@ class WhisperAIProvider(Provider): r = self.session.post(f"{self.endpoint}/detect-language", params={'encode': 'false'}, files={'audio_file': out}, - timeout=(self.timeout, self.timeout)) + timeout=(self.response, self.timeout)) logger.debug(f"Whisper detected language of {path} as {r.json()['detected_language']}") @@ -326,7 +330,7 @@ class WhisperAIProvider(Provider): r = self.session.post(f"{self.endpoint}/asr", params={'task': subtitle.task, 'language': whisper_get_language_reverse(subtitle.audio_language), 'output': 'srt', 'encode': 'false'}, files={'audio_file': out}, - timeout=(self.timeout, self.timeout)) + timeout=(self.response, self.timeout)) endTime = time.time() elapsedTime = timedelta(seconds=round(endTime - startTime))