diff --git a/.github/workflows/python-demos.yml b/.github/workflows/python-demos.yml index a3eb9394..86469dcf 100644 --- a/.github/workflows/python-demos.yml +++ b/.github/workflows/python-demos.yml @@ -39,6 +39,12 @@ jobs: - name: Pre-build dependencies run: python -m pip install --upgrade pip + # ************** REMOVE AFTER RELEASE ******************** + - name: Build binding + run: | + pip install wheel setuptools && cd ../../binding/python && python setup.py sdist bdist_wheel && pip install dist/pvcheetah-2.1.0-py3-none-any.whl + # ******************************************************** + - name: Install dependencies run: pip install -r requirements.txt @@ -55,6 +61,12 @@ jobs: steps: - uses: actions/checkout@v3 + # ************** REMOVE AFTER RELEASE ******************** + - name: Build binding + run: | + pip3 install wheel setuptools && cd ../../binding/python && python3 setup.py sdist bdist_wheel && pip3 install dist/pvcheetah-2.1.0-py3-none-any.whl + # ******************************************************** + - name: Install dependencies run: pip3 install -r requirements.txt diff --git a/binding/python/_cheetah.py b/binding/python/_cheetah.py index c37911c4..0e963f96 100644 --- a/binding/python/_cheetah.py +++ b/binding/python/_cheetah.py @@ -1,12 +1,12 @@ # -# Copyright 2018-2023 Picovoice Inc. +# Copyright 2018-2024 Picovoice Inc. # -# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" -# file accompanying this source. +# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" +# file accompanying this source. # -# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. # import os @@ -16,7 +16,7 @@ class CheetahError(Exception): - def __init__(self, message: str = '', message_stack: Sequence[str] = None): + def __init__(self, message: str = '', message_stack: Optional[Sequence[str]] = None): super().__init__(message) self._message = message diff --git a/binding/python/setup.py b/binding/python/setup.py index 5d27e11c..09bc33bc 100644 --- a/binding/python/setup.py +++ b/binding/python/setup.py @@ -1,5 +1,5 @@ # -# Copyright 2022-2023 Picovoice Inc. +# Copyright 2022-2024 Picovoice Inc. # # You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" # file accompanying this source. @@ -48,7 +48,7 @@ setuptools.setup( name="pvcheetah", - version="2.0.2", + version="2.1.0", author="Picovoice", author_email="hello@picovoice.ai", description="Cheetah Speech-to-Text Engine.", diff --git a/binding/python/test_cheetah.py b/binding/python/test_cheetah.py index 40b42fef..aeedcbf8 100644 --- a/binding/python/test_cheetah.py +++ b/binding/python/test_cheetah.py @@ -1,19 +1,17 @@ # -# Copyright 2018-2023 Picovoice Inc. +# Copyright 2018-2024 Picovoice Inc. # -# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" -# file accompanying this source. +# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" +# file accompanying this source. # -# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. # import os -import struct import sys import unittest -import wave from parameterized import parameterized @@ -22,7 +20,7 @@ from test_util import * -parameters = load_test_data() +language_tests = load_test_data() class CheetahTestCase(unittest.TestCase): @@ -32,17 +30,17 @@ def setUpClass(cls): cls._audio_directory = os.path.join('..', '..', 'resources', 'audio_samples') @classmethod - def _create_cheetah(cls, enable_automatic_punctuation: bool) -> Cheetah: + def _create_cheetah(cls, language: str, enable_automatic_punctuation: bool) -> Cheetah: return Cheetah( access_key=cls._access_key, - model_path=default_model_path('../..'), + model_path=get_model_path_by_language(language=language), library_path=default_library_path('../..'), enable_automatic_punctuation=enable_automatic_punctuation) - @parameterized.expand(parameters) + @parameterized.expand(language_tests) def test_process( self, - _: str, + language: str, audio_file: str, expected_transcript: str, punctuations: List[str], @@ -50,7 +48,7 @@ def test_process( o = None try: - o = self._create_cheetah(False) + o = self._create_cheetah(language=language, enable_automatic_punctuation=False) pcm = read_wav_file( file_name=os.path.join(self._audio_directory, audio_file), @@ -77,10 +75,10 @@ def test_process( if o is not None: o.delete() - @parameterized.expand(parameters) + @parameterized.expand(language_tests) def test_process_with_punctuation( self, - _: str, + language: str, audio_file: str, expected_transcript: str, punctuations: List[str], @@ -88,7 +86,7 @@ def test_process_with_punctuation( o = None try: - o = self._create_cheetah(True) + o = self._create_cheetah(language=language, enable_automatic_punctuation=True) pcm = read_wav_file( file_name=os.path.join(self._audio_directory, audio_file), @@ -112,7 +110,11 @@ def test_process_with_punctuation( o.delete() def test_version(self): - o = self._create_cheetah(False) + o = Cheetah( + access_key=self._access_key, + model_path=default_model_path('../..'), + library_path=default_library_path('../..'), + enable_automatic_punctuation=True) self.assertIsInstance(o.version, str) self.assertGreater(len(o.version), 0) diff --git a/binding/python/test_cheetah_perf.py b/binding/python/test_cheetah_perf.py index dfc5b795..3c173fd0 100644 --- a/binding/python/test_cheetah_perf.py +++ b/binding/python/test_cheetah_perf.py @@ -1,12 +1,12 @@ # -# Copyright 2022 Picovoice Inc. +# Copyright 2022-2024 Picovoice Inc. # -# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" -# file accompanying this source. +# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" +# file accompanying this source. # -# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. # import os diff --git a/binding/python/test_util.py b/binding/python/test_util.py index 4ba1815e..8ebf818a 100644 --- a/binding/python/test_util.py +++ b/binding/python/test_util.py @@ -1,5 +1,5 @@ # -# Copyright 2023 Picovoice Inc. +# Copyright 2023-2024 Picovoice Inc. # # You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" # file accompanying this source. @@ -9,23 +9,32 @@ # specific language governing permissions and limitations under the License. # +import json +import os import struct import wave + from typing import * def load_test_data() -> List[Tuple[str, str, str, List[str], float]]: - parameters = [ + data_file_path = os.path.join(os.path.dirname(__file__), "../../resources/.test/test_data.json") + with open(data_file_path, encoding="utf8") as data_file: + json_test_data = data_file.read() + test_data = json.loads(json_test_data)['tests'] + + language_tests = [ ( - "en", - "test.wav", - "Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.", - ["."], - 0.025 + t['language'], + t['audio_file'], + t['transcript'], + t['punctuations'], + t['error_rate'], ) + for t in test_data['language_tests'] ] - return parameters + return language_tests def read_wav_file(file_name: str, sample_rate: int) -> Tuple: @@ -48,6 +57,17 @@ def read_wav_file(file_name: str, sample_rate: int) -> Tuple: return frames[::channels] +def get_model_path_by_language(language: str) -> str: + model_path_subdir = _append_language('../../lib/common/cheetah_params', language) + return os.path.join(os.path.dirname(__file__), f'{model_path_subdir}.pv') + + +def _append_language(s: str, language: str) -> str: + if language == 'en': + return s + return "%s_%s" % (s, language) + + def get_word_error_rate(transcript: str, expected_transcript: str, use_cer: bool = False) -> float: transcript_split = list(transcript) if use_cer else transcript.split() expected_split = list(expected_transcript) if use_cer else expected_transcript.split() @@ -55,7 +75,7 @@ def get_word_error_rate(transcript: str, expected_transcript: str, use_cer: bool def _levenshtein_distance(words1: Sequence[str], words2: Sequence[str]) -> int: - res = [[0] * (len(words1) + 2) for _ in range(len(words2) + 1)] + res = [[0] * (len(words2) + 1) for _ in range(len(words1) + 1)] for i in range(len(words1) + 1): res[i][0] = i for j in range(len(words2) + 1): diff --git a/demo/python/requirements.txt b/demo/python/requirements.txt index c9d2486b..71bb9cbc 100644 --- a/demo/python/requirements.txt +++ b/demo/python/requirements.txt @@ -1,2 +1,2 @@ -pvcheetah==2.0.2 +pvcheetah==2.1.0 pvrecorder==1.2.3 diff --git a/demo/python/setup.py b/demo/python/setup.py index 6bc828ec..b492d541 100644 --- a/demo/python/setup.py +++ b/demo/python/setup.py @@ -28,7 +28,7 @@ setuptools.setup( name="pvcheetahdemo", - version="2.0.2", + version="2.1.0", author="Picovoice", author_email="hello@picovoice.ai", description="Cheetah speech-to-text engine demos",