pvzebra 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pvzebra-1.0.0/MANIFEST.in +6 -0
- pvzebra-1.0.0/PKG-INFO +79 -0
- pvzebra-1.0.0/README.md +62 -0
- pvzebra-1.0.0/pvzebra/LICENSE +201 -0
- pvzebra-1.0.0/pvzebra/__init__.py +14 -0
- pvzebra-1.0.0/pvzebra/_factory.py +76 -0
- pvzebra-1.0.0/pvzebra/_util.py +82 -0
- pvzebra-1.0.0/pvzebra/_zebra.py +312 -0
- pvzebra-1.0.0/pvzebra/lib/linux/x86_64/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/mac/arm64/libpv_zebra.dylib +0 -0
- pvzebra-1.0.0/pvzebra/lib/mac/x86_64/libpv_zebra.dylib +0 -0
- pvzebra-1.0.0/pvzebra/lib/raspberry-pi/cortex-a53/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/raspberry-pi/cortex-a53-aarch64/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/raspberry-pi/cortex-a72/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/raspberry-pi/cortex-a72-aarch64/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/raspberry-pi/cortex-a76/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/raspberry-pi/cortex-a76-aarch64/libpv_zebra.so +0 -0
- pvzebra-1.0.0/pvzebra/lib/windows/amd64/libpv_zebra.dll +0 -0
- pvzebra-1.0.0/pvzebra/lib/windows/amd64/pv_ypu_impl_cuda_zebra.dll +0 -0
- pvzebra-1.0.0/pvzebra/lib/windows/arm64/libpv_zebra.dll +0 -0
- pvzebra-1.0.0/pvzebra.egg-info/PKG-INFO +79 -0
- pvzebra-1.0.0/pvzebra.egg-info/SOURCES.txt +24 -0
- pvzebra-1.0.0/pvzebra.egg-info/dependency_links.txt +1 -0
- pvzebra-1.0.0/pvzebra.egg-info/top_level.txt +1 -0
- pvzebra-1.0.0/setup.cfg +4 -0
- pvzebra-1.0.0/setup.py +64 -0
pvzebra-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pvzebra
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Zebra Translate
|
|
5
|
+
Home-page: https://github.com/Picovoice/zebra
|
|
6
|
+
Author: Picovoice
|
|
7
|
+
Author-email: hello@picovoice.ai
|
|
8
|
+
Keywords: Translation,Text Translation,Language Translation
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Zebra Binding for Python
|
|
19
|
+
|
|
20
|
+
## Zebra Translate
|
|
21
|
+
|
|
22
|
+
Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)
|
|
23
|
+
|
|
24
|
+
Zebra is a lightweight, on-device neural machine translation engine. Zebra is:
|
|
25
|
+
|
|
26
|
+
- Private; All processing runs locally.
|
|
27
|
+
- Cross-Platform:
|
|
28
|
+
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64)
|
|
29
|
+
- Raspberry Pi (3, 4, 5)
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
- Python 3.9+
|
|
34
|
+
- Runs on Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64), and Raspberry Pi (3, 4, 5).
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```console
|
|
39
|
+
pip3 install pvzebra
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## AccessKey
|
|
43
|
+
|
|
44
|
+
Zebra requires a valid Picovoice `AccessKey` at initialization. `AccessKey` acts as your credentials when using Zebra SDKs.
|
|
45
|
+
You can get your `AccessKey` for free. Make sure to keep your `AccessKey` secret.
|
|
46
|
+
Signup or Login to [Picovoice Console](https://console.picovoice.ai/) to get your `AccessKey`.
|
|
47
|
+
|
|
48
|
+
### Usage
|
|
49
|
+
|
|
50
|
+
Create an instance of the engine and translate some text:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import pvzebra
|
|
54
|
+
|
|
55
|
+
handle = pvzebra.create(access_key='${ACCESS_KEY}', model_path='${MODEL_PATH}')
|
|
56
|
+
|
|
57
|
+
translation = handle.translate('${TEXT}')
|
|
58
|
+
print(translation)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/), `${MODEL_PATH}` with
|
|
62
|
+
a supported translation model located [here](../../lib/common/) and `${TEXT}` with the text to translate.
|
|
63
|
+
Finally, when done be sure to explicitly release the resources using `handle.delete()`.
|
|
64
|
+
|
|
65
|
+
### Translation Models
|
|
66
|
+
|
|
67
|
+
Zebra translation models are located [here](../../lib/common/). The selected model decides the source and target translation languages.
|
|
68
|
+
|
|
69
|
+
The format of the model follows:
|
|
70
|
+
|
|
71
|
+
```console
|
|
72
|
+
zebra_params_${SOURCE}_${TARGET}.pv
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Where `${SOURCE}` is the language code of the source language and `${TARGET}` is the language code of the target language for the translation.
|
|
76
|
+
|
|
77
|
+
## Demos
|
|
78
|
+
|
|
79
|
+
[pvzebrademo](https://pypi.org/project/pvzebrademo/) provides command-line utilities for translating text using Zebra.
|
pvzebra-1.0.0/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Zebra Binding for Python
|
|
2
|
+
|
|
3
|
+
## Zebra Translate
|
|
4
|
+
|
|
5
|
+
Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)
|
|
6
|
+
|
|
7
|
+
Zebra is a lightweight, on-device neural machine translation engine. Zebra is:
|
|
8
|
+
|
|
9
|
+
- Private; All processing runs locally.
|
|
10
|
+
- Cross-Platform:
|
|
11
|
+
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64)
|
|
12
|
+
- Raspberry Pi (3, 4, 5)
|
|
13
|
+
|
|
14
|
+
## Compatibility
|
|
15
|
+
|
|
16
|
+
- Python 3.9+
|
|
17
|
+
- Runs on Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64), and Raspberry Pi (3, 4, 5).
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
pip3 install pvzebra
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## AccessKey
|
|
26
|
+
|
|
27
|
+
Zebra requires a valid Picovoice `AccessKey` at initialization. `AccessKey` acts as your credentials when using Zebra SDKs.
|
|
28
|
+
You can get your `AccessKey` for free. Make sure to keep your `AccessKey` secret.
|
|
29
|
+
Signup or Login to [Picovoice Console](https://console.picovoice.ai/) to get your `AccessKey`.
|
|
30
|
+
|
|
31
|
+
### Usage
|
|
32
|
+
|
|
33
|
+
Create an instance of the engine and translate some text:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import pvzebra
|
|
37
|
+
|
|
38
|
+
handle = pvzebra.create(access_key='${ACCESS_KEY}', model_path='${MODEL_PATH}')
|
|
39
|
+
|
|
40
|
+
translation = handle.translate('${TEXT}')
|
|
41
|
+
print(translation)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/), `${MODEL_PATH}` with
|
|
45
|
+
a supported translation model located [here](../../lib/common/) and `${TEXT}` with the text to translate.
|
|
46
|
+
Finally, when done be sure to explicitly release the resources using `handle.delete()`.
|
|
47
|
+
|
|
48
|
+
### Translation Models
|
|
49
|
+
|
|
50
|
+
Zebra translation models are located [here](../../lib/common/). The selected model decides the source and target translation languages.
|
|
51
|
+
|
|
52
|
+
The format of the model follows:
|
|
53
|
+
|
|
54
|
+
```console
|
|
55
|
+
zebra_params_${SOURCE}_${TARGET}.pv
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Where `${SOURCE}` is the language code of the source language and `${TARGET}` is the language code of the target language for the translation.
|
|
59
|
+
|
|
60
|
+
## Demos
|
|
61
|
+
|
|
62
|
+
[pvzebrademo](https://pypi.org/project/pvzebrademo/) provides command-line utilities for translating text using Zebra.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Picovoice Inc.
|
|
3
|
+
#
|
|
4
|
+
# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
5
|
+
# file accompanying this source.
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
8
|
+
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
9
|
+
# specific language governing permissions and limitations under the License.
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
from ._factory import *
|
|
13
|
+
from ._util import *
|
|
14
|
+
from ._zebra import *
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Picovoice Inc.
|
|
3
|
+
#
|
|
4
|
+
# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
5
|
+
# file accompanying this source.
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
8
|
+
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
9
|
+
# specific language governing permissions and limitations under the License.
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
from typing import (
|
|
13
|
+
Optional,
|
|
14
|
+
Sequence
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from ._util import default_library_path
|
|
18
|
+
|
|
19
|
+
from ._zebra import (
|
|
20
|
+
list_hardware_devices,
|
|
21
|
+
Zebra,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def create(
|
|
26
|
+
access_key: str,
|
|
27
|
+
model_path: Optional[str] = None,
|
|
28
|
+
device: Optional[str] = None,
|
|
29
|
+
library_path: Optional[str] = None) -> Zebra:
|
|
30
|
+
"""
|
|
31
|
+
Factory method for Zebra Translate engine.
|
|
32
|
+
|
|
33
|
+
:param access_key: AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
|
|
34
|
+
:param model_path: Absolute path to the file containing model parameters (`.pv`).
|
|
35
|
+
Sets the source and target translation languages.
|
|
36
|
+
:param device: String representation of the device (e.g., CPU or GPU) to use. If set to `best`, the most
|
|
37
|
+
suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device.
|
|
38
|
+
To select a specific GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index
|
|
39
|
+
of the target GPU. If set to `cpu`, the engine will run on the CPU with the default number of threads.
|
|
40
|
+
To specify the number of threads, set this argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}`
|
|
41
|
+
is the desired number of threads.
|
|
42
|
+
:param library_path: Absolute path to Zebra's dynamic library. If not set it will be set to the default location.
|
|
43
|
+
:return: An instance of Zebra translation engine.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
if device is None:
|
|
47
|
+
device = "best"
|
|
48
|
+
|
|
49
|
+
if library_path is None:
|
|
50
|
+
library_path = default_library_path()
|
|
51
|
+
|
|
52
|
+
return Zebra(
|
|
53
|
+
access_key=access_key,
|
|
54
|
+
model_path=model_path,
|
|
55
|
+
device=device,
|
|
56
|
+
library_path=library_path)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def available_devices(library_path: Optional[str] = None) -> Sequence[str]:
|
|
60
|
+
"""
|
|
61
|
+
Lists all available devices that Zebra can use for translation. Each entry in the list can be the `device` argument
|
|
62
|
+
of `.create` factory method or `Zebra` constructor.
|
|
63
|
+
:param library_path: Absolute path to Zebra's dynamic library. If not set it will be set to the default location.
|
|
64
|
+
:return: List of all available devices that Zebra can use for translation.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
if library_path is None:
|
|
68
|
+
library_path = default_library_path()
|
|
69
|
+
|
|
70
|
+
return list_hardware_devices(library_path=library_path)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
__all__ = [
|
|
74
|
+
"available_devices",
|
|
75
|
+
"create"
|
|
76
|
+
]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Picovoice Inc.
|
|
3
|
+
#
|
|
4
|
+
# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
5
|
+
# file accompanying this source.
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
8
|
+
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
9
|
+
# specific language governing permissions and limitations under the License.
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import platform
|
|
14
|
+
import subprocess
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _is_64bit():
|
|
18
|
+
return "64bit" in platform.architecture()[0]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _linux_machine() -> str:
|
|
22
|
+
machine = platform.machine()
|
|
23
|
+
if machine == "x86_64":
|
|
24
|
+
return machine
|
|
25
|
+
elif machine in ["aarch64", "armv7l"]:
|
|
26
|
+
arch_info = ("-" + machine) if _is_64bit() else ""
|
|
27
|
+
else:
|
|
28
|
+
raise NotImplementedError("Unsupported CPU architecture: `%s`" % machine)
|
|
29
|
+
|
|
30
|
+
cpu_info = ""
|
|
31
|
+
try:
|
|
32
|
+
cpu_info = subprocess.check_output(["cat", "/proc/cpuinfo"]).decode("utf-8")
|
|
33
|
+
cpu_part_list = [x for x in cpu_info.split("\n") if "CPU part" in x]
|
|
34
|
+
cpu_part = cpu_part_list[0].split(" ")[-1].lower()
|
|
35
|
+
except Exception as e:
|
|
36
|
+
raise RuntimeError("Failed to identify the CPU with `%s`\nCPU info: `%s`" % (e, cpu_info))
|
|
37
|
+
|
|
38
|
+
if "0xd03" == cpu_part:
|
|
39
|
+
return "cortex-a53" + arch_info
|
|
40
|
+
elif "0xd07" == cpu_part:
|
|
41
|
+
return "cortex-a57" + arch_info
|
|
42
|
+
elif "0xd08" == cpu_part:
|
|
43
|
+
return "cortex-a72" + arch_info
|
|
44
|
+
elif "0xd0b" == cpu_part:
|
|
45
|
+
return "cortex-a76" + arch_info
|
|
46
|
+
else:
|
|
47
|
+
raise NotImplementedError("Unsupported CPU: `%s`." % cpu_part)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
_RASPBERRY_PI_MACHINES = {
|
|
51
|
+
"cortex-a53",
|
|
52
|
+
"cortex-a72",
|
|
53
|
+
"cortex-a76",
|
|
54
|
+
"cortex-a53-aarch64",
|
|
55
|
+
"cortex-a72-aarch64",
|
|
56
|
+
"cortex-a76-aarch64"}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def default_library_path(relative: str = "") -> str:
|
|
60
|
+
if platform.system() == "Darwin":
|
|
61
|
+
if platform.machine() == "x86_64":
|
|
62
|
+
return os.path.join(os.path.dirname(__file__), relative, "lib/mac/x86_64/libpv_zebra.dylib")
|
|
63
|
+
elif platform.machine() == "arm64":
|
|
64
|
+
return os.path.join(os.path.dirname(__file__), relative, "lib/mac/arm64/libpv_zebra.dylib")
|
|
65
|
+
elif platform.system() == "Linux":
|
|
66
|
+
linux_machine = _linux_machine()
|
|
67
|
+
if linux_machine == "x86_64":
|
|
68
|
+
return os.path.join(os.path.dirname(__file__), relative, "lib/linux/x86_64/libpv_zebra.so")
|
|
69
|
+
elif linux_machine in _RASPBERRY_PI_MACHINES:
|
|
70
|
+
return os.path.join(
|
|
71
|
+
os.path.dirname(__file__), relative, "lib/raspberry-pi/%s/libpv_zebra.so" % linux_machine
|
|
72
|
+
)
|
|
73
|
+
elif platform.system() == "Windows":
|
|
74
|
+
if platform.machine().lower() == 'amd64':
|
|
75
|
+
return os.path.join(os.path.dirname(__file__), relative, "lib", "windows", "amd64", "libpv_zebra.dll")
|
|
76
|
+
elif platform.machine().lower() == 'arm64':
|
|
77
|
+
return os.path.join(os.path.dirname(__file__), relative, "lib", "windows", "arm64", "libpv_zebra.dll")
|
|
78
|
+
|
|
79
|
+
raise NotImplementedError("Unsupported platform.")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
__all__ = ["default_library_path"]
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
from collections import namedtuple
|
|
4
|
+
from ctypes import *
|
|
5
|
+
from enum import Enum
|
|
6
|
+
from typing import *
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ZebraError(Exception):
|
|
10
|
+
def __init__(self, message: str = "", message_stack: Sequence[str] = None):
|
|
11
|
+
super().__init__(message)
|
|
12
|
+
|
|
13
|
+
self._message = message
|
|
14
|
+
self._message_stack = list() if message_stack is None else message_stack
|
|
15
|
+
|
|
16
|
+
def __str__(self):
|
|
17
|
+
message = self._message
|
|
18
|
+
if len(self._message_stack) > 0:
|
|
19
|
+
message += ":"
|
|
20
|
+
for i in range(len(self._message_stack)):
|
|
21
|
+
message += "\n [%d] %s" % (i, self._message_stack[i])
|
|
22
|
+
return message
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def message(self) -> str:
|
|
26
|
+
return self._message
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def message_stack(self) -> Sequence[str]:
|
|
30
|
+
return self._message_stack
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ZebraMemoryError(ZebraError):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ZebraIOError(ZebraError):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ZebraInvalidArgumentError(ZebraError):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ZebraStopIterationError(ZebraError):
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ZebraKeyError(ZebraError):
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class ZebraInvalidStateError(ZebraError):
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ZebraRuntimeError(ZebraError):
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ZebraActivationError(ZebraError):
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ZebraActivationLimitError(ZebraError):
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class ZebraActivationThrottledError(ZebraError):
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ZebraActivationRefusedError(ZebraError):
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class Zebra(object):
|
|
78
|
+
"""
|
|
79
|
+
Python binding for Zebra Translate engine.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
class PicovoiceStatuses(Enum):
|
|
83
|
+
SUCCESS = 0
|
|
84
|
+
OUT_OF_MEMORY = 1
|
|
85
|
+
IO_ERROR = 2
|
|
86
|
+
INVALID_ARGUMENT = 3
|
|
87
|
+
STOP_ITERATION = 4
|
|
88
|
+
KEY_ERROR = 5
|
|
89
|
+
INVALID_STATE = 6
|
|
90
|
+
RUNTIME_ERROR = 7
|
|
91
|
+
ACTIVATION_ERROR = 8
|
|
92
|
+
ACTIVATION_LIMIT_REACHED = 9
|
|
93
|
+
ACTIVATION_THROTTLED = 10
|
|
94
|
+
ACTIVATION_REFUSED = 11
|
|
95
|
+
|
|
96
|
+
_PICOVOICE_STATUS_TO_EXCEPTION = {
|
|
97
|
+
PicovoiceStatuses.OUT_OF_MEMORY: ZebraMemoryError,
|
|
98
|
+
PicovoiceStatuses.IO_ERROR: ZebraIOError,
|
|
99
|
+
PicovoiceStatuses.INVALID_ARGUMENT: ZebraInvalidArgumentError,
|
|
100
|
+
PicovoiceStatuses.STOP_ITERATION: ZebraStopIterationError,
|
|
101
|
+
PicovoiceStatuses.KEY_ERROR: ZebraKeyError,
|
|
102
|
+
PicovoiceStatuses.INVALID_STATE: ZebraInvalidStateError,
|
|
103
|
+
PicovoiceStatuses.RUNTIME_ERROR: ZebraRuntimeError,
|
|
104
|
+
PicovoiceStatuses.ACTIVATION_ERROR: ZebraActivationError,
|
|
105
|
+
PicovoiceStatuses.ACTIVATION_LIMIT_REACHED: ZebraActivationLimitError,
|
|
106
|
+
PicovoiceStatuses.ACTIVATION_THROTTLED: ZebraActivationThrottledError,
|
|
107
|
+
PicovoiceStatuses.ACTIVATION_REFUSED: ZebraActivationRefusedError,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class CZebra(Structure):
|
|
111
|
+
pass
|
|
112
|
+
|
|
113
|
+
def __init__(self, access_key: str, model_path: str, device: str, library_path: str) -> None:
|
|
114
|
+
"""
|
|
115
|
+
Constructor.
|
|
116
|
+
|
|
117
|
+
:param access_key: AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
|
|
118
|
+
:param model_path: Absolute path to the file containing model parameters (`.pv`).
|
|
119
|
+
Sets the source and target translation languages.
|
|
120
|
+
:param device: String representation of the device (e.g., CPU or GPU) to use. If set to `best`, the most
|
|
121
|
+
suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device.
|
|
122
|
+
To select a specific GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index
|
|
123
|
+
of the target GPU. If set to `cpu`, the engine will run on the CPU with the default number of threads.
|
|
124
|
+
To specify the number of threads, set this argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}`
|
|
125
|
+
is the desired number of threads.
|
|
126
|
+
:param library_path: Absolute path to Zebra's dynamic library.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
if not isinstance(access_key, str) or len(access_key) == 0:
|
|
130
|
+
raise ZebraInvalidArgumentError("`access_key` should be a non-empty string.")
|
|
131
|
+
|
|
132
|
+
if not isinstance(model_path, str) or len(model_path) == 0:
|
|
133
|
+
raise ZebraInvalidArgumentError("`model_path` should be a non-empty string.")
|
|
134
|
+
|
|
135
|
+
if not os.path.exists(model_path):
|
|
136
|
+
raise ZebraIOError("Could not find model file at `%s`." % model_path)
|
|
137
|
+
|
|
138
|
+
if not isinstance(device, str) or len(device) == 0:
|
|
139
|
+
raise ZebraInvalidArgumentError("`device` should be a non-empty string.")
|
|
140
|
+
|
|
141
|
+
if not os.path.exists(library_path):
|
|
142
|
+
raise ZebraIOError("Could not find Zebra's dynamic library at `%s`." % library_path)
|
|
143
|
+
|
|
144
|
+
library = cdll.LoadLibrary(library_path)
|
|
145
|
+
|
|
146
|
+
set_sdk_func = library.pv_set_sdk
|
|
147
|
+
set_sdk_func.argtypes = [c_char_p]
|
|
148
|
+
set_sdk_func.restype = None
|
|
149
|
+
|
|
150
|
+
set_sdk_func("python".encode("utf-8"))
|
|
151
|
+
|
|
152
|
+
self._get_error_stack_func = library.pv_get_error_stack
|
|
153
|
+
self._get_error_stack_func.argtypes = [POINTER(POINTER(c_char_p)), POINTER(c_int)]
|
|
154
|
+
self._get_error_stack_func.restype = self.PicovoiceStatuses
|
|
155
|
+
|
|
156
|
+
self._free_error_stack_func = library.pv_free_error_stack
|
|
157
|
+
self._free_error_stack_func.argtypes = [POINTER(c_char_p)]
|
|
158
|
+
self._free_error_stack_func.restype = None
|
|
159
|
+
|
|
160
|
+
init_func = library.pv_zebra_init
|
|
161
|
+
init_func.argtypes = [c_char_p, c_char_p, c_char_p, POINTER(POINTER(self.CZebra))]
|
|
162
|
+
init_func.restype = self.PicovoiceStatuses
|
|
163
|
+
|
|
164
|
+
self._handle = POINTER(self.CZebra)()
|
|
165
|
+
|
|
166
|
+
status = init_func(
|
|
167
|
+
access_key.encode(),
|
|
168
|
+
model_path.encode(),
|
|
169
|
+
device.encode(),
|
|
170
|
+
byref(self._handle))
|
|
171
|
+
if status is not self.PicovoiceStatuses.SUCCESS:
|
|
172
|
+
raise self._PICOVOICE_STATUS_TO_EXCEPTION[status](
|
|
173
|
+
message="Initialization failed", message_stack=self._get_error_stack()
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
max_character_limit_func = library.pv_zebra_max_character_limit
|
|
177
|
+
max_character_limit_func.argtypes = [POINTER(self.CZebra), POINTER(c_int32)]
|
|
178
|
+
max_character_limit_func.restype = self.PicovoiceStatuses
|
|
179
|
+
|
|
180
|
+
c_max_character_limit = c_int32()
|
|
181
|
+
status = max_character_limit_func(self._handle, byref(c_max_character_limit))
|
|
182
|
+
if status is not self.PicovoiceStatuses.SUCCESS:
|
|
183
|
+
raise self._PICOVOICE_STATUS_TO_EXCEPTION[status](
|
|
184
|
+
message="Failed to get max character limit", message_stack=self._get_error_stack()
|
|
185
|
+
)
|
|
186
|
+
self._max_character_limit = c_max_character_limit.value
|
|
187
|
+
|
|
188
|
+
self._delete_func = library.pv_zebra_delete
|
|
189
|
+
self._delete_func.argtypes = [POINTER(self.CZebra)]
|
|
190
|
+
self._delete_func.restype = None
|
|
191
|
+
|
|
192
|
+
self._translate_func = library.pv_zebra_translate
|
|
193
|
+
self._translate_func.argtypes = [
|
|
194
|
+
POINTER(self.CZebra),
|
|
195
|
+
c_char_p,
|
|
196
|
+
POINTER(c_char_p),
|
|
197
|
+
]
|
|
198
|
+
self._translate_func.restype = self.PicovoiceStatuses
|
|
199
|
+
|
|
200
|
+
self._translation_delete_func = library.pv_zebra_translation_delete
|
|
201
|
+
self._translation_delete_func.argtypes = [POINTER(self.CZebra), c_char_p]
|
|
202
|
+
self._translation_delete_func.restype = None
|
|
203
|
+
|
|
204
|
+
version_func = library.pv_zebra_version
|
|
205
|
+
version_func.argtypes = []
|
|
206
|
+
version_func.restype = c_char_p
|
|
207
|
+
self._version = version_func().decode("utf-8")
|
|
208
|
+
|
|
209
|
+
def translate(self, text: str) -> str:
|
|
210
|
+
"""
|
|
211
|
+
Translates text. The maximum number of characters that can be translated at once
|
|
212
|
+
is given by `.max_character_limit`.
|
|
213
|
+
|
|
214
|
+
:param text: Text to translate.
|
|
215
|
+
:return: Translated text.
|
|
216
|
+
"""
|
|
217
|
+
|
|
218
|
+
if len(text) == 0:
|
|
219
|
+
raise ZebraInvalidArgumentError("Text cannot be empty.")
|
|
220
|
+
|
|
221
|
+
if len(text) > self.max_character_limit:
|
|
222
|
+
raise ZebraInvalidArgumentError("Maximum character limit exceeded.")
|
|
223
|
+
|
|
224
|
+
c_translation = c_char_p()
|
|
225
|
+
status = self._translate_func(self._handle, text.encode(), byref(c_translation))
|
|
226
|
+
if status is not self.PicovoiceStatuses.SUCCESS:
|
|
227
|
+
raise self._PICOVOICE_STATUS_TO_EXCEPTION[status](
|
|
228
|
+
message="Translate failed", message_stack=self._get_error_stack()
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
translation = c_translation.value.decode()
|
|
232
|
+
self._translation_delete_func(self._handle, c_translation)
|
|
233
|
+
|
|
234
|
+
return translation
|
|
235
|
+
|
|
236
|
+
def delete(self) -> None:
|
|
237
|
+
"""Releases resources acquired by Zebra."""
|
|
238
|
+
|
|
239
|
+
self._delete_func(self._handle)
|
|
240
|
+
|
|
241
|
+
@property
|
|
242
|
+
def version(self) -> str:
|
|
243
|
+
"""Version."""
|
|
244
|
+
|
|
245
|
+
return self._version
|
|
246
|
+
|
|
247
|
+
@property
|
|
248
|
+
def max_character_limit(self) -> int:
|
|
249
|
+
"""Gets the maximum number of characters that can be translated at once by `.translate`."""
|
|
250
|
+
|
|
251
|
+
return self._max_character_limit
|
|
252
|
+
|
|
253
|
+
def _get_error_stack(self) -> Sequence[str]:
|
|
254
|
+
message_stack_ref = POINTER(c_char_p)()
|
|
255
|
+
message_stack_depth = c_int()
|
|
256
|
+
status = self._get_error_stack_func(byref(message_stack_ref), byref(message_stack_depth))
|
|
257
|
+
if status is not self.PicovoiceStatuses.SUCCESS:
|
|
258
|
+
raise self._PICOVOICE_STATUS_TO_EXCEPTION[status](message="Unable to get Zebra error state")
|
|
259
|
+
|
|
260
|
+
message_stack = list()
|
|
261
|
+
for i in range(message_stack_depth.value):
|
|
262
|
+
message_stack.append(message_stack_ref[i].decode("utf-8"))
|
|
263
|
+
|
|
264
|
+
self._free_error_stack_func(message_stack_ref)
|
|
265
|
+
|
|
266
|
+
return message_stack
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def list_hardware_devices(library_path: str) -> Sequence[str]:
|
|
270
|
+
dll_dir_obj = None
|
|
271
|
+
if hasattr(os, "add_dll_directory"):
|
|
272
|
+
dll_dir_obj = os.add_dll_directory(os.path.dirname(library_path))
|
|
273
|
+
|
|
274
|
+
library = cdll.LoadLibrary(library_path)
|
|
275
|
+
|
|
276
|
+
if dll_dir_obj is not None:
|
|
277
|
+
dll_dir_obj.close()
|
|
278
|
+
|
|
279
|
+
list_hardware_devices_func = library.pv_zebra_list_hardware_devices
|
|
280
|
+
list_hardware_devices_func.argtypes = [POINTER(POINTER(c_char_p)), POINTER(c_int32)]
|
|
281
|
+
list_hardware_devices_func.restype = Zebra.PicovoiceStatuses
|
|
282
|
+
c_hardware_devices = POINTER(c_char_p)()
|
|
283
|
+
c_num_hardware_devices = c_int32()
|
|
284
|
+
status = list_hardware_devices_func(byref(c_hardware_devices), byref(c_num_hardware_devices))
|
|
285
|
+
if status is not Zebra.PicovoiceStatuses.SUCCESS:
|
|
286
|
+
raise _PICOVOICE_STATUS_TO_EXCEPTION[status](message='`pv_zebra_list_hardware_devices` failed.')
|
|
287
|
+
res = [c_hardware_devices[i].decode() for i in range(c_num_hardware_devices.value)]
|
|
288
|
+
|
|
289
|
+
free_hardware_devices_func = library.pv_zebra_free_hardware_devices
|
|
290
|
+
free_hardware_devices_func.argtypes = [POINTER(c_char_p), c_int32]
|
|
291
|
+
free_hardware_devices_func.restype = None
|
|
292
|
+
free_hardware_devices_func(c_hardware_devices, c_num_hardware_devices.value)
|
|
293
|
+
|
|
294
|
+
return res
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
__all__ = [
|
|
298
|
+
'list_hardware_devices',
|
|
299
|
+
"Zebra",
|
|
300
|
+
"ZebraActivationError",
|
|
301
|
+
"ZebraActivationLimitError",
|
|
302
|
+
"ZebraActivationRefusedError",
|
|
303
|
+
"ZebraActivationThrottledError",
|
|
304
|
+
"ZebraError",
|
|
305
|
+
"ZebraIOError",
|
|
306
|
+
"ZebraInvalidArgumentError",
|
|
307
|
+
"ZebraInvalidStateError",
|
|
308
|
+
"ZebraKeyError",
|
|
309
|
+
"ZebraMemoryError",
|
|
310
|
+
"ZebraRuntimeError",
|
|
311
|
+
"ZebraStopIterationError"
|
|
312
|
+
]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pvzebra
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Zebra Translate
|
|
5
|
+
Home-page: https://github.com/Picovoice/zebra
|
|
6
|
+
Author: Picovoice
|
|
7
|
+
Author-email: hello@picovoice.ai
|
|
8
|
+
Keywords: Translation,Text Translation,Language Translation
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Zebra Binding for Python
|
|
19
|
+
|
|
20
|
+
## Zebra Translate
|
|
21
|
+
|
|
22
|
+
Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)
|
|
23
|
+
|
|
24
|
+
Zebra is a lightweight, on-device neural machine translation engine. Zebra is:
|
|
25
|
+
|
|
26
|
+
- Private; All processing runs locally.
|
|
27
|
+
- Cross-Platform:
|
|
28
|
+
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64)
|
|
29
|
+
- Raspberry Pi (3, 4, 5)
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
- Python 3.9+
|
|
34
|
+
- Runs on Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64), and Raspberry Pi (3, 4, 5).
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```console
|
|
39
|
+
pip3 install pvzebra
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## AccessKey
|
|
43
|
+
|
|
44
|
+
Zebra requires a valid Picovoice `AccessKey` at initialization. `AccessKey` acts as your credentials when using Zebra SDKs.
|
|
45
|
+
You can get your `AccessKey` for free. Make sure to keep your `AccessKey` secret.
|
|
46
|
+
Signup or Login to [Picovoice Console](https://console.picovoice.ai/) to get your `AccessKey`.
|
|
47
|
+
|
|
48
|
+
### Usage
|
|
49
|
+
|
|
50
|
+
Create an instance of the engine and translate some text:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import pvzebra
|
|
54
|
+
|
|
55
|
+
handle = pvzebra.create(access_key='${ACCESS_KEY}', model_path='${MODEL_PATH}')
|
|
56
|
+
|
|
57
|
+
translation = handle.translate('${TEXT}')
|
|
58
|
+
print(translation)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/), `${MODEL_PATH}` with
|
|
62
|
+
a supported translation model located [here](../../lib/common/) and `${TEXT}` with the text to translate.
|
|
63
|
+
Finally, when done be sure to explicitly release the resources using `handle.delete()`.
|
|
64
|
+
|
|
65
|
+
### Translation Models
|
|
66
|
+
|
|
67
|
+
Zebra translation models are located [here](../../lib/common/). The selected model decides the source and target translation languages.
|
|
68
|
+
|
|
69
|
+
The format of the model follows:
|
|
70
|
+
|
|
71
|
+
```console
|
|
72
|
+
zebra_params_${SOURCE}_${TARGET}.pv
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Where `${SOURCE}` is the language code of the source language and `${TARGET}` is the language code of the target language for the translation.
|
|
76
|
+
|
|
77
|
+
## Demos
|
|
78
|
+
|
|
79
|
+
[pvzebrademo](https://pypi.org/project/pvzebrademo/) provides command-line utilities for translating text using Zebra.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
pvzebra/LICENSE
|
|
5
|
+
pvzebra/__init__.py
|
|
6
|
+
pvzebra/_factory.py
|
|
7
|
+
pvzebra/_util.py
|
|
8
|
+
pvzebra/_zebra.py
|
|
9
|
+
pvzebra.egg-info/PKG-INFO
|
|
10
|
+
pvzebra.egg-info/SOURCES.txt
|
|
11
|
+
pvzebra.egg-info/dependency_links.txt
|
|
12
|
+
pvzebra.egg-info/top_level.txt
|
|
13
|
+
pvzebra/lib/linux/x86_64/libpv_zebra.so
|
|
14
|
+
pvzebra/lib/mac/arm64/libpv_zebra.dylib
|
|
15
|
+
pvzebra/lib/mac/x86_64/libpv_zebra.dylib
|
|
16
|
+
pvzebra/lib/raspberry-pi/cortex-a53/libpv_zebra.so
|
|
17
|
+
pvzebra/lib/raspberry-pi/cortex-a53-aarch64/libpv_zebra.so
|
|
18
|
+
pvzebra/lib/raspberry-pi/cortex-a72/libpv_zebra.so
|
|
19
|
+
pvzebra/lib/raspberry-pi/cortex-a72-aarch64/libpv_zebra.so
|
|
20
|
+
pvzebra/lib/raspberry-pi/cortex-a76/libpv_zebra.so
|
|
21
|
+
pvzebra/lib/raspberry-pi/cortex-a76-aarch64/libpv_zebra.so
|
|
22
|
+
pvzebra/lib/windows/amd64/libpv_zebra.dll
|
|
23
|
+
pvzebra/lib/windows/amd64/pv_ypu_impl_cuda_zebra.dll
|
|
24
|
+
pvzebra/lib/windows/arm64/libpv_zebra.dll
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pvzebra
|
pvzebra-1.0.0/setup.cfg
ADDED
pvzebra-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Picovoice Inc.
|
|
3
|
+
#
|
|
4
|
+
# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
5
|
+
# file accompanying this source.
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
8
|
+
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
9
|
+
# specific language governing permissions and limitations under the License.
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import shutil
|
|
14
|
+
|
|
15
|
+
import setuptools
|
|
16
|
+
|
|
17
|
+
INCLUDE_FILES = ('../../LICENSE', '__init__.py', '_factory.py', '_zebra.py', '_util.py')
|
|
18
|
+
INCLUDE_LIBS = ('linux', 'mac', 'raspberry-pi', 'windows')
|
|
19
|
+
os.system('git clean -dfx')
|
|
20
|
+
|
|
21
|
+
package_folder = os.path.join(os.path.dirname(__file__), 'pvzebra')
|
|
22
|
+
os.mkdir(package_folder)
|
|
23
|
+
manifest_in = ""
|
|
24
|
+
|
|
25
|
+
for rel_path in INCLUDE_FILES:
|
|
26
|
+
shutil.copy(os.path.join(os.path.dirname(__file__), rel_path), package_folder)
|
|
27
|
+
manifest_in += "include pvzebra/%s\n" % os.path.basename(rel_path)
|
|
28
|
+
|
|
29
|
+
os.mkdir(os.path.join(package_folder, 'lib'))
|
|
30
|
+
for platform in INCLUDE_LIBS:
|
|
31
|
+
shutil.copytree(
|
|
32
|
+
os.path.join(os.path.dirname(__file__), '../../lib', platform),
|
|
33
|
+
os.path.join(package_folder, 'lib', platform))
|
|
34
|
+
|
|
35
|
+
manifest_in += "recursive-include pvzebra/lib *\n"
|
|
36
|
+
|
|
37
|
+
with open(os.path.join(os.path.dirname(__file__), 'MANIFEST.in'), 'w') as f:
|
|
38
|
+
f.write(manifest_in)
|
|
39
|
+
|
|
40
|
+
with open(os.path.join(os.path.dirname(__file__), 'README.md'), 'r') as f:
|
|
41
|
+
long_description = f.read()
|
|
42
|
+
|
|
43
|
+
setuptools.setup(
|
|
44
|
+
name="pvzebra",
|
|
45
|
+
version="1.0.0",
|
|
46
|
+
author="Picovoice",
|
|
47
|
+
author_email="hello@picovoice.ai",
|
|
48
|
+
description="Zebra Translate",
|
|
49
|
+
long_description=long_description,
|
|
50
|
+
long_description_content_type="text/markdown",
|
|
51
|
+
url="https://github.com/Picovoice/zebra",
|
|
52
|
+
packages=["pvzebra"],
|
|
53
|
+
include_package_data=True,
|
|
54
|
+
classifiers=[
|
|
55
|
+
"Development Status :: 5 - Production/Stable",
|
|
56
|
+
"Intended Audience :: Developers",
|
|
57
|
+
"License :: OSI Approved :: Apache Software License",
|
|
58
|
+
"Operating System :: OS Independent",
|
|
59
|
+
"Programming Language :: Python :: 3",
|
|
60
|
+
"Topic :: Text Processing :: Linguistic",
|
|
61
|
+
],
|
|
62
|
+
python_requires=">=3.9",
|
|
63
|
+
keywords="Translation, Text Translation, Language Translation",
|
|
64
|
+
)
|