18 log = logging.getLogger(
'PPN')
19 log.setLevel(logging.WARNING)
23 if machine ==
'x86_64':
25 elif machine ==
'aarch64':
26 arch_info =
'-' + machine
27 elif machine
in [
'armv7l',
'armv6l']:
30 raise NotImplementedError(
"Unsupported CPU architecture: '%s'" % machine)
34 cpu_info = subprocess.check_output([
'cat',
'/proc/cpuinfo']).decode()
35 cpu_part_list = [x
for x
in cpu_info.split(
'\n')
if 'CPU part' in x]
36 cpu_part = cpu_part_list[0].split(
' ')[-1].lower()
37 except Exception
as error:
38 raise RuntimeError(
"Failed to identify the CPU with '%s'\nCPU info: %s" % (error, cpu_info))
40 if '0xb76' == cpu_part:
41 return 'arm11' + arch_info
42 elif '0xc07' == cpu_part:
43 return 'cortex-a7' + arch_info
44 elif '0xd03' == cpu_part:
45 return 'cortex-a53' + arch_info
46 elif '0xd07' == cpu_part:
47 return 'cortex-a57' + arch_info
48 elif '0xd08' == cpu_part:
49 return 'cortex-a72' + arch_info
50 elif '0xc08' == cpu_part:
51 return 'beaglebone' + arch_info
52 elif machine ==
'armv7l':
54 'WARNING: Please be advised that this device (CPU part = %s) is not officially supported by Picovoice. '
55 'Falling back to the armv6-based (Raspberry Pi Zero) library. This is not tested nor optimal.' % cpu_part)
58 raise NotImplementedError(
"Unsupported CPU: '%s'." % cpu_part)
62 pv_system = platform.system()
63 if pv_system
not in {
'Darwin',
'Linux',
'Windows'}:
64 raise ValueError(
"Unsupported system '%s'." % pv_system)
66 if pv_system ==
'Linux':
69 pv_machine = platform.machine()
71 return pv_system, pv_machine
76 _RASPBERRY_PI_MACHINES = {
'arm11',
'cortex-a7',
'cortex-a53',
'cortex-a72',
'cortex-a53-aarch64',
'cortex-a72-aarch64'}
77 _JETSON_MACHINES = {
'cortex-a57-aarch64'}
81 if _PV_SYSTEM ==
'Darwin':
82 if _PV_MACHINE ==
'x86_64':
83 return os.path.join(os.path.dirname(__file__), relative,
'lib/mac/x86_64/libpv_porcupine.dylib')
84 elif _PV_MACHINE ==
"arm64":
85 return os.path.join(os.path.dirname(__file__), relative,
'lib/mac/arm64/libpv_porcupine.dylib')
86 elif _PV_SYSTEM ==
'Linux':
87 if _PV_MACHINE ==
'x86_64':
88 return os.path.join(os.path.dirname(__file__), relative,
'lib/linux/x86_64/libpv_porcupine.so')
89 elif _PV_MACHINE
in _JETSON_MACHINES:
91 os.path.dirname(__file__),
93 'lib/jetson/%s/libpv_porcupine.so' % _PV_MACHINE)
94 elif _PV_MACHINE
in _RASPBERRY_PI_MACHINES:
96 os.path.dirname(__file__),
98 'lib/raspberry-pi/%s/libpv_porcupine.so' % _PV_MACHINE)
99 elif _PV_MACHINE ==
'beaglebone':
100 return os.path.join(os.path.dirname(__file__), relative,
'lib/beaglebone/libpv_porcupine.so')
101 elif _PV_SYSTEM ==
'Windows':
102 return os.path.join(os.path.dirname(__file__), relative,
'lib/windows/amd64/libpv_porcupine.dll')
104 raise NotImplementedError(
'Unsupported platform.')
108 return os.path.join(os.path.dirname(__file__), relative,
'lib/common/porcupine_params.pv')
112 if _PV_SYSTEM ==
'Darwin':
114 elif _PV_SYSTEM ==
'Linux':
115 if _PV_MACHINE ==
'x86_64':
117 elif _PV_MACHINE
in _JETSON_MACHINES:
119 elif _PV_MACHINE
in _RASPBERRY_PI_MACHINES:
120 return 'raspberry-pi'
121 elif _PV_MACHINE ==
'beaglebone':
123 elif _PV_SYSTEM ==
'Windows':
126 raise NotImplementedError(
'Unsupported platform')
130 keyword_files_dir = \
134 for x
in os.listdir(keyword_files_dir):
135 res[x.rsplit(
'_')[0]] = os.path.join(keyword_files_dir, x)