Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pouya Rostam committed Sep 13, 2023
1 parent 32dd49e commit 2e751d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 39 deletions.
3 changes: 2 additions & 1 deletion demo/c/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cmake-build-debug
build
build
__pycache__
23 changes: 5 additions & 18 deletions demo/c/test/test_falcon_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
import sys
import unittest

from jiwer import wer
from parameterized import parameterized

from test_util import *

test_parameters = load_test_data()


class PorcupineCTestCase(unittest.TestCase):
class FalconCTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
Expand All @@ -37,29 +32,21 @@ def _get_library_file(self):
"lib",
self._platform,
self._arch,
"libpv_leopard." + get_lib_ext(self._platform)
"libpv_falcon." + get_lib_ext(self._platform)
)

def _get_model_path_by_language(self, language):
model_path_subdir = append_language('lib/common/leopard_params', language)
return os.path.join(self._root_dir, '%s.pv' % model_path_subdir)

@parameterized.expand(test_parameters)
def test_leopard(self, language, audio_file_name, ground_truth, error_rate):
def test_leopard(self, language, audio_file_name, error_rate):
args = [
os.path.join(os.path.dirname(__file__), "../build/leopard_demo"),
os.path.join(os.path.dirname(__file__), "../build/falcon_demo"),
"-a", self._access_key,
"-l", self._get_library_file(),
"-m", self._get_model_path_by_language(language),
"-m", os.path.join(self._root_dir, 'lib/common/falcon_params.pv'),
os.path.join(self._root_dir, 'resources/audio_samples', audio_file_name),
]
process = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
stdout, stderr = process.communicate()
self.assertEqual(process.poll(), 0)
self.assertEqual(stderr.decode('utf-8'), '')
transcript = stdout.decode('utf-8').strip().split('\n')[1]
error = wer(ground_truth, transcript)
self.assertLessEqual(error, error_rate)


if __name__ == '__main__':
Expand Down
21 changes: 1 addition & 20 deletions demo/c/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,4 @@ def get_lib_ext(platform):
elif platform == "mac":
return "dylib"
else:
return "so"


def append_language(s, language):
if language == 'en':
return s
return "%s_%s" % (s, language)


def load_test_data():
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']['parameters']

test_parameters = [
(t['language'], t['audio_file'], t['transcript'], t['error_rate'])
for t in test_data]

return test_parameters
return "so"

0 comments on commit 2e751d6

Please sign in to comment.