From 6de37f8d2ce7d5c8e74564b0e2f7ab7f3220ebac Mon Sep 17 00:00:00 2001 From: nikkie Date: Wed, 17 Apr 2024 13:13:04 +0000 Subject: [PATCH 1/4] [chore] Install latest pocketsphinx (5.0.3) --- .github/workflows/unittests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 00625686..079dcd47 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -41,7 +41,7 @@ jobs: - name: Install Python dependencies (Ubuntu only) if: matrix.os == 'ubuntu-latest' run: | - python -m pip install 'pocketsphinx<5' + python -m pip install pocketsphinx - name: Install Python dependencies run: | python -m pip install .[whisper-local,whisper-api] From 4aedf9de2249dd57e605a8a7531ba56fe5392da8 Mon Sep 17 00:00:00 2001 From: nikkie Date: Wed, 17 Apr 2024 13:14:03 +0000 Subject: [PATCH 2/4] [bugfix] Fix pocketsphinx's DeprecationWarning --- speech_recognition/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/speech_recognition/__init__.py b/speech_recognition/__init__.py index 8e68c30d..2a175e3d 100644 --- a/speech_recognition/__init__.py +++ b/speech_recognition/__init__.py @@ -623,7 +623,7 @@ def recognize_sphinx(self, audio_data, language="en-US", keyword_entries=None, g raise RequestError("missing PocketSphinx phoneme dictionary file: \"{}\"".format(phoneme_dictionary_file)) # create decoder object - config = pocketsphinx.Decoder.default_config() + config = pocketsphinx.Config() config.set_string("-hmm", acoustic_parameters_directory) # set the path of the hidden Markov model (HMM) parameter files config.set_string("-lm", language_model_file) config.set_string("-dict", phoneme_dictionary_file) @@ -641,8 +641,8 @@ def recognize_sphinx(self, audio_data, language="en-US", keyword_entries=None, g f.flush() # perform the speech recognition with the keywords file (this is inside the context manager so the file isn;t deleted until we're done) - decoder.set_kws("keywords", f.name) - decoder.set_search("keywords") + decoder.add_kws("keywords", f.name) + decoder.activate_search("keywords") elif grammar is not None: # a path to a FSG or JSGF grammar if not os.path.exists(grammar): raise ValueError("Grammar '{0}' does not exist.".format(grammar)) From b9940b7cdee74d01e13dae7f509b03c11aba59b8 Mon Sep 17 00:00:00 2001 From: nikkie Date: Wed, 17 Apr 2024 13:16:50 +0000 Subject: [PATCH 3/4] [test] Workaround: Fix expected for pocketsphinx 5.0.x --- tests/test_special_features.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_special_features.py b/tests/test_special_features.py index 9dd2574e..a710e74c 100644 --- a/tests/test_special_features.py +++ b/tests/test_special_features.py @@ -18,8 +18,8 @@ def test_sphinx_keywords(self): r = sr.Recognizer() with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source) self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("one", 1.0), ("two", 1.0), ("three", 1.0)]), "three two one") - self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0.95), ("too", 1.0), ("tree", 1.0)]), "tree too wan") - self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "tee to un") + self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0.95), ("too", 1.0), ("tree", 1.0)]), "wan too wan too ") + self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "un un un to un to ") def assertSameWords(self, tested, reference, msg=None): set_tested = set(tested.split()) From 616084565e1cd87ed4588a195739d6d2948e33d3 Mon Sep 17 00:00:00 2001 From: nikkie Date: Thu, 18 Apr 2024 14:27:00 +0000 Subject: [PATCH 4/4] [docs] pocketsphinx maintained official repository --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 965bd46a..972ad15b 100644 --- a/README.rst +++ b/README.rst @@ -129,7 +129,7 @@ PyAudio `wheel packages `__ for common 64-bi PocketSphinx-Python (for Sphinx users) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -`PocketSphinx-Python `__ is **required if and only if you want to use the Sphinx recognizer** (``recognizer_instance.recognize_sphinx``). +`PocketSphinx-Python `__ is **required if and only if you want to use the Sphinx recognizer** (``recognizer_instance.recognize_sphinx``). PocketSphinx-Python `wheel packages `__ for 64-bit Python 3.4, and 3.5 on Windows are included for convenience, under the ``third-party/`` `directory `__. To install, simply run ``pip install wheel`` followed by ``pip install ./third-party/WHEEL_FILENAME`` (replace ``pip`` with ``pip3`` if using Python 3) in the SpeechRecognition folder.