Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty responses from whisper #2745

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions custom_libs/subliminal_patch/providers/whisperai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from requests import Session

from requests.exceptions import JSONDecodeError
from subliminal_patch.subtitle import Subtitle
from subliminal_patch.providers import Provider
from subliminal import __short_version__
Expand Down Expand Up @@ -269,10 +270,19 @@ def detect_language(self, path) -> Language:
params={'encode': 'false'},
files={'audio_file': out},
timeout=(self.response, self.timeout))

try:
results = r.json()
except JSONDecodeError:
results = {}

if len(results) == 0:
logger.info(f"Whisper returned empty response when detecting language")
return None

logger.debug(f"Whisper detected language of {path} as {r.json()['detected_language']}")
logger.debug(f"Whisper detected language of {path} as {results['detected_language']}")

return whisper_get_language(r.json()["language_code"], r.json()["detected_language"])
return whisper_get_language(results["language_code"], results["detected_language"])

def query(self, language, video):
if language not in self.languages:
Expand Down