Skip to content

Commit

Permalink
fixed lib path in python demo app
Browse files Browse the repository at this point in the history
Former-commit-id: 50da639
  • Loading branch information
kenarsa authored and amiranhari committed Apr 7, 2018
1 parent a14c4f0 commit 3264eaf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 53 deletions.
49 changes: 24 additions & 25 deletions binding/python/test_porcupine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ class PorcupineTestCase(unittest.TestCase):

def setUp(self):
self._porcupine = Porcupine(
library_path=self._abs_path('../../lib/%s/%s/libpv_porcupine.%s' % (self._system(), self._machine(),
self._dylib_extension())),
library_path=self._library_path(),
model_file_path=self._abs_path('../../lib/common/porcupine_params.pv'),
keyword_file_path=self._abs_path('../../resources/keyword_files/porcupine_%s.ppn' % (self._system())),
keyword_file_path=self._abs_path('../../resources/keyword_files/porcupine_%s.ppn' % self._keyword_file_extension()),
sensitivity=0.5)

def tearDown(self):
Expand All @@ -55,33 +54,33 @@ def _abs_path(rel_path):
return os.path.join(os.path.dirname(__file__), rel_path)

@staticmethod
def _system():
x = platform.system()
if x == 'Linux':
def _keyword_file_extension():
system = platform.system()
machine = platform.machine()

if system == 'Linux' and (machine == 'x86_64' or machine == 'i386'):
return 'linux'
elif x == 'Darwin':
elif system == 'Darwin':
return 'mac'
else:
raise NotImplementedError('Porcupine is not supported on %s yet!' % x)
elif system == 'Linux' and machine.startswith('arm'):
return 'raspberrypi'

@staticmethod
def _machine():
x = platform.machine()
if x == 'x86_64' or x == 'i386':
return x
else:
raise NotImplementedError('Porcupine is not supported on %s yet!' % x)
raise NotImplementedError('Porcupine is not supported on %s/%s yet!' % (system, machine))

@staticmethod
def _dylib_extension():
s = platform.system()
if s == 'Linux':
return 'so'

if s == 'Darwin':
return 'dylib'

raise NotImplementedError('Porcupine is not supported on %s yet!' % s)
def _library_path():
system = platform.system()
machine = platform.machine()

if system == 'Darwin':
return os.path.join(os.path.dirname(__file__), '../../lib/mac/%s/libpv_porcupine.dylib' % machine)
elif system == 'Linux':
if machine == 'x86_64' or machine == 'i386':
return os.path.join(os.path.dirname(__file__), '../../lib/linux/%s/libpv_porcupine.so' % machine)
elif machine.startswith('arm'):
return os.path.join(os.path.dirname(__file__), '../../lib/raspberry-pi/libpv_porcupine.so')

raise NotImplementedError('Porcupine is not supported on %s/%s yet!' % (system, machine))


if __name__ == '__main__':
Expand Down
40 changes: 12 additions & 28 deletions demo/python/porcupine_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,47 +137,31 @@ def show_audio_devices_info(cls):
pa.terminate()


def _system():
x = platform.system()
if x == 'Linux':
return 'linux'
elif x == 'Darwin':
return 'mac'
else:
raise NotImplementedError('Porcupine is not supported on %s yet!' % x)

def _default_library_path():
system = platform.system()
machine = platform.machine()

def _machine():
x = platform.machine()
if x == 'x86_64' or x == 'i386':
return x
else:
raise NotImplementedError('Porcupine is not supported on %s yet!' % x)
if system == 'Darwin':
return os.path.join(os.path.dirname(__file__), '../../lib/mac/%s/libpv_porcupine.dylib' % machine)
elif system == 'Linux':
if machine == 'x86_64' or machine == 'i386':
return os.path.join(os.path.dirname(__file__), '../../lib/linux/%s/libpv_porcupine.so' % machine)
elif machine.startswith('arm'):
return os.path.join(os.path.dirname(__file__), '../../lib/raspberry-pi/libpv_porcupine.so')


def _dynamic_library_extension():
x = _system()
if x == 'linux':
return 'so'
elif x == 'mac':
return 'dylib'
else:
raise NotImplementedError('Porcupine is not supported on %s yet!' % x)
raise NotImplementedError('Porcupine is not supported on %s/%s yet!' % (system, machine))


if __name__ == '__main__':
parser = argparse.ArgumentParser()

parser.add_argument('--keyword_file_path', help='absolute path to keyword file', type=str)

default_library_path = os.path.join(
os.path.dirname(__file__),
'../../lib/%s/%s/libpv_porcupine.%s' % (_system(), _machine(), _dynamic_library_extension()))
parser.add_argument(
'--library_path',
help="absolute path to Porcupine's dynamic library",
type=str,
default=default_library_path)
default=_default_library_path())

parser.add_argument(
'--model_file_path',
Expand Down

0 comments on commit 3264eaf

Please sign in to comment.