Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 python #672

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions .github/workflows/python-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
include:
- os: ubuntu-latest
platform: linux
Expand All @@ -46,7 +46,26 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Pre-build dependencies
run: python -m pip install --upgrade pip
run: |
python -m pip install --upgrade pip
pip install wheel

# ************** REMOVE AFTER RELEASE ********************
- name: ppn
working-directory: resources/porcupine/binding/python
run: |
python setup.py sdist bdist_wheel && pip install dist/pvporcupine-3.0.0-py3-none-any.whl

- name: rhn
working-directory: resources/rhino/binding/python
run: |
python setup.py sdist bdist_wheel && pip install dist/pvrhino-3.0.0-py3-none-any.whl

- name: pv
working-directory: sdk/python
run: |
python setup.py sdist bdist_wheel && pip install dist/picovoice-3.0.0-py3-none-any.whl
# ********************************************************

- name: Install dependencies
run: pip install -r requirements.txt
Expand Down Expand Up @@ -85,6 +104,28 @@ jobs:
with:
submodules: recursive

- name: Pre-build dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install wheel

# ************** REMOVE AFTER RELEASE ********************
- name: ppn
working-directory: resources/porcupine/binding/python
run: |
pip3 uninstall -y pvporcupine && python3 setup.py sdist bdist_wheel && pip3 install dist/pvporcupine-3.0.0-py3-none-any.whl

- name: rhn
working-directory: resources/rhino/binding/python
run: |
pip3 uninstall -y pvrhino && python3 setup.py sdist bdist_wheel && pip3 install dist/pvrhino-3.0.0-py3-none-any.whl

- name: pv
working-directory: sdk/python
run: |
pip3 uninstall -y picovoice && python3 setup.py sdist bdist_wheel && pip3 install dist/picovoice-3.0.0-py3-none-any.whl
# ********************************************************

- name: Install dependencies
run: pip3 install -r requirements.txt

Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
Expand All @@ -51,6 +51,18 @@ jobs:
python -m pip install --upgrade pip
pip install wheel

# ************** REMOVE AFTER RELEASE ********************
- name: ppn
working-directory: resources/porcupine/binding/python
run: |
pip install wheel && python setup.py sdist bdist_wheel && pip install dist/pvporcupine-3.0.0-py3-none-any.whl

- name: rhn
working-directory: resources/rhino/binding/python
run: |
python setup.py sdist bdist_wheel && pip install dist/pvrhino-3.0.0-py3-none-any.whl
# ********************************************************

- name: Install dependencies
run: pip3 install -r requirements.txt

Expand All @@ -75,6 +87,18 @@ jobs:
python3 -m pip install --upgrade pip
pip3 install wheel

# ************** REMOVE AFTER RELEASE ********************
- name: ppn
working-directory: resources/porcupine/binding/python
run: |
pip3 uninstall -y pvporcupine && python3 setup.py sdist bdist_wheel && pip3 install dist/pvporcupine-3.0.0-py3-none-any.whl

- name: rhn
working-directory: resources/rhino/binding/python
run: |
pip3 uninstall -y pvrhino && python3 setup.py sdist bdist_wheel && pip3 install dist/pvrhino-3.0.0-py3-none-any.whl
# ********************************************************

- name: Install dependencies
run: pip3 install -r requirements.txt

Expand Down
2 changes: 1 addition & 1 deletion demo/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
picovoice==2.2.1
picovoice==3.0.0
pvrecorder==1.2.1
4 changes: 2 additions & 2 deletions demo/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@

