1
0
mirror of https://github.com/Picovoice/porcupine.git synced 2022-01-28 03:27:53 +03:00

python test m1 (#627)

This commit is contained in:
Kwangsoo Yeo
2022-01-17 16:02:54 -08:00
committed by GitHub
parent 12e20e4ced
commit 153b57e957
8 changed files with 35 additions and 35 deletions

View File

@@ -50,7 +50,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ['3.5', '3.6', '3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v2
@@ -60,16 +60,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Pre-build dependencies specific to Ubuntu
if: runner.os == 'Linux'
run: sudo apt install libsndfile1-dev
- name: Pre-build dependencies
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt
- name: Test
run: python test_porcupine.py ${{secrets.PV_VALID_ACCESS_KEY}}
@@ -84,11 +74,5 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Pre-build dependencies
run: python3 -m pip install --upgrade pip
- name: Install dependencies
run: pip3 install -r requirements.txt
- name: Test
run: python3 test_porcupine.py ${{secrets.PV_VALID_ACCESS_KEY}}

View File

@@ -18,7 +18,7 @@ applications. It is
## Compatibility
- Python 3
- Python 3.5+
- Runs on Linux (x86_64), macOS (x86_64 and arm64), Windows (x86_64), Raspberry Pi, NVIDIA Jetson (Nano), and BeagleBone.
## Installation

View File

@@ -1,5 +1,5 @@
#
# Copyright 2020-2021 Picovoice Inc.
# Copyright 2020-2022 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.

View File

@@ -1,5 +1,5 @@
#
# Copyright 2018-2021 Picovoice Inc.
# Copyright 2018-2022 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.

View File

@@ -1,2 +0,0 @@
numpy
soundfile

View File

@@ -1,5 +1,5 @@
#
# Copyright 2019-2021 Picovoice Inc.
# Copyright 2019-2022 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.
@@ -75,7 +75,6 @@ setuptools.setup(
long_description_content_type="text/markdown",
url="https://github.com/Picovoice/porcupine",
packages=["pvporcupine"],
install_requires=["enum34", "numpy"],
include_package_data=True,
classifiers=[
"Development Status :: 5 - Production/Stable",
@@ -85,6 +84,6 @@ setuptools.setup(
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Sound/Audio :: Speech"
],
python_requires='>=3',
python_requires='>=3.5',
keywords="wake word engine, hotword detection, keyword spotting, wake word detection, voice commands",
)

View File

@@ -1,5 +1,5 @@
#
# Copyright 2018-2021 Picovoice Inc.
# Copyright 2018-2022 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,10 +9,10 @@
# specific language governing permissions and limitations under the License.
#
import struct
import sys
import unittest
import soundfile
import wave
from porcupine import Porcupine
from util import *
@@ -23,12 +23,32 @@ class PorcupineTestCase(unittest.TestCase):
def __append_language(s, language):
if language == 'en':
return s
return f'{s}_{language}'
return "%s_%s" % (s, language)
@staticmethod
def __read_file(file_name, sample_rate):
wav_file = wave.open(file_name, mode="rb")
channels = wav_file.getnchannels()
num_frames = wav_file.getnframes()
if wav_file.getframerate() != sample_rate:
raise ValueError(
"Audio file should have a sample rate of %d, got %d" % (sample_rate, wav_file.getframerate()))
samples = wav_file.readframes(num_frames)
wav_file.close()
frames = struct.unpack('h' * num_frames * channels, samples)
if channels == 2:
print("Picovoice processes single-channel audio but stereo file is provided. Processing left channel only.")
return frames[::channels]
@classmethod
def __pv_model_path_by_language(cls, relative, language):
model_path_subdir = cls.__append_language('lib/common/porcupine_params', language)
return os.path.join(os.path.dirname(__file__), relative, f'{model_path_subdir}.pv')
return os.path.join(os.path.dirname(__file__), relative, '%s.pv' % model_path_subdir)
@classmethod
def __pv_keyword_paths_by_language(cls, relative, language):
@@ -45,7 +65,7 @@ class PorcupineTestCase(unittest.TestCase):
def run_porcupine(self, language, keywords, ground_truth, audio_file_name=None):
if audio_file_name is None:
_audio_file_name_prefix = self.__append_language('multiple_keywords', language)
audio_file_name = f'{_audio_file_name_prefix}.wav'
audio_file_name = '%s.wav' % _audio_file_name_prefix
keyword_paths = list()
for x in keywords:
keyword_paths.append(self.__pv_keyword_paths_by_language('../..', language)[x])
@@ -57,10 +77,9 @@ class PorcupineTestCase(unittest.TestCase):
keyword_paths=keyword_paths,
sensitivities=[0.5] * len(keyword_paths))
audio, sample_rate = soundfile.read(
audio = self.__read_file(
os.path.join(os.path.dirname(__file__), '../../resources/audio_samples/', audio_file_name),
dtype='int16')
assert sample_rate == porcupine.sample_rate
porcupine.sample_rate)
num_frames = len(audio) // porcupine.frame_length
results = []

View File

@@ -1,5 +1,5 @@
#
# Copyright 2020-2021 Picovoice Inc.
# Copyright 2020-2022 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.