@agfpd/voice-connect 0.1.11
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.
- package/LICENSE +201 -0
- package/README.md +72 -0
- package/bin/peer-voice-http.mjs +20 -0
- package/bin/peer-voice-mcp.mjs +18 -0
- package/package.json +61 -0
- package/src/apikey.mjs +61 -0
- package/src/audio.mjs +112 -0
- package/src/config.mjs +75 -0
- package/src/configfile.mjs +38 -0
- package/src/engines/f5.mjs +111 -0
- package/src/engines/gemini.mjs +199 -0
- package/src/engines/gptaudio.mjs +230 -0
- package/src/engines/mlxwhisper.mjs +70 -0
- package/src/engines/speaches.mjs +69 -0
- package/src/engines/supertonic.mjs +177 -0
- package/src/home.mjs +15 -0
- package/src/http.mjs +252 -0
- package/src/jobs.mjs +95 -0
- package/src/langsplit.mjs +129 -0
- package/src/profile.mjs +165 -0
- package/src/providers.mjs +210 -0
- package/src/ref.mjs +157 -0
- package/src/router.mjs +91 -0
- package/src/ruaccent.mjs +114 -0
- package/src/ruaccent_stress.py +66 -0
- package/src/server.mjs +278 -0
- package/src/stress.mjs +25 -0
- package/src/stt.mjs +48 -0
- package/src/synthlog.mjs +46 -0
- package/src/voice.mjs +201 -0
- package/src/worker.mjs +120 -0
package/LICENSE
ADDED
|
@@ -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 Artur Agafapudov
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# voice-connect
|
|
2
|
+
|
|
3
|
+
**Text-to-voice for a team of AI agents — the voice component of [iapeer](https://github.com/agfpd/iapeer).**
|
|
4
|
+
|
|
5
|
+
An MCP server that gives AI agents a single tool — `voice_create` — to turn text into a ready-to-send `.ogg/opus` voice file.
|
|
6
|
+
|
|
7
|
+
> **Built for iapeer.** It isn't a standalone TTS service — it runs inside [iapeer](https://github.com/agfpd/iapeer), alongside `iapeer-memory` and `telegram-runtime`. A peer synthesizes a file with one tool call and delivers it over iapeer's own messaging.
|
|
8
|
+
|
|
9
|
+
## How it works
|
|
10
|
+
|
|
11
|
+
Engine routing with fallback happens inside the tool: **Gemini 3.1 Flash TTS** primary (ru+en in one pass) → **gpt-audio** over OpenRouter → **F5-TTS** (live prosody) → **Supertonic 3** local floor (offline). The agent passes text and gets back a path; delivery (e.g. `send_to_peer(personality, attachments=[path])`) stays the caller's job — the tool only produces the file.
|
|
12
|
+
|
|
13
|
+
Short text is synthesized synchronously: the path comes back right away. Long text (over ~2000 chars) is synthesized asynchronously — the tool returns a `job_id` immediately, and a background worker notifies the caller over IAP when the file is ready.
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- **Node.js ≥ 18**
|
|
18
|
+
- **ffmpeg / ffprobe** on `PATH` (audio encode + probe). On macOS: `brew install ffmpeg`.
|
|
19
|
+
- **python3** — only for the first provision of the local Supertonic fallback (a managed venv is created on demand).
|
|
20
|
+
- **API keys** — read from the environment, or from a shell rc file as a fallback:
|
|
21
|
+
- `GEMINI_API_KEY` — the primary engine (Google Gemini TTS).
|
|
22
|
+
- `OPENROUTER_API_KEY` — the gpt-audio fallback rung (OpenRouter).
|
|
23
|
+
- Neither key is strictly required: with no key, routing falls through to the local F5 / Supertonic engines.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
As a plugin (Claude Code / Codex), via the agfpd marketplace:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
/plugin marketplace add agfpd/agfpd-marketplace
|
|
31
|
+
/plugin install voice-connect@agfpd
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or run the MCP server directly from npm:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
npx -y @agfpd/voice-connect@latest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
The server exposes a single tool:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
voice_create(text, voice?, lang?, style?, note?, engine?, out_path?)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Param | Type | Description |
|
|
49
|
+
|-------|------|-------------|
|
|
50
|
+
| `text` | string (required) | Text to speak. Mixed ru+en is fine — read in one pass. |
|
|
51
|
+
| `voice` | string | Gemini prebuilt voice. Default `Aoede`. |
|
|
52
|
+
| `lang` | `ru` \| `en` \| `na` | Language hint for the fallback engines (Gemini reads any language itself). Omit to auto-detect by character share. |
|
|
53
|
+
| `style` | string | Delivery directive (tone / emotion / tempo) for the cloud engines; ignored by the local fallbacks. |
|
|
54
|
+
| `note` | string | Reminder echoed back in the async "done" message (e.g. who to deliver to). Ignored for short (sync) text. |
|
|
55
|
+
| `engine` | `auto` \| `gemini` \| `gpt-audio` \| `supertonic` | Force an engine. Default `auto` (the full cascade). |
|
|
56
|
+
| `out_path` | string | Absolute output `.ogg` path. Default: a unique file under `~/.iapeer/cache/peer-voice/out/`. |
|
|
57
|
+
|
|
58
|
+
**Returns** — short text (sync): `{ path, engine, voice, lang?, probe, fallback_from? }`. Long text (async): `{ job_id, status: "started" }`, followed by an IAP message `voice job <id> done path=<path> note=<note>` when synthesis finishes.
|
|
59
|
+
|
|
60
|
+
Delivery is never automatic — attach the returned file yourself, e.g. `send_to_peer(personality, attachments=[path])`.
|
|
61
|
+
|
|
62
|
+
## What makes it different
|
|
63
|
+
|
|
64
|
+
- **One tool, four engines.** The cascade routes from cloud quality down to an offline floor inside the tool; the caller never picks an engine unless it wants to.
|
|
65
|
+
- **Mixed ru+en in one pass.** Gemini reads both languages together, so a Russian-dominant line with a few English words comes back natural — no splitting, no per-language calls.
|
|
66
|
+
- **Always a result.** With no API key, routing falls through to the local F5 / Supertonic engines; synthesis works offline.
|
|
67
|
+
- **Long text never blocks.** Over ~2000 chars the tool returns a `job_id` at once and a detached worker notifies the caller over IAP when the file is ready.
|
|
68
|
+
- **Produces, never delivers.** The tool hands back a path; the caller attaches it with `send_to_peer` — one clear boundary between synthesis and delivery.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
[Apache-2.0](LICENSE). Platform: macOS. voice-connect is the voice provider for the [iapeer](https://github.com/agfpd/iapeer) ecosystem — a component of iapeer, not a standalone system.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Entry point for the voice-connect HTTP facade — the always-on, OpenAI-compatible
|
|
4
|
+
* audio service (/v1/audio/speech + /v1/audio/transcriptions) over the same
|
|
5
|
+
* core as the MCP server. Runtimes (telegram-runtime, voicetalk) hit it over
|
|
6
|
+
* HTTP, no MCP.
|
|
7
|
+
*
|
|
8
|
+
* Pure Node ESM — no bun, no build step. Bind host/port come from the env
|
|
9
|
+
* (PEER_VOICE_HTTP_HOST / PEER_VOICE_HTTP_PORT); see src/http.mjs. Intended to
|
|
10
|
+
* run under launchd as a long-lived local service.
|
|
11
|
+
*
|
|
12
|
+
* Host tools used at runtime: ffmpeg/ffprobe (always), python3 (only the first
|
|
13
|
+
* time the Supertonic fallback provisions its venv) — same as the MCP server.
|
|
14
|
+
*/
|
|
15
|
+
import { main } from '../src/http.mjs';
|
|
16
|
+
|
|
17
|
+
main().catch(err => {
|
|
18
|
+
process.stderr.write(`voice-connect http: fatal: ${err && err.stack ? err.stack : err}\n`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Entry point for @agfpd/voice-connect (MCP server).
|
|
4
|
+
*
|
|
5
|
+
* Pure Node ESM — no bun, no build step. The MCP server only needs the
|
|
6
|
+
* standard library (fetch, Buffer, child_process) plus the MCP SDK, so it runs
|
|
7
|
+
* directly under node wherever npm/npx is available. The plugin's .mcp.json
|
|
8
|
+
* invokes this via `npx -y @agfpd/voice-connect@latest`.
|
|
9
|
+
*
|
|
10
|
+
* Host tools used at runtime: ffmpeg/ffprobe (always), python3 (only the first
|
|
11
|
+
* time the Supertonic fallback provisions its venv).
|
|
12
|
+
*/
|
|
13
|
+
import { main } from '../src/server.mjs';
|
|
14
|
+
|
|
15
|
+
main().catch(err => {
|
|
16
|
+
process.stderr.write(`voice-connect: fatal: ${err && err.stack ? err.stack : err}\n`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agfpd/voice-connect",
|
|
3
|
+
"version": "0.1.11",
|
|
4
|
+
"description": "voice-connect — voice service for agents. MCP tools tts (text → ready-to-send .ogg/opus voice file) and stt (audio → text) over one core, plus an OpenAI-compatible HTTP facade (/v1/audio/speech + /v1/audio/transcriptions) for runtimes. Cascade with fallback inside each tool — TTS: Gemini 3.1 Flash → gpt-audio (OpenRouter) → F5-TTS → Supertonic 3 local floor; STT: speaches → mlx-whisper local floor. Delivery stays the caller's job (send_to_peer attachments).",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "agfpd",
|
|
8
|
+
"url": "https://github.com/agfpd"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/agfpd/voice-connect",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/agfpd/voice-connect.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/agfpd/voice-connect/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"claude-code",
|
|
20
|
+
"codex",
|
|
21
|
+
"mcp",
|
|
22
|
+
"model-context-protocol",
|
|
23
|
+
"iapeer",
|
|
24
|
+
"agents",
|
|
25
|
+
"voice-connect",
|
|
26
|
+
"tts",
|
|
27
|
+
"text-to-speech",
|
|
28
|
+
"speech-to-text",
|
|
29
|
+
"voice",
|
|
30
|
+
"gemini",
|
|
31
|
+
"supertonic"
|
|
32
|
+
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"bin": {
|
|
35
|
+
"voice-connect-mcp": "bin/peer-voice-mcp.mjs"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"bin/",
|
|
39
|
+
"src/",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"start": "node bin/peer-voice-mcp.mjs",
|
|
45
|
+
"test": "node --test tests/*.test.mjs",
|
|
46
|
+
"release": "npm version patch && npm publish && git push --follow-tags && node scripts/bump-marketplace.cjs",
|
|
47
|
+
"release:minor": "npm version minor && npm publish && git push --follow-tags && node scripts/bump-marketplace.cjs",
|
|
48
|
+
"release:major": "npm version major && npm publish && git push --follow-tags && node scripts/bump-marketplace.cjs",
|
|
49
|
+
"prepublishOnly": "test -z \"$(git status --porcelain)\" || (echo 'release: working tree is dirty — commit or stash before release' >&2 && exit 1)",
|
|
50
|
+
"version": "node scripts/sync-plugin-version.cjs"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/apikey.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a cloud API key (Gemini, OpenRouter).
|
|
3
|
+
*
|
|
4
|
+
* Order: process env first, then a fallback that greps the user's shell rc
|
|
5
|
+
* files for `export <NAME>=...`, then the autonomous config file's `keys` map
|
|
6
|
+
* (configfile.mjs) for standalone use. The rc fallback is the one conscious,
|
|
7
|
+
* sanctioned host assumption in this plugin (§2 of the team plugin standard):
|
|
8
|
+
* the key lives in ~/.zshrc on the operator's machine and is not exported into
|
|
9
|
+
* the non-login shell an MCP server runs under. Mirrors the proven legacy
|
|
10
|
+
* voice-reply.sh recipe.
|
|
11
|
+
*
|
|
12
|
+
* Note (ops): a LIVE MCP server process keeps the env it booted with, so a key
|
|
13
|
+
* added to ~/.zshrc after start is only visible via the rc fallback — or after
|
|
14
|
+
* the server respawns. The two cloud engines (Gemini direct, gpt-audio over
|
|
15
|
+
* OpenRouter) each read their own key with the same posture.
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { readConfigFile } from './configfile.mjs';
|
|
21
|
+
|
|
22
|
+
const RC_FILES = ['.zshrc', '.zshenv', '.bashrc', '.bash_profile', '.profile'];
|
|
23
|
+
|
|
24
|
+
/** Read `name` from a parsed config-file object's `keys` map, or null. */
|
|
25
|
+
export function keyFromConfigFile(file, name) {
|
|
26
|
+
const v = file && file.keys && typeof file.keys === 'object' ? file.keys[name] : undefined;
|
|
27
|
+
return typeof v === 'string' && v.trim() ? v.trim() : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Read `name` from process env, else from the first rc file that exports it. */
|
|
31
|
+
function readKey(name) {
|
|
32
|
+
if (process.env[name] && process.env[name].trim()) {
|
|
33
|
+
return process.env[name].trim();
|
|
34
|
+
}
|
|
35
|
+
// Match: export <NAME>="value" | 'value' | value
|
|
36
|
+
const re = new RegExp(`^\\s*export\\s+${name}=["']?([^"'\\n]+)["']?`, 'm');
|
|
37
|
+
for (const rc of RC_FILES) {
|
|
38
|
+
let content;
|
|
39
|
+
try {
|
|
40
|
+
content = readFileSync(join(homedir(), rc), 'utf8');
|
|
41
|
+
} catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const m = content.match(re);
|
|
45
|
+
if (m && m[1].trim()) {
|
|
46
|
+
return m[1].trim();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Final fallback: the autonomous config file's `keys` map (standalone mode —
|
|
50
|
+
// a user without env/rc keys sets them there). env/rc still win when present.
|
|
51
|
+
return keyFromConfigFile(readConfigFile(), name);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function readGeminiKey() {
|
|
55
|
+
return readKey('GEMINI_API_KEY');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** OpenRouter key — provider for the gpt-audio fallback rung (engines/gptaudio.mjs). */
|
|
59
|
+
export function readOpenRouterKey() {
|
|
60
|
+
return readKey('OPENROUTER_API_KEY');
|
|
61
|
+
}
|
package/src/audio.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audio plumbing around the system `ffmpeg`/`ffprobe`.
|
|
3
|
+
*
|
|
4
|
+
* Internal canonical format is raw PCM s16le, 24 kHz, mono — what Gemini TTS
|
|
5
|
+
* returns natively and what Supertonic wavs are normalized to. Pieces are
|
|
6
|
+
* concatenated as PCM buffers in memory (with optional silence gaps), then the
|
|
7
|
+
* combined PCM is encoded ONCE to Telegram-grade ogg/opus.
|
|
8
|
+
*/
|
|
9
|
+
import { execFile } from 'node:child_process';
|
|
10
|
+
import { promisify } from 'node:util';
|
|
11
|
+
import { readFile, writeFile, unlink } from 'node:fs/promises';
|
|
12
|
+
|
|
13
|
+
const pexecFile = promisify(execFile);
|
|
14
|
+
|
|
15
|
+
export const SAMPLE_RATE = 24000;
|
|
16
|
+
export const CHANNELS = 1;
|
|
17
|
+
export const BYTES_PER_SAMPLE = 2;
|
|
18
|
+
|
|
19
|
+
const FFMPEG = process.env.PEER_VOICE_FFMPEG || 'ffmpeg';
|
|
20
|
+
const FFPROBE = process.env.PEER_VOICE_FFPROBE || 'ffprobe';
|
|
21
|
+
|
|
22
|
+
async function run(bin, args) {
|
|
23
|
+
try {
|
|
24
|
+
return await pexecFile(bin, args, { maxBuffer: 64 * 1024 * 1024 });
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (err && err.code === 'ENOENT') {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`${bin} not found on PATH. voice-connect needs ffmpeg/ffprobe installed ` +
|
|
29
|
+
`(macOS: brew install ffmpeg). Override the binary via PEER_VOICE_FFMPEG / PEER_VOICE_FFPROBE.`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const stderr = (err && err.stderr ? String(err.stderr) : '').slice(-500);
|
|
33
|
+
throw new Error(`${bin} failed: ${stderr || (err && err.message) || 'unknown error'}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Decode any audio file (e.g. a Supertonic wav) to canonical PCM and read it. */
|
|
38
|
+
export async function decodeToPcmBuffer(srcPath) {
|
|
39
|
+
const pcmPath = `${srcPath}.s16le.pcm`;
|
|
40
|
+
try {
|
|
41
|
+
await run(FFMPEG, [
|
|
42
|
+
'-hide_banner', '-loglevel', 'error',
|
|
43
|
+
'-i', srcPath,
|
|
44
|
+
'-f', 's16le', '-ar', String(SAMPLE_RATE), '-ac', String(CHANNELS),
|
|
45
|
+
pcmPath, '-y',
|
|
46
|
+
]);
|
|
47
|
+
return await readFile(pcmPath);
|
|
48
|
+
} finally {
|
|
49
|
+
await unlink(pcmPath).catch(() => {});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Encode a canonical-PCM buffer to ogg/opus (Telegram voice profile).
|
|
54
|
+
* The intermediate PCM is removed afterwards so no `*.in.pcm` turd is left
|
|
55
|
+
* next to the output (this runs outside the caller's temp dir). */
|
|
56
|
+
export async function encodePcmToOgg(pcmBuffer, oggPath) {
|
|
57
|
+
const pcmPath = `${oggPath}.in.pcm`;
|
|
58
|
+
try {
|
|
59
|
+
await writeFile(pcmPath, pcmBuffer);
|
|
60
|
+
await run(FFMPEG, [
|
|
61
|
+
'-hide_banner', '-loglevel', 'error',
|
|
62
|
+
'-f', 's16le', '-ar', String(SAMPLE_RATE), '-ac', String(CHANNELS),
|
|
63
|
+
'-i', pcmPath,
|
|
64
|
+
'-c:a', 'libopus', '-b:a', '48k', '-vbr', 'on', '-application', 'voip',
|
|
65
|
+
oggPath, '-y',
|
|
66
|
+
]);
|
|
67
|
+
return oggPath;
|
|
68
|
+
} finally {
|
|
69
|
+
await unlink(pcmPath).catch(() => {});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Wrap a canonical-PCM buffer into a RIFF wav file (e.g. an F5 voice reference).
|
|
74
|
+
* A real wav container — not raw PCM — so the service's soundfile reader parses
|
|
75
|
+
* it cleanly. The intermediate PCM is removed afterwards. */
|
|
76
|
+
export async function encodePcmToWav(pcmBuffer, wavPath) {
|
|
77
|
+
const pcmPath = `${wavPath}.in.pcm`;
|
|
78
|
+
try {
|
|
79
|
+
await writeFile(pcmPath, pcmBuffer);
|
|
80
|
+
await run(FFMPEG, [
|
|
81
|
+
'-hide_banner', '-loglevel', 'error',
|
|
82
|
+
'-f', 's16le', '-ar', String(SAMPLE_RATE), '-ac', String(CHANNELS),
|
|
83
|
+
'-i', pcmPath,
|
|
84
|
+
'-c:a', 'pcm_s16le',
|
|
85
|
+
wavPath, '-y',
|
|
86
|
+
]);
|
|
87
|
+
return wavPath;
|
|
88
|
+
} finally {
|
|
89
|
+
await unlink(pcmPath).catch(() => {});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Probe an output file: { duration, format_name, codec_name, sample_rate, channels }. */
|
|
94
|
+
export async function probe(filePath) {
|
|
95
|
+
const { stdout } = await run(FFPROBE, [
|
|
96
|
+
'-v', 'error',
|
|
97
|
+
'-show_entries', 'format=duration,format_name',
|
|
98
|
+
'-show_entries', 'stream=codec_name,sample_rate,channels',
|
|
99
|
+
'-of', 'json',
|
|
100
|
+
filePath,
|
|
101
|
+
]);
|
|
102
|
+
const data = JSON.parse(stdout);
|
|
103
|
+
const stream = (data.streams && data.streams[0]) || {};
|
|
104
|
+
const format = data.format || {};
|
|
105
|
+
return {
|
|
106
|
+
duration: format.duration ? Number(format.duration) : null,
|
|
107
|
+
format_name: format.format_name || null,
|
|
108
|
+
codec_name: stream.codec_name || null,
|
|
109
|
+
sample_rate: stream.sample_rate ? Number(stream.sample_rate) : null,
|
|
110
|
+
channels: stream.channels != null ? Number(stream.channels) : null,
|
|
111
|
+
};
|
|
112
|
+
}
|
package/src/config.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config center — the single surface that answers "what voice, what keys" for a
|
|
3
|
+
* synthesis, with a RUNTIME-mode-dependent source (no race, no config in three
|
|
4
|
+
* places):
|
|
5
|
+
*
|
|
6
|
+
* - iapeer-mode → voice from the peer-profile (profile.mjs), keys from env/rc.
|
|
7
|
+
* - autonomous → voice + keys from the package config file (configfile.mjs).
|
|
8
|
+
*
|
|
9
|
+
* Mode is decided by ONE signal: does the caller have an iapeer identity?
|
|
10
|
+
* callerPersonality() resolves it from PEER_PERSONALITY (claude) OR the cwd
|
|
11
|
+
* peer-profile (codex) — non-null ⇒ iapeer, null ⇒ autonomous. So the iapeer
|
|
12
|
+
* voice path is byte-identical to before (it just delegates to callerVoiceMap);
|
|
13
|
+
* autonomous is the new, additive standalone path. voice-connect NEVER creates a
|
|
14
|
+
* peer-profile — the autonomous source is the file only.
|
|
15
|
+
*
|
|
16
|
+
* Keys are global in BOTH modes; their env → rc → config-file ladder lives in
|
|
17
|
+
* apikey.mjs (re-exported here so this module is the one config import).
|
|
18
|
+
*/
|
|
19
|
+
import { callerPersonality, callerVoiceMap } from './profile.mjs';
|
|
20
|
+
import { readGeminiKey, readOpenRouterKey } from './apikey.mjs';
|
|
21
|
+
import { readConfigFile, configPath } from './configfile.mjs';
|
|
22
|
+
|
|
23
|
+
// ── pure cores (host-independent, unit-tested) ──────────────────────────────
|
|
24
|
+
|
|
25
|
+
/** The runtime mode for a given caller identity. */
|
|
26
|
+
export function modeForPersonality(personality) {
|
|
27
|
+
return personality ? 'iapeer' : 'autonomous';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Pick the voice map for a mode from the two candidate sources. */
|
|
31
|
+
export function selectVoiceMap({ mode, profileVoiceMap, fileVoiceMap }) {
|
|
32
|
+
return mode === 'iapeer' ? (profileVoiceMap || {}) : (fileVoiceMap || {});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The `voice` map out of a parsed config-file object, or {}. */
|
|
36
|
+
export function voiceFromConfig(file) {
|
|
37
|
+
return file && file.voice && typeof file.voice === 'object' ? file.voice : {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ── impure wrappers (wire the real sources) ─────────────────────────────────
|
|
41
|
+
|
|
42
|
+
/** 'iapeer' | 'autonomous' for the current caller. */
|
|
43
|
+
export function detectMode() {
|
|
44
|
+
return modeForPersonality(callerPersonality());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The caller's voice map (model-name → voice), from the mode-appropriate source.
|
|
49
|
+
* iapeer → peer-profile (callerVoiceMap, unchanged env/cwd logic); autonomous →
|
|
50
|
+
* the config file's `voice`.
|
|
51
|
+
* @returns {Record<string,string>}
|
|
52
|
+
*/
|
|
53
|
+
export function voiceMap() {
|
|
54
|
+
const mode = detectMode();
|
|
55
|
+
return selectVoiceMap({
|
|
56
|
+
mode,
|
|
57
|
+
profileVoiceMap: mode === 'iapeer' ? callerVoiceMap() : {},
|
|
58
|
+
fileVoiceMap: voiceFromConfig(readConfigFile()),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Keys (global, env → rc → config-file). Re-exported so config.mjs is the seam.
|
|
63
|
+
export { readGeminiKey, readOpenRouterKey };
|
|
64
|
+
|
|
65
|
+
/** Diagnostic snapshot of the effective config source (no secrets revealed). */
|
|
66
|
+
export function effectiveConfig() {
|
|
67
|
+
return {
|
|
68
|
+
mode: detectMode(),
|
|
69
|
+
personality: callerPersonality(),
|
|
70
|
+
configPath: configPath(),
|
|
71
|
+
hasGeminiKey: Boolean(readGeminiKey()),
|
|
72
|
+
hasOpenRouterKey: Boolean(readOpenRouterKey()),
|
|
73
|
+
voiceModels: Object.keys(voiceMap()),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autonomous config file — the standalone (non-iapeer) settings source.
|
|
3
|
+
*
|
|
4
|
+
* In iapeer-mode the package is configured from the peer-profile (voice) and the
|
|
5
|
+
* host env/rc (keys). Standalone — a bare Claude Code / Codex / OpenAI-SDK user
|
|
6
|
+
* without iapeer — there is no peer-profile, so voice-connect reads ONE file:
|
|
7
|
+
*
|
|
8
|
+
* {
|
|
9
|
+
* "voice": { "gemini-3.1-flash-tts-preview": "Aoede", "supertonic-3": "M5" },
|
|
10
|
+
* "keys": { "GEMINI_API_KEY": "...", "OPENROUTER_API_KEY": "..." }
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* Path: $PEER_VOICE_CONFIG, else <peerVoiceHome()>/config.json. voice-connect
|
|
14
|
+
* only READS this file — it never writes a peer-profile or this config itself
|
|
15
|
+
* (the operator / iapeer owns configuration).
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { peerVoiceHome } from './home.mjs';
|
|
20
|
+
|
|
21
|
+
/** Resolved path of the autonomous config file. */
|
|
22
|
+
export function configPath() {
|
|
23
|
+
return process.env.PEER_VOICE_CONFIG || join(peerVoiceHome(), 'config.json');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parse the autonomous config file, or null when absent / empty / unparseable.
|
|
28
|
+
* @param {string} [path] override (tests); defaults to configPath()
|
|
29
|
+
* @returns {object|null}
|
|
30
|
+
*/
|
|
31
|
+
export function readConfigFile(path = configPath()) {
|
|
32
|
+
try {
|
|
33
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
34
|
+
return raw && typeof raw === 'object' ? raw : null;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|