diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ad22cb85..2ab67022 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 5.2.1 +current_version = 5.2.2 commit = True [bumpversion:file:ibm_watson/version.py] diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f86b1ef..248fa0ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [5.2.2](https://github.com/watson-developer-cloud/python-sdk/compare/v5.2.1...v5.2.2) (2021-07-06) + + +### Bug Fixes + +* robustify the STT streaming results handling ([#768](https://github.com/watson-developer-cloud/python-sdk/issues/768)) ([264807d](https://github.com/watson-developer-cloud/python-sdk/commit/264807d7eb3287bbca56328496a477e042a9b2ca)) + ## [5.2.1](https://github.com/watson-developer-cloud/python-sdk/compare/v5.2.0...v5.2.1) (2021-06-28) diff --git a/ibm_watson/version.py b/ibm_watson/version.py index 4dc2ef26..7478af2c 100644 --- a/ibm_watson/version.py +++ b/ibm_watson/version.py @@ -1 +1 @@ -__version__ = '5.2.1' +__version__ = '5.2.2' diff --git a/ibm_watson/websocket/recognize_listener.py b/ibm_watson/websocket/recognize_listener.py index 3931a252..21679760 100644 --- a/ibm_watson/websocket/recognize_listener.py +++ b/ibm_watson/websocket/recognize_listener.py @@ -194,18 +194,21 @@ def on_data(self, ws, message, message_type, fin): # if in streaming elif 'results' in json_object or 'speaker_labels' in json_object: - hypothesis = '' - if 'results' in json_object: - hypothesis = json_object['results'][0]['alternatives'][0][ - 'transcript'] - b_final = (json_object['results'][0]['final'] is True) - transcripts = self.extract_transcripts( - json_object['results'][0]['alternatives']) - - if b_final: - self.callback.on_transcription(transcripts) - - self.callback.on_hypothesis(hypothesis) + # If results are present, extract the hypothesis and, if finalized, the full + # set of transcriptions and send them to the appropriate callbacks. + results = json_object.get('results') + if results: + b_final = (results[0].get('final') is True) + alternatives = results[0].get('alternatives') + if alternatives: + hypothesis = alternatives[0].get('transcript') + transcripts = self.extract_transcripts(alternatives) + if b_final: + self.callback.on_transcription(transcripts) + if hypothesis: + self.callback.on_hypothesis(hypothesis) + + # Always call the on_data callback if 'results' or 'speaker_labels' are present self.callback.on_data(json_object) def on_error(self, ws, error): diff --git a/setup.py b/setup.py index d8d42ea5..f3d67142 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ from setuptools import setup from os import path -__version__ = '5.2.1' +__version__ = '5.2.2' # read contents of README file this_directory = path.abspath(path.dirname(__file__))