From 5b3a8a0605696da4c7d06249af5a1189877f8bb3 Mon Sep 17 00:00:00 2001 From: nikkie Date: Mon, 15 Apr 2024 14:50:05 +0000 Subject: [PATCH 1/6] [refactor] Install ffmpeg by GitHub Action --- .github/workflows/unittests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 01ede18f..ce992f60 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -27,7 +27,8 @@ jobs: run: | sudo apt-get update sudo apt-get install --no-install-recommends -y libpulse-dev libasound2-dev - sudo apt-get install --no-install-recommends -y ffmpeg + - name: Install ffmpeg (for Whisper) + uses: FedericoCarboni/setup-ffmpeg@v3 - name: Install Python dependencies run: | python -m pip install 'pocketsphinx<5' From 4f1dbc5e789019117138a52d85e181c8ca4307f0 Mon Sep 17 00:00:00 2001 From: nikkie Date: Mon, 15 Apr 2024 15:19:04 +0000 Subject: [PATCH 2/6] [test] Skip pocketsphinx on Windows (future drop) --- tests/test_recognition.py | 2 ++ tests/test_special_features.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/test_recognition.py b/tests/test_recognition.py index bb0ce3a9..cb575053 100644 --- a/tests/test_recognition.py +++ b/tests/test_recognition.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import os +import sys import unittest import speech_recognition as sr @@ -25,6 +26,7 @@ def test_recognizer_attributes(self): self.assertEqual(r.phrase_threshold, 0.3) self.assertEqual(r.non_speaking_duration, 0.5) + @unittest.skip(sys.platform.startswith("win"), "skip on Windows") def test_sphinx_english(self): r = sr.Recognizer() with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source) diff --git a/tests/test_special_features.py b/tests/test_special_features.py index f249356e..b47d3d66 100644 --- a/tests/test_special_features.py +++ b/tests/test_special_features.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import os +import sys import unittest import speech_recognition as sr @@ -12,6 +13,7 @@ def setUp(self): self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav") self.addTypeEqualityFunc(str, self.assertSameWords) + @unittest.skip(sys.platform.startswith("win"), "skip on Windows") def test_sphinx_keywords(self): r = sr.Recognizer() with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source) From 4619ec5b4a7f11f9bcb0966e2279386c76562694 Mon Sep 17 00:00:00 2001 From: nikkie Date: Mon, 15 Apr 2024 15:19:53 +0000 Subject: [PATCH 3/6] [chore] Run unittests on Windows too --- .github/workflows/unittests.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index ce992f60..dfc5f309 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -10,13 +10,21 @@ on: jobs: build: - runs-on: ubuntu-latest - strategy: fail-fast: true matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] - + include: + - os: ubuntu-latest + python-version: "3.8" + - os: ubuntu-latest + python-version: "3.9" + - os: ubuntu-latest + python-version: "3.10" + - os: ubuntu-latest + python-version: "3.11" + - os: windows-latest + python-version: "3.11" + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -24,14 +32,18 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install build dependencies + if: ${{ matrix.os }} == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install --no-install-recommends -y libpulse-dev libasound2-dev - name: Install ffmpeg (for Whisper) uses: FedericoCarboni/setup-ffmpeg@v3 - - name: Install Python dependencies + - name: Install Python dependencies (Ubuntu only) + if: ${{ matrix.os }} == 'ubuntu-latest' run: | python -m pip install 'pocketsphinx<5' + - name: Install Python dependencies + run: | python -m pip install .[whisper-local,whisper-api] - name: Test with unittest run: | From 64c7e565054103cab8fcbf8cae856c218a2b930b Mon Sep 17 00:00:00 2001 From: nikkie Date: Tue, 16 Apr 2024 00:03:06 +0000 Subject: [PATCH 4/6] [bugfix] Omit brackets --- .github/workflows/unittests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index dfc5f309..00625686 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -32,14 +32,14 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install build dependencies - if: ${{ matrix.os }} == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update sudo apt-get install --no-install-recommends -y libpulse-dev libasound2-dev - name: Install ffmpeg (for Whisper) uses: FedericoCarboni/setup-ffmpeg@v3 - name: Install Python dependencies (Ubuntu only) - if: ${{ matrix.os }} == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' run: | python -m pip install 'pocketsphinx<5' - name: Install Python dependencies From f1e6a84f4525fe6929688f9f3934dc6b2de33d51 Mon Sep 17 00:00:00 2001 From: nikkie Date: Tue, 16 Apr 2024 00:09:00 +0000 Subject: [PATCH 5/6] [bugfix] Confuse with skipIf --- tests/test_recognition.py | 2 +- tests/test_special_features.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_recognition.py b/tests/test_recognition.py index cb575053..72511663 100644 --- a/tests/test_recognition.py +++ b/tests/test_recognition.py @@ -26,7 +26,7 @@ def test_recognizer_attributes(self): self.assertEqual(r.phrase_threshold, 0.3) self.assertEqual(r.non_speaking_duration, 0.5) - @unittest.skip(sys.platform.startswith("win"), "skip on Windows") + @unittest.skipIf(sys.platform.startswith("win"), "skip on Windows") def test_sphinx_english(self): r = sr.Recognizer() with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source) diff --git a/tests/test_special_features.py b/tests/test_special_features.py index b47d3d66..9dd2574e 100644 --- a/tests/test_special_features.py +++ b/tests/test_special_features.py @@ -13,7 +13,7 @@ def setUp(self): self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav") self.addTypeEqualityFunc(str, self.assertSameWords) - @unittest.skip(sys.platform.startswith("win"), "skip on Windows") + @unittest.skipIf(sys.platform.startswith("win"), "skip on Windows") def test_sphinx_keywords(self): r = sr.Recognizer() with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source) From 654c471a143c5fc7a86481313173e1024bfe4582 Mon Sep 17 00:00:00 2001 From: nikkie Date: Tue, 16 Apr 2024 00:17:56 +0000 Subject: [PATCH 6/6] [test] Assert recognize_google attribute existance --- tests/test_recognition.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_recognition.py b/tests/test_recognition.py index 72511663..90c17521 100644 --- a/tests/test_recognition.py +++ b/tests/test_recognition.py @@ -16,6 +16,7 @@ def setUp(self): def test_recognizer_attributes(self): r = sr.Recognizer() + attributes = set(dir(r)) self.assertEqual(r.energy_threshold, 300) self.assertTrue(r.dynamic_energy_threshold) @@ -25,6 +26,8 @@ def test_recognizer_attributes(self): self.assertIsNone(r.operation_timeout) self.assertEqual(r.phrase_threshold, 0.3) self.assertEqual(r.non_speaking_duration, 0.5) + # https://github.com/Uberi/speech_recognition/issues/743 + self.assertTrue("recognize_google" in attributes) @unittest.skipIf(sys.platform.startswith("win"), "skip on Windows") def test_sphinx_english(self):