abr-sdk 0.1.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.
@@ -0,0 +1,28 @@
1
+ <!-- Automatically generated by abr-bones, do not edit this file directly -->
2
+
3
+ # ABR SDK license
4
+
5
+ Copyright (c) 2026-2026 Applied Brain Research
6
+
7
+ All information contained herein is and remains the property of
8
+ Applied Brain Research. The intellectual and technical concepts contained
9
+ herein are proprietary to Applied Brain Research and may be covered by U.S.
10
+ and Foreign Patents, patents in process, and are protected by trade secret
11
+ or copyright law. Dissemination of this information or reproduction of this
12
+ material is strictly forbidden unless prior written permission is obtained
13
+ from Applied Brain Research. Access to the source code contained herein is
14
+ hereby forbidden to anyone except current Applied Brain Research employees,
15
+ contractors or other outside parties that have executed Confidentiality
16
+ and/or Non-disclosure agreements explicitly covering such access.
17
+
18
+ The copyright notice above does not evidence any actual or intended
19
+ publication or disclosure of this source code, which includes information
20
+ that is confidential and/or proprietary, and is a trade secret, of
21
+ Applied Brain Research. ANY REPRODUCTION, MODIFICATION, DISTRIBUTION,
22
+ PUBLIC PERFORMANCE, OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS
23
+ SOURCE CODE WITHOUT THE EXPRESS WRITTEN CONSENT OF APPLIED BRAIN RESEARCH
24
+ IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE LAWS AND
25
+ INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF THIS SOURCE
26
+ CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS
27
+ TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE,
28
+ USE, OR SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
@@ -0,0 +1 @@
1
+ prune tests
abr_sdk-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: abr-sdk
3
+ Version: 0.1.0
4
+ Summary: Python bindings for ABR's on-device speech SDK (speech-to-text and text-to-speech)
5
+ Author-email: Applied Brain Research <info@appliedbrainresearch.com>
6
+ License-Expression: LicenseRef-Proprietary-ABR
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Intended Audience :: Developers
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.md
12
+ Dynamic: license-file
13
+
14
+ # ABR SDK
15
+
16
+ Python bindings for the Applied Brain Research on-device speech SDK:
17
+ low-latency automatic speech recognition (ASR) and text-to-speech (TTS)
18
+ that run entirely on the local device, with no network calls at inference
19
+ time.
20
+
21
+ This package does not contain the speech models or the native engine;
22
+ it loads an ABR SDK application package that you obtain separately
23
+ and drives it through a small, Pythonic API.
24
+
25
+ Full documentation: <https://docs.appliedbrainresearch.com/sdk>
26
+ Customer portal with application packages: <https://dev.appliedbrainresearch.com>
27
+
28
+ ## Installation
29
+
30
+ Use any of the following to install `abr-sdk` and incorporate it into your
31
+ project.
32
+
33
+ ```bash
34
+ pip install abr-sdk
35
+ uv add abr-sdk
36
+ ```
37
+
38
+ The package is dependency-free and supports Python 3.10+. To run it you also
39
+ need an ABR SDK application package for your platform and a license, both
40
+ provided by Applied Brain Research.
41
+
42
+ ## Quickstart
43
+
44
+ Activate the library once per device. This is the only step that needs
45
+ network access; inference is fully offline:
46
+
47
+ ```bash
48
+ abr-sdk activate path/to/library.so --key-file license.key
49
+ ```
50
+
51
+ Recognize speech from 16 kHz mono signed-16-bit little-endian PCM. A chunk may
52
+ _replace_ trailing text, so apply each one to a running buffer:
53
+
54
+ ```python
55
+ from abr_sdk.asr import Asr, AsrChunk
56
+
57
+ buf = bytearray()
58
+
59
+ def on_chunk(chunk: AsrChunk) -> None:
60
+ chunk.update(buf) # apply correction in place
61
+ print(buf.decode("utf-8"))
62
+
63
+ with Asr("path/to/libasr.so") as asr:
64
+ while (data := audio_source.read(3200)): # ~100 ms of PCM
65
+ asr.push(data, on_chunk=on_chunk)
66
+ asr.wait_for_completion() # flush and wait for final chunks
67
+ ```
68
+
69
+ Synthesize speech to 16 kHz mono signed-16-bit little-endian PCM:
70
+
71
+ ```python
72
+ from abr_sdk.tts import Tts
73
+
74
+ with Tts("path/to/libtts.so") as tts:
75
+ tts.push(b"Hello from Applied Brain Research.", on_pcm=audio_sink.write)
76
+ tts.wait_for_completion()
77
+ ```
78
+
79
+ See the [full documentation](https://docs.appliedbrainresearch.com/sdk) for
80
+ activation options, full end-to-end examples, and the complete API.
81
+
82
+ ## License
83
+
84
+ Proprietary. Copyright (c) Applied Brain Research.
85
+ Use of this package and the ABR SDK libraries it loads is governed by your
86
+ agreement with Applied Brain Research.
@@ -0,0 +1,73 @@
1
+ # ABR SDK
2
+
3
+ Python bindings for the Applied Brain Research on-device speech SDK:
4
+ low-latency automatic speech recognition (ASR) and text-to-speech (TTS)
5
+ that run entirely on the local device, with no network calls at inference
6
+ time.
7
+
8
+ This package does not contain the speech models or the native engine;
9
+ it loads an ABR SDK application package that you obtain separately
10
+ and drives it through a small, Pythonic API.
11
+
12
+ Full documentation: <https://docs.appliedbrainresearch.com/sdk>
13
+ Customer portal with application packages: <https://dev.appliedbrainresearch.com>
14
+
15
+ ## Installation
16
+
17
+ Use any of the following to install `abr-sdk` and incorporate it into your
18
+ project.
19
+
20
+ ```bash
21
+ pip install abr-sdk
22
+ uv add abr-sdk
23
+ ```
24
+
25
+ The package is dependency-free and supports Python 3.10+. To run it you also
26
+ need an ABR SDK application package for your platform and a license, both
27
+ provided by Applied Brain Research.
28
+
29
+ ## Quickstart
30
+
31
+ Activate the library once per device. This is the only step that needs
32
+ network access; inference is fully offline:
33
+
34
+ ```bash
35
+ abr-sdk activate path/to/library.so --key-file license.key
36
+ ```
37
+
38
+ Recognize speech from 16 kHz mono signed-16-bit little-endian PCM. A chunk may
39
+ _replace_ trailing text, so apply each one to a running buffer:
40
+
41
+ ```python
42
+ from abr_sdk.asr import Asr, AsrChunk
43
+
44
+ buf = bytearray()
45
+
46
+ def on_chunk(chunk: AsrChunk) -> None:
47
+ chunk.update(buf) # apply correction in place
48
+ print(buf.decode("utf-8"))
49
+
50
+ with Asr("path/to/libasr.so") as asr:
51
+ while (data := audio_source.read(3200)): # ~100 ms of PCM
52
+ asr.push(data, on_chunk=on_chunk)
53
+ asr.wait_for_completion() # flush and wait for final chunks
54
+ ```
55
+
56
+ Synthesize speech to 16 kHz mono signed-16-bit little-endian PCM:
57
+
58
+ ```python
59
+ from abr_sdk.tts import Tts
60
+
61
+ with Tts("path/to/libtts.so") as tts:
62
+ tts.push(b"Hello from Applied Brain Research.", on_pcm=audio_sink.write)
63
+ tts.wait_for_completion()
64
+ ```
65
+
66
+ See the [full documentation](https://docs.appliedbrainresearch.com/sdk) for
67
+ activation options, full end-to-end examples, and the complete API.
68
+
69
+ ## License
70
+
71
+ Proprietary. Copyright (c) Applied Brain Research.
72
+ Use of this package and the ABR SDK libraries it loads is governed by your
73
+ agreement with Applied Brain Research.
@@ -0,0 +1,37 @@
1
+ # (c) 2026 Applied Brain Research
2
+ #
3
+ # All information contained herein is and remains the property of Applied Brain
4
+ # Research. The intellectual and technical concepts contained herein are
5
+ # proprietary to Applied Brain Research and may be covered by U.S. and Foreign
6
+ # Patents, patents in process, and are protected by trade secret or copyright
7
+ # law. Dissemination of this information or reproduction of this material is
8
+ # strictly forbidden unless prior written permission is obtained from Applied
9
+ # Brain Research. Access to the source code contained herein is hereby
10
+ # forbidden to anyone except current Applied Brain Research employees,
11
+ # contractors or other outside parties that have executed Confidentiality
12
+ # and/or Non-disclosure agreements explicitly covering such access.
13
+ #
14
+ # The copyright notice above does not evidence any actual or intended
15
+ # publication or disclosure of this source code, which includes information
16
+ # that is confidential and/or proprietary, and is a trade secret, of Applied
17
+ # Brain Research. ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC
18
+ # PERFORMANCE, OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT
19
+ # THE EXPRESS WRITTEN CONSENT OF APPLIED BRAIN RESEARCH IS STRICTLY PROHIBITED,
20
+ # AND IN VIOLATION OF APPLICABLE LAWS AND INTERNATIONAL TREATIES. THE RECEIPT
21
+ # OR POSSESSION OF THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY
22
+ # OR IMPLY ANY RIGHTS TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO
23
+ # MANUFACTURE, USE, OR SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
24
+
25
+ """Entry point for the Python ABR SDK."""
26
+
27
+ from abr_sdk.core import Application, Library
28
+ from abr_sdk.exceptions import AbrSdkError
29
+ from abr_sdk.version import __copyright__, __version__
30
+
31
+ __all__ = [
32
+ "AbrSdkError",
33
+ "Application",
34
+ "Library",
35
+ "__copyright__",
36
+ "__version__",
37
+ ]
@@ -0,0 +1,175 @@
1
+ # (c) 2026 Applied Brain Research
2
+ #
3
+ # All information contained herein is and remains the property of Applied Brain
4
+ # Research. The intellectual and technical concepts contained herein are
5
+ # proprietary to Applied Brain Research and may be covered by U.S. and Foreign
6
+ # Patents, patents in process, and are protected by trade secret or copyright
7
+ # law. Dissemination of this information or reproduction of this material is
8
+ # strictly forbidden unless prior written permission is obtained from Applied
9
+ # Brain Research. Access to the source code contained herein is hereby
10
+ # forbidden to anyone except current Applied Brain Research employees,
11
+ # contractors or other outside parties that have executed Confidentiality
12
+ # and/or Non-disclosure agreements explicitly covering such access.
13
+ #
14
+ # The copyright notice above does not evidence any actual or intended
15
+ # publication or disclosure of this source code, which includes information
16
+ # that is confidential and/or proprietary, and is a trade secret, of Applied
17
+ # Brain Research. ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC
18
+ # PERFORMANCE, OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT
19
+ # THE EXPRESS WRITTEN CONSENT OF APPLIED BRAIN RESEARCH IS STRICTLY PROHIBITED,
20
+ # AND IN VIOLATION OF APPLICABLE LAWS AND INTERNATIONAL TREATIES. THE RECEIPT
21
+ # OR POSSESSION OF THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY
22
+ # OR IMPLY ANY RIGHTS TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO
23
+ # MANUFACTURE, USE, OR SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
24
+
25
+ """
26
+ The ``abr-sdk`` command-line tool.
27
+
28
+ Currently exposes one subcommand, ``activate``, which reads this device's
29
+ fingerprint from the SDK library, trades a license key for a signed machine
30
+ file from Keygen, and writes it under the license directory.
31
+
32
+ The fingerprint is read from the library's ``fingerprint`` property, available
33
+ without instantiating a model, so activation needs no license to discover the
34
+ fingerprint it must bind to. Verifying and installing the downloaded envelope is
35
+ the SDK's job: ``abr_sdk.core.install_license`` hands it to the native
36
+ ``abr_app_activate_license``, which checks the signature and writes the
37
+ device-bound license and integrity files under the license directory.
38
+
39
+ Author: Trevor Bekolay (Applied Brain Research)
40
+ """
41
+
42
+ from __future__ import annotations
43
+
44
+ import argparse
45
+ import enum
46
+ import string
47
+ import sys
48
+ from pathlib import Path
49
+ from typing import Final
50
+
51
+ from abr_sdk.cabi import AbrSdkCAbiError, Status
52
+ from abr_sdk.core import DEFAULT_LICENSE_DIR, Library, install_license
53
+ from abr_sdk.exceptions import AbrSdkError
54
+ from abr_sdk.keygen import ActivationError, Failure, KeygenClient
55
+
56
+
57
+ class ExitCode(enum.IntEnum):
58
+ """Process exit codes. The specific reason is in the stderr message."""
59
+
60
+ SUCCESS = 0
61
+ ERROR = 1
62
+ NETWORK = 2
63
+ LICENSE = 3
64
+
65
+
66
+ _EXIT_FOR_FAILURE: Final[dict[Failure, ExitCode]] = {
67
+ Failure.NETWORK: ExitCode.NETWORK,
68
+ Failure.LICENSE: ExitCode.LICENSE,
69
+ Failure.PROTOCOL: ExitCode.ERROR,
70
+ }
71
+
72
+
73
+ def build_parser() -> argparse.ArgumentParser:
74
+ """Construct the top-level ``abr-sdk`` parser with its subcommands."""
75
+ parser = argparse.ArgumentParser(
76
+ prog="abr-sdk", description="ABR SDK command-line tools."
77
+ )
78
+ sub = parser.add_subparsers(dest="command", required=True)
79
+
80
+ activate = sub.add_parser(
81
+ "activate", help="Activate this device's ABR license against Keygen."
82
+ )
83
+ activate.add_argument(
84
+ "library", type=Path, help="Path to the ABR SDK shared library (.so)."
85
+ )
86
+ key_group = activate.add_mutually_exclusive_group(required=True)
87
+ key_group.add_argument(
88
+ "--key", metavar="STRING", help="The ABR license key, as a string."
89
+ )
90
+ key_group.add_argument(
91
+ "--key-file",
92
+ type=Path,
93
+ metavar="FILE",
94
+ help="Path to a file containing the ABR license key (whitespace trimmed).",
95
+ )
96
+ activate.add_argument(
97
+ "--license-dir",
98
+ type=Path,
99
+ default=DEFAULT_LICENSE_DIR,
100
+ metavar="DIR",
101
+ help=f"Directory to write the license into (default: {DEFAULT_LICENSE_DIR}).",
102
+ )
103
+ activate.set_defaults(func=cmd_activate)
104
+ return parser
105
+
106
+
107
+ def is_valid_fingerprint(value: str) -> bool:
108
+ """Return True when *value* is exactly 64 hexadecimal characters."""
109
+ return len(value) == 64 and all(c in string.hexdigits for c in value)
110
+
111
+
112
+ def cmd_activate(args: argparse.Namespace) -> int:
113
+ """Read the device fingerprint from the library, then run activation."""
114
+ try:
115
+ key = _resolve_key(args)
116
+ except OSError as exc:
117
+ return _fail(ExitCode.ERROR, f"cannot read the key file {args.key_file}: {exc}")
118
+
119
+ try:
120
+ library = Library(args.library)
121
+ except (AbrSdkError, OSError) as exc:
122
+ return _fail(ExitCode.ERROR, f"cannot load the SDK library: {exc}")
123
+ try:
124
+ fingerprint = library.get_property("fingerprint")
125
+ except KeyError:
126
+ return _fail(ExitCode.ERROR, "SDK library exposes no 'fingerprint' property.")
127
+ if not isinstance(fingerprint, str) or not is_valid_fingerprint(fingerprint):
128
+ return _fail(ExitCode.ERROR, "device fingerprint from the library is invalid.")
129
+
130
+ client = KeygenClient(key)
131
+ return run_activation(client, library, fingerprint.lower(), args.license_dir)
132
+
133
+
134
+ def _resolve_key(args: argparse.Namespace) -> str:
135
+ """Return the license key from ``--key`` or the ``--key-file`` contents."""
136
+ if args.key_file is not None:
137
+ return args.key_file.read_text(encoding="utf-8").strip()
138
+ return args.key
139
+
140
+
141
+ def run_activation(
142
+ client: KeygenClient, library: Library, fingerprint: str, license_dir: Path
143
+ ) -> int:
144
+ """Download the license envelope from Keygen and install it via the SDK."""
145
+ try:
146
+ envelope = client.activate(fingerprint)
147
+ except ActivationError as exc:
148
+ return _fail(_EXIT_FOR_FAILURE[exc.kind], str(exc))
149
+
150
+ try:
151
+ install_license(library, envelope, license_dir=license_dir)
152
+ except AbrSdkCAbiError as exc:
153
+ code = ExitCode.LICENSE if exc.status == Status.ERR_LICENSE else ExitCode.ERROR
154
+ return _fail(code, f"could not install the license: {exc}")
155
+ except AbrSdkError as exc:
156
+ return _fail(ExitCode.ERROR, f"could not install the license: {exc}")
157
+
158
+ print(f"abr-sdk: activation succeeded; license installed in {license_dir}")
159
+ return ExitCode.SUCCESS
160
+
161
+
162
+ def _fail(code: ExitCode, message: str) -> int:
163
+ """Print a prefixed message to stderr and return *code*."""
164
+ print(f"abr-sdk: {message}", file=sys.stderr)
165
+ return code
166
+
167
+
168
+ def main(argv: list[str] | None = None) -> None:
169
+ """Parse arguments and dispatch to the selected subcommand."""
170
+ args = build_parser().parse_args(argv)
171
+ raise SystemExit(args.func(args))
172
+
173
+
174
+ if __name__ == "__main__":
175
+ main()