setuptools.setup(
name="picovoicedemo",
version="2.2.4",
version="3.0.0",
author="Picovoice Inc.",
author_email="hello@picovoice.ai",
description="Picovoice demos.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Picovoice/picovoice",
packages=["picovoicedemo"],
install_requires=["picovoice==2.2.1", "pvrecorder==1.2.1"],
install_requires=["picovoice==3.0.0", "pvrecorder==1.2.1"],
include_package_data=True,
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
4 changes: 2 additions & 2 deletions demo/tkinter/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
picovoice==2.2.1
pvrecorder==1.1.2
picovoice==3.0.0
pvrecorder==1.2.1
15 changes: 13 additions & 2 deletions sdk/python/_picovoice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2020-2022 Picovoice Inc.
# Copyright 2020-2023 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.
Expand Down Expand Up @@ -261,6 +261,17 @@ def process(self, pcm: Sequence[int]) -> None:
except pvrhino.RhinoError as e:
raise _PPN_RHN_ERROR_TO_PICOVOICE_ERROR[type(e)] from e

def reset(self) -> None:
"""
Resets the internal state of Picovoice. It should be called before processing a new stream of audio
or when Picovoice was stopped whilst processing a stream of audio.
"""
try:
self._is_wake_word_detected = False
self._rhino.reset()
except pvrhino.RhinoError as e:
raise _PPN_RHN_ERROR_TO_PICOVOICE_ERROR[type(e)] from e

@property
def sample_rate(self) -> int:
"""Audio sample rate accepted by Picovoice."""
Expand All @@ -277,7 +288,7 @@ def frame_length(self) -> int:
def version(self) -> str:
"""Version"""

return '2.2.0'
return '3.0.0'

@property
def context_info(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameterized
pvporcupine==2.2.1
pvrhino==2.2.1
pvporcupine==3.0.0
pvrhino==3.0.0
setuptools
6 changes: 3 additions & 3 deletions sdk/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2020-2022 Picovoice Inc.
# Copyright 2020-2023 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.
Expand Down Expand Up @@ -33,15 +33,15 @@

setuptools.setup(
name="picovoice",
version="2.2.1",
version="3.0.0",
author="Picovoice Inc.",
author_email="hello@picovoice.ai",
description="Picovoice is an end-to-end platform for building voice products on your terms.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Picovoice/picovoice",
packages=["picovoice"],
install_requires=["pvporcupine==2.2.1", "pvrhino==2.2.1"],
install_requires=["pvporcupine==3.0.0", "pvrhino==3.0.0"],
include_package_data=True,
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
47 changes: 35 additions & 12 deletions sdk/python/test_picovoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class PicovoiceTestData:
def __init__(self):
self.picovoiceInstance = None
self.picovoice = None
self.is_wake_word_detected = False
self.inference = None

Expand All @@ -41,6 +41,15 @@ def inference_callback(self, inference):
self.inference = inference


class PicovoiceResetTestData(PicovoiceTestData):
def __init__(self):
super().__init__()

def wake_word_callback(self):
self.is_wake_word_detected = True
self.picovoice.reset()


class PicovoiceTestCase(unittest.TestCase):
@staticmethod
def _concatenate(language, context, keyword):
Expand All @@ -66,9 +75,8 @@ def __read_file(file_name, sample_rate):

return frames[::channels]

def run_picovoice(self, language, keyword, context, audio_file_name, intent, slots):
test_data = PicovoiceTestData()
picovoice = Picovoice(
def run_picovoice(self, language, keyword, context, audio_file_name, intent, slots, test_data):
test_data.picovoice = Picovoice(
access_key=sys.argv[1],
keyword_path=pv_keyword_paths_by_language(language)[keyword],
context_path=context_path(context, language),
Expand All @@ -80,17 +88,20 @@ def run_picovoice(self, language, keyword, context, audio_file_name, intent, slo
audio = \
self.__read_file(
os.path.join(os.path.dirname(__file__), '../../resources/audio_samples', audio_file_name),
picovoice.sample_rate)
test_data.picovoice.sample_rate)

for _ in range(2):
test_data.reset()
for i in range(len(audio) // picovoice.frame_length):
frame = audio[i * picovoice.frame_length:(i + 1) * picovoice.frame_length]
picovoice.process(frame)
for i in range(len(audio) // test_data.picovoice.frame_length):
frame = audio[i * test_data.picovoice.frame_length:(i + 1) * test_data.picovoice.frame_length]
test_data.picovoice.process(frame)

self.assertTrue(test_data.is_wake_word_detected)
self.assertEqual(test_data.inference.intent, intent)
self.assertEqual(test_data.inference.slots, slots)
if intent is None and slots is None:
self.assertIsNone(test_data.inference)
else:
self.assertEqual(test_data.inference.intent, intent)
self.assertEqual(test_data.inference.slots, slots)

@parameterized.expand(test_parameters)
def test_picovoice(self, language, keyword, context, audio_file_name, intent, slots):
Expand All @@ -100,12 +111,24 @@ def test_picovoice(self, language, keyword, context, audio_file_name, intent, sl
context=context,
audio_file_name=audio_file_name,
intent=intent,
slots=slots)
slots=slots,
test_data=PicovoiceTestData())

def test_reset(self):
test_param = test_parameters[0]
self.run_picovoice(
language=test_param[0],
keyword=test_param[1],
context=test_param[2],
audio_file_name=test_param[3],
intent=None,
slots=None,
test_data=PicovoiceResetTestData())


if __name__ == '__main__':
if len(sys.argv) != 2:
print("usage: test_porcupine.py ${ACCESS_KEY}")
print("usage: test_picovoice.py ${ACCESS_KEY}")
exit(1)

unittest.main(argv=sys.argv[:1])