Skip to content

Commit

Permalink
Handle empty responses from whisper
Browse files Browse the repository at this point in the history
This will replace JSONDecodeError with a more friendly message.
  • Loading branch information
JaiZed committed Oct 30, 2024
1 parent ac1a3c5 commit b5f6e5a
Showing 1 changed file with 12 additions and 2 deletions.
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

0 comments on commit b5f6e5a

Please sign in to comment.