cogno-vox 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,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 2026 Sudoers AI
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,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: cogno-vox
3
+ Version: 0.1.0
4
+ Summary: Voice/audio I/O edge for the Cogno cognitive pipeline — speech-to-text (STT) in, text-to-speech (TTS) out, with provider-agnostic fallback chains
5
+ Author: Sudoers AI
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/sudoers-ai/cogno-vox
8
+ Project-URL: Repository, https://github.com/sudoers-ai/cogno-vox
9
+ Project-URL: Issues, https://github.com/sudoers-ai/cogno-vox/issues
10
+ Keywords: llm,stt,tts,whisper,speech-to-text,text-to-speech,voice,agents
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: httpx>=0.24
26
+ Requires-Dist: cogno-homeo<0.2,>=0.1
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.5; extra == "dev"
32
+ Requires-Dist: mypy>=1.8; extra == "dev"
33
+ Requires-Dist: fastapi>=0.110; extra == "dev"
34
+ Requires-Dist: httpx>=0.27; extra == "dev"
35
+ Provides-Extra: bedrock
36
+ Requires-Dist: boto3>=1.34; extra == "bedrock"
37
+ Provides-Extra: server
38
+ Requires-Dist: fastapi>=0.110; extra == "server"
39
+ Requires-Dist: uvicorn>=0.29; extra == "server"
40
+ Dynamic: license-file
41
+
42
+ # cogno-vox
43
+
44
+ **Voice/audio I/O edge for the [Cogno](https://github.com/sudoers-ai/cogno-anima) cognitive pipeline** — speech-to-text in, text-to-speech out, behind provider-agnostic fallback chains.
45
+
46
+ `cogno-vox` is the *mouth and ears* of Cogno. Where [`cogno-anima`](https://github.com/sudoers-ai/cogno-anima) is the *mind* (pure cognition) and [`cogno-engram`](https://github.com/sudoers-ai/cogno-engram) is the *memory* (persistence substrate), `cogno-vox` is the **transport edge** that sits on the two boundaries of the pipeline:
47
+
48
+ ```
49
+ gateway ──▶ [vox STT] ──▶ cogno-anima (NOUMENO…SUPEREGO) ──▶ [vox TTS] ──▶ gateway
50
+ audio→text text→audio
51
+ ```
52
+
53
+ It is the most decoupled of the libraries: the core imports **neither** `cogno-anima` **nor** `cogno-engram` — it only converts audio ⇆ text.
54
+
55
+ > Status: **alpha** — core (ports + OpenAI-compatible backends + fallback chains) and the unit suite are in place.
56
+
57
+ ## Two capability-scoped ports
58
+
59
+ Like `cogno-anima`'s `LLMBackend`/`Embedder` and `cogno-engram`'s three ports, each direction is a structurally-typed `Protocol` with its own fallback chain (try tier 1→N, first non-empty wins, all-fail → raises):
60
+
61
+ | Port | Async method | Reference backends |
62
+ | --- | --- | --- |
63
+ | `TranscriberBackend` (STT) | `transcribe(audio, filename) -> str` | OpenAI-compatible (faster-whisper-server / Groq / OpenAI), Gemini multimodal, Bedrock/Voxtral |
64
+ | `SynthesizerBackend` (TTS) | `synthesize(text) -> bytes` | OpenAI-compatible (Kokoro / OpenAI), Grok, ElevenLabs, Gemini |
65
+
66
+ `OpenAICompat*` covers any `/v1/audio/transcriptions` or `/v1/audio/speech` server — local or cloud differ only by `base_url`/`api_key`, no SDK needed (just `httpx`).
67
+
68
+ ## Async by design
69
+
70
+ Everything is `async` (`httpx.AsyncClient`) to run under concurrent request load alongside `cogno-anima`/`cogno-engram`. Provider SDKs are lazy-imported behind extras (`pip install "cogno-vox[bedrock]"`); the OpenAI-compatible HTTP path needs no extra.
71
+
72
+ ## Host-injected config (no YAML, no env contextvar)
73
+
74
+ The host owns tier selection (model ladder, per-tenant routing, BYOK). You hand the factory a `VoxConfig`:
75
+
76
+ ```python
77
+ from cogno_vox import VoxConfig, TierConfig, create_transcriber, create_synthesizer
78
+
79
+ config = VoxConfig(
80
+ transcribe_tiers=(
81
+ TierConfig(provider="local", model="Systran/faster-whisper-small",
82
+ base_url="http://localhost:8000"),
83
+ TierConfig(provider="groq", model="whisper-large-v3-turbo",
84
+ base_url="https://api.groq.com/openai/v1", api_key="gsk_..."),
85
+ ),
86
+ synthesize_tiers=(
87
+ TierConfig(provider="local", model="kokoro",
88
+ base_url="http://localhost:8880/v1", voice="af_alloy"),
89
+ TierConfig(provider="openai", model="tts-1", voice="alloy",
90
+ base_url="https://api.openai.com/v1", api_key="sk-..."),
91
+ ),
92
+ default_tts_format="opus", # mandatory for Telegram native voice notes
93
+ )
94
+
95
+ stt = await create_transcriber(config).transcribe(audio_bytes, "voice.ogg")
96
+ print(stt.text, stt.tier, stt.elapsed_ms)
97
+
98
+ out = await create_synthesizer(config).synthesize("Olá, tudo bem?")
99
+ # out.audio (bytes), out.fmt, out.tier, out.elapsed_ms
100
+ ```
101
+
102
+ `split_text_for_tts()` slices long replies into ~30s segments (≈65 words) at sentence boundaries — one voice note each.
103
+
104
+ ## What stays in the host
105
+
106
+ Provider/model selection, RBAC premium gating, BYOK & key rotation, the channel delivery (`sendVoice`/`sendMedia`) and the channel-mandated format choice. `cogno-vox` offers `opus`/`mp3`; the host decides.
107
+
108
+ ## The Cogno ecosystem
109
+
110
+ `cogno-vox` is one organ of **[Cogno](https://github.com/sudoers-ai)** — a family of
111
+ small, composable, Apache-2.0 libraries that together form a complete
112
+ conversational-agent platform. Each library owns a single concern and stays
113
+ infra-agnostic; a **host** assembles them into a running agent:
114
+
115
+ ![The Cogno ecosystem](docs/assets/cogno-ecosystem.svg)
116
+
117
+ The open-source libraries are the organs; the **host is the body** that joins
118
+ them. Our reference host — `cogno-host`, with its `cogno-ui` dashboard — is the
119
+ private product layer, but it holds no special powers: everything it does rides
120
+ on the public seams documented in each library's `docs/HOST_INTEGRATION.md`, so
121
+ you can assemble a body of your own.
122
+
123
+ ## Develop
124
+
125
+ ```bash
126
+ pip install -e ".[dev]"
127
+ pytest tests/unit -q # mocked HTTP, no network
128
+ ruff check cogno_vox && mypy cogno_vox
129
+ ```
130
+
131
+ ### Live integration tests (gated, auto-skip)
132
+
133
+ `tests/integration` runs end-to-end against real local servers and **auto-skips**
134
+ unless pointed at them (same pattern as `cogno-engram`'s `ENGRAM_TEST_DSN`).
135
+ Validated against `fedirz/faster-whisper-server` (`Systran/faster-whisper-small`)
136
+ and `ghcr.io/remsky/kokoro-fastapi-cpu`. The bundled `docker-compose.yml` brings
137
+ both up:
138
+
139
+ ```bash
140
+ docker compose up -d # whisper :8000, kokoro :8880
141
+
142
+ VOX_TEST_WHISPER_URL=http://localhost:8000 \
143
+ VOX_TEST_KOKORO_URL=http://localhost:8880/v1 \
144
+ pytest tests/integration -q # synth (Kokoro) -> transcribe (Whisper) round-trip
145
+ ```
146
+
147
+ See [`docs/HOST_INTEGRATION.md`](docs/HOST_INTEGRATION.md) for wiring `cogno-vox`
148
+ onto the two edges of the pipeline.
149
+
150
+ ## License
151
+
152
+ Apache-2.0.
@@ -0,0 +1,111 @@
1
+ # cogno-vox
2
+
3
+ **Voice/audio I/O edge for the [Cogno](https://github.com/sudoers-ai/cogno-anima) cognitive pipeline** — speech-to-text in, text-to-speech out, behind provider-agnostic fallback chains.
4
+
5
+ `cogno-vox` is the *mouth and ears* of Cogno. Where [`cogno-anima`](https://github.com/sudoers-ai/cogno-anima) is the *mind* (pure cognition) and [`cogno-engram`](https://github.com/sudoers-ai/cogno-engram) is the *memory* (persistence substrate), `cogno-vox` is the **transport edge** that sits on the two boundaries of the pipeline:
6
+
7
+ ```
8
+ gateway ──▶ [vox STT] ──▶ cogno-anima (NOUMENO…SUPEREGO) ──▶ [vox TTS] ──▶ gateway
9
+ audio→text text→audio
10
+ ```
11
+
12
+ It is the most decoupled of the libraries: the core imports **neither** `cogno-anima` **nor** `cogno-engram` — it only converts audio ⇆ text.
13
+
14
+ > Status: **alpha** — core (ports + OpenAI-compatible backends + fallback chains) and the unit suite are in place.
15
+
16
+ ## Two capability-scoped ports
17
+
18
+ Like `cogno-anima`'s `LLMBackend`/`Embedder` and `cogno-engram`'s three ports, each direction is a structurally-typed `Protocol` with its own fallback chain (try tier 1→N, first non-empty wins, all-fail → raises):
19
+
20
+ | Port | Async method | Reference backends |
21
+ | --- | --- | --- |
22
+ | `TranscriberBackend` (STT) | `transcribe(audio, filename) -> str` | OpenAI-compatible (faster-whisper-server / Groq / OpenAI), Gemini multimodal, Bedrock/Voxtral |
23
+ | `SynthesizerBackend` (TTS) | `synthesize(text) -> bytes` | OpenAI-compatible (Kokoro / OpenAI), Grok, ElevenLabs, Gemini |
24
+
25
+ `OpenAICompat*` covers any `/v1/audio/transcriptions` or `/v1/audio/speech` server — local or cloud differ only by `base_url`/`api_key`, no SDK needed (just `httpx`).
26
+
27
+ ## Async by design
28
+
29
+ Everything is `async` (`httpx.AsyncClient`) to run under concurrent request load alongside `cogno-anima`/`cogno-engram`. Provider SDKs are lazy-imported behind extras (`pip install "cogno-vox[bedrock]"`); the OpenAI-compatible HTTP path needs no extra.
30
+
31
+ ## Host-injected config (no YAML, no env contextvar)
32
+
33
+ The host owns tier selection (model ladder, per-tenant routing, BYOK). You hand the factory a `VoxConfig`:
34
+
35
+ ```python
36
+ from cogno_vox import VoxConfig, TierConfig, create_transcriber, create_synthesizer
37
+
38
+ config = VoxConfig(
39
+ transcribe_tiers=(
40
+ TierConfig(provider="local", model="Systran/faster-whisper-small",
41
+ base_url="http://localhost:8000"),
42
+ TierConfig(provider="groq", model="whisper-large-v3-turbo",
43
+ base_url="https://api.groq.com/openai/v1", api_key="gsk_..."),
44
+ ),
45
+ synthesize_tiers=(
46
+ TierConfig(provider="local", model="kokoro",
47
+ base_url="http://localhost:8880/v1", voice="af_alloy"),
48
+ TierConfig(provider="openai", model="tts-1", voice="alloy",
49
+ base_url="https://api.openai.com/v1", api_key="sk-..."),
50
+ ),
51
+ default_tts_format="opus", # mandatory for Telegram native voice notes
52
+ )
53
+
54
+ stt = await create_transcriber(config).transcribe(audio_bytes, "voice.ogg")
55
+ print(stt.text, stt.tier, stt.elapsed_ms)
56
+
57
+ out = await create_synthesizer(config).synthesize("Olá, tudo bem?")
58
+ # out.audio (bytes), out.fmt, out.tier, out.elapsed_ms
59
+ ```
60
+
61
+ `split_text_for_tts()` slices long replies into ~30s segments (≈65 words) at sentence boundaries — one voice note each.
62
+
63
+ ## What stays in the host
64
+
65
+ Provider/model selection, RBAC premium gating, BYOK & key rotation, the channel delivery (`sendVoice`/`sendMedia`) and the channel-mandated format choice. `cogno-vox` offers `opus`/`mp3`; the host decides.
66
+
67
+ ## The Cogno ecosystem
68
+
69
+ `cogno-vox` is one organ of **[Cogno](https://github.com/sudoers-ai)** — a family of
70
+ small, composable, Apache-2.0 libraries that together form a complete
71
+ conversational-agent platform. Each library owns a single concern and stays
72
+ infra-agnostic; a **host** assembles them into a running agent:
73
+
74
+ ![The Cogno ecosystem](docs/assets/cogno-ecosystem.svg)
75
+
76
+ The open-source libraries are the organs; the **host is the body** that joins
77
+ them. Our reference host — `cogno-host`, with its `cogno-ui` dashboard — is the
78
+ private product layer, but it holds no special powers: everything it does rides
79
+ on the public seams documented in each library's `docs/HOST_INTEGRATION.md`, so
80
+ you can assemble a body of your own.
81
+
82
+ ## Develop
83
+
84
+ ```bash
85
+ pip install -e ".[dev]"
86
+ pytest tests/unit -q # mocked HTTP, no network
87
+ ruff check cogno_vox && mypy cogno_vox
88
+ ```
89
+
90
+ ### Live integration tests (gated, auto-skip)
91
+
92
+ `tests/integration` runs end-to-end against real local servers and **auto-skips**
93
+ unless pointed at them (same pattern as `cogno-engram`'s `ENGRAM_TEST_DSN`).
94
+ Validated against `fedirz/faster-whisper-server` (`Systran/faster-whisper-small`)
95
+ and `ghcr.io/remsky/kokoro-fastapi-cpu`. The bundled `docker-compose.yml` brings
96
+ both up:
97
+
98
+ ```bash
99
+ docker compose up -d # whisper :8000, kokoro :8880
100
+
101
+ VOX_TEST_WHISPER_URL=http://localhost:8000 \
102
+ VOX_TEST_KOKORO_URL=http://localhost:8880/v1 \
103
+ pytest tests/integration -q # synth (Kokoro) -> transcribe (Whisper) round-trip
104
+ ```
105
+
106
+ See [`docs/HOST_INTEGRATION.md`](docs/HOST_INTEGRATION.md) for wiring `cogno-vox`
107
+ onto the two edges of the pipeline.
108
+
109
+ ## License
110
+
111
+ Apache-2.0.
@@ -0,0 +1,64 @@
1
+ """cogno-vox — voice/audio I/O edge for the Cogno cognitive pipeline.
2
+
3
+ STT before the mind, TTS after it:
4
+ gateway -> [vox STT] -> cogno-anima -> [vox TTS] -> gateway
5
+
6
+ The core imports neither cogno-anima nor cogno-engram — it only converts
7
+ audio <-> text behind two capability-scoped protocols with provider-agnostic
8
+ fallback chains.
9
+ """
10
+
11
+ from cogno_vox.chunker import split_text_for_tts
12
+ from cogno_vox.factory import create_synthesizer, create_transcriber
13
+ from cogno_vox.text_prep import apply_emotion, clean_text_for_tts, strip_emotion_tags
14
+ from cogno_vox.ports import (
15
+ SynthesisError,
16
+ SynthesizerBackend,
17
+ TranscriberBackend,
18
+ TranscriptionError,
19
+ VoxError,
20
+ )
21
+ from cogno_vox.synthesizer import (
22
+ ElevenLabsSynthesizer,
23
+ FallbackSynthesizer,
24
+ GeminiSynthesizer,
25
+ GrokSynthesizer,
26
+ OpenAICompatSynthesizer,
27
+ )
28
+ from cogno_vox.transcriber import (
29
+ BedrockTranscriber,
30
+ FallbackTranscriber,
31
+ GeminiTranscriber,
32
+ OpenAICompatTranscriber,
33
+ )
34
+ from cogno_vox.types import (
35
+ SUPPORTED_INPUT_FORMATS,
36
+ SynthesisResult,
37
+ TierConfig,
38
+ TranscriptionResult,
39
+ VoxConfig,
40
+ )
41
+
42
+ __version__ = "0.1.0"
43
+
44
+ __all__ = [
45
+ "__version__",
46
+ # ports + errors
47
+ "TranscriberBackend", "SynthesizerBackend",
48
+ "VoxError", "TranscriptionError", "SynthesisError",
49
+ # types
50
+ "VoxConfig", "TierConfig", "TranscriptionResult", "SynthesisResult",
51
+ "SUPPORTED_INPUT_FORMATS",
52
+ # chains
53
+ "FallbackTranscriber", "FallbackSynthesizer",
54
+ # transcriber backends
55
+ "OpenAICompatTranscriber", "GeminiTranscriber", "BedrockTranscriber",
56
+ # synthesizer backends
57
+ "OpenAICompatSynthesizer", "GrokSynthesizer",
58
+ "ElevenLabsSynthesizer", "GeminiSynthesizer",
59
+ # factory + utils
60
+ "create_transcriber", "create_synthesizer", "split_text_for_tts",
61
+ "apply_emotion",
62
+ "clean_text_for_tts",
63
+ "strip_emotion_tags",
64
+ ]
@@ -0,0 +1,97 @@
1
+ """
2
+ cogno_vox.audio_utils — audio container helpers.
3
+
4
+ Currently: raw PCM → Opus-in-Ogg via an ffmpeg subprocess. Gemini TTS returns
5
+ Linear16 PCM @ 24kHz; Telegram (and most voice-note channels) expect Opus.
6
+
7
+ ffmpeg is a *soft* dependency: if it is not on PATH the function degrades by
8
+ returning the raw PCM unchanged (the caller/channel may still accept it, or the
9
+ fallback chain moves on) rather than raising.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import logging
15
+ import shutil
16
+ import subprocess
17
+
18
+ log = logging.getLogger(__name__)
19
+
20
+
21
+ def ffmpeg_available() -> bool:
22
+ """True when the ``ffmpeg`` binary is on PATH. Used for a boot-time check: the local Kokoro
23
+ tier re-encodes opus via ffmpeg (``wav_to_opus``), and its degrade is STRICT (``b""``), so a
24
+ missing ffmpeg silently kills all voice output — worth surfacing at startup, not per turn."""
25
+ return shutil.which("ffmpeg") is not None
26
+
27
+
28
+ def pcm_to_opus(pcm: bytes, sample_rate: int = 24000) -> bytes:
29
+ """Convert raw signed-16-bit mono PCM to Opus-in-Ogg via ffmpeg.
30
+
31
+ Returns the original ``pcm`` unchanged if ffmpeg is unavailable or fails.
32
+ """
33
+ if not pcm:
34
+ return b""
35
+ try:
36
+ result = subprocess.run(
37
+ [
38
+ "ffmpeg", "-y",
39
+ "-f", "s16le", # signed 16-bit little-endian
40
+ "-ar", str(sample_rate),
41
+ "-ac", "1", # mono
42
+ "-i", "pipe:0",
43
+ "-c:a", "libopus",
44
+ "-b:a", "32k",
45
+ "-f", "ogg",
46
+ "pipe:1",
47
+ ],
48
+ input=pcm,
49
+ capture_output=True,
50
+ timeout=30,
51
+ )
52
+ if result.returncode == 0 and result.stdout:
53
+ return result.stdout
54
+ log.warning("ffmpeg PCM->Opus failed: rc=%d stderr=%s",
55
+ result.returncode, result.stderr[:200])
56
+ return pcm
57
+ except FileNotFoundError:
58
+ log.warning("ffmpeg not found — returning raw PCM")
59
+ return pcm
60
+ except Exception as exc:
61
+ log.warning("PCM->Opus conversion error: %s", exc)
62
+ return pcm
63
+
64
+
65
+ def wav_to_opus(audio: bytes) -> bytes:
66
+ """Convert a container-carrying audio blob (WAV/anything ffmpeg sniffs) to Opus-in-Ogg.
67
+
68
+ Companion to :func:`pcm_to_opus` for sources that return a full container instead of raw
69
+ PCM — e.g. requesting ``wav`` from a Kokoro server (whose own ``opus`` encoder truncates
70
+ the tail of the audio) and encoding properly here.
71
+
72
+ Degrade contract is STRICT (unlike ``pcm_to_opus``): on ffmpeg failure it returns ``b""``.
73
+ The caller promised opus (``fmt`` is reported to the channel, which labels the voice note
74
+ ``audio/ogg``) — handing back WAV under that label breaks playback outright, whereas an
75
+ empty result makes the tier fail over to the next engine (or degrade to a text reply).
76
+ """
77
+ if not audio:
78
+ return b""
79
+ try:
80
+ result = subprocess.run(
81
+ ["ffmpeg", "-y", "-i", "pipe:0",
82
+ "-c:a", "libopus", "-b:a", "32k", "-f", "ogg", "pipe:1"],
83
+ input=audio,
84
+ capture_output=True,
85
+ timeout=30,
86
+ )
87
+ if result.returncode == 0 and result.stdout:
88
+ return result.stdout
89
+ log.warning("ffmpeg WAV->Opus failed: rc=%d stderr=%s",
90
+ result.returncode, result.stderr[:200])
91
+ return b""
92
+ except FileNotFoundError:
93
+ log.warning("ffmpeg not found — WAV->Opus unavailable, failing the tier over")
94
+ return b""
95
+ except Exception as exc:
96
+ log.warning("WAV->Opus conversion error: %s", exc)
97
+ return b""