@agentforge-ai/tools-voice 0.7.0
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 +197 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +266 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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!)
|
|
184
|
+
|
|
185
|
+
Copyright [yyyy] [name of copyright owner]
|
|
186
|
+
|
|
187
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
188
|
+
you may not use this file except in compliance with the License.
|
|
189
|
+
You may obtain a copy of the License at
|
|
190
|
+
|
|
191
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
192
|
+
|
|
193
|
+
Unless required by applicable law or agreed to in writing, software
|
|
194
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
195
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
196
|
+
See the License for the specific language governing permissions and
|
|
197
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as _mastra_core_tools from '@mastra/core/tools';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Voice configuration types for AgentForge voice tools.
|
|
5
|
+
*/
|
|
6
|
+
interface VoiceConfig {
|
|
7
|
+
/** ElevenLabs voice ID */
|
|
8
|
+
voiceId?: string;
|
|
9
|
+
/** Speech speed multiplier (0.5–2.0). Default: 1.0 */
|
|
10
|
+
speed?: number;
|
|
11
|
+
/** TTS model ID (e.g., 'eleven_multilingual_v2'). Default: 'eleven_multilingual_v2' */
|
|
12
|
+
model?: string;
|
|
13
|
+
/** Voice provider. Default: 'elevenlabs' */
|
|
14
|
+
provider?: 'elevenlabs';
|
|
15
|
+
/** Language code (e.g., 'en', 'es'). Default: 'en' */
|
|
16
|
+
language?: string;
|
|
17
|
+
}
|
|
18
|
+
declare const DEFAULT_VOICE_CONFIG: Required<VoiceConfig>;
|
|
19
|
+
/** Maximum text length for TTS input (ElevenLabs limit) */
|
|
20
|
+
declare const MAX_TTS_TEXT_LENGTH = 5000;
|
|
21
|
+
/** Maximum audio file size for STT (OpenAI Whisper limit: 25MB) */
|
|
22
|
+
declare const MAX_STT_FILE_SIZE: number;
|
|
23
|
+
/**
|
|
24
|
+
* Sanitize text input for TTS.
|
|
25
|
+
* Strips control characters and trims whitespace.
|
|
26
|
+
* Throws if text exceeds maximum length.
|
|
27
|
+
*/
|
|
28
|
+
declare function sanitizeTtsText(text: string): string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ElevenLabs TTS Client for AgentForge.
|
|
32
|
+
*
|
|
33
|
+
* Sends text to the ElevenLabs text-to-speech API and returns audio data.
|
|
34
|
+
* API Reference: https://elevenlabs.io/docs/api-reference/text-to-speech
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
interface TtsRequest {
|
|
38
|
+
/** Text to convert to speech */
|
|
39
|
+
text: string;
|
|
40
|
+
/** Voice configuration overrides */
|
|
41
|
+
config?: Partial<VoiceConfig>;
|
|
42
|
+
}
|
|
43
|
+
interface TtsResponse {
|
|
44
|
+
/** Audio data as ArrayBuffer */
|
|
45
|
+
audio: ArrayBuffer;
|
|
46
|
+
/** Content type of the audio (e.g., 'audio/mpeg') */
|
|
47
|
+
contentType: string;
|
|
48
|
+
/** Character count of the input text */
|
|
49
|
+
characterCount: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Convert text to speech using the ElevenLabs API.
|
|
53
|
+
*
|
|
54
|
+
* @throws Error if ELEVENLABS_API_KEY is not set
|
|
55
|
+
* @throws Error if the API request fails
|
|
56
|
+
* @throws Error if text validation fails
|
|
57
|
+
*/
|
|
58
|
+
declare function textToSpeech(request: TtsRequest): Promise<TtsResponse>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* OpenAI Whisper STT Client for AgentForge.
|
|
62
|
+
*
|
|
63
|
+
* Sends audio data to the OpenAI Whisper transcription API.
|
|
64
|
+
* API Reference: https://platform.openai.com/docs/guides/speech-to-text
|
|
65
|
+
*/
|
|
66
|
+
interface SttRequest {
|
|
67
|
+
/** Audio data as ArrayBuffer or Uint8Array (cross-platform; no Node.js Buffer) */
|
|
68
|
+
audio: ArrayBuffer | Uint8Array;
|
|
69
|
+
/** Audio file name with extension (used for MIME type detection). Default: 'audio.ogg' */
|
|
70
|
+
fileName?: string;
|
|
71
|
+
/** Language hint (ISO-639-1 code). Optional. */
|
|
72
|
+
language?: string;
|
|
73
|
+
/** Whisper model to use. Default: 'whisper-1' */
|
|
74
|
+
model?: string;
|
|
75
|
+
}
|
|
76
|
+
interface SttResponse {
|
|
77
|
+
/** Transcribed text */
|
|
78
|
+
text: string;
|
|
79
|
+
/** Language detected or used */
|
|
80
|
+
language?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Transcribe audio to text using the OpenAI Whisper API.
|
|
84
|
+
*
|
|
85
|
+
* @throws Error if OPENAI_API_KEY is not set
|
|
86
|
+
* @throws Error if the API request fails
|
|
87
|
+
* @throws Error if audio exceeds size limit
|
|
88
|
+
*/
|
|
89
|
+
declare function speechToText(request: SttRequest): Promise<SttResponse>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create a Mastra voice tool that provides TTS and STT capabilities.
|
|
93
|
+
*
|
|
94
|
+
* @param defaultConfig - Default voice configuration for TTS
|
|
95
|
+
* @returns A Mastra tool with text-to-speech and speech-to-text actions
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { createVoiceTool } from '@agentforge-ai/tools-voice';
|
|
100
|
+
*
|
|
101
|
+
* const voiceTool = createVoiceTool({ voiceId: 'custom-voice-id' });
|
|
102
|
+
* // Register with Mastra agent
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function createVoiceTool(defaultConfig?: Partial<VoiceConfig>): _mastra_core_tools.Tool<{
|
|
106
|
+
action: "text-to-speech" | "speech-to-text";
|
|
107
|
+
voiceId?: string | undefined;
|
|
108
|
+
speed?: number | undefined;
|
|
109
|
+
language?: string | undefined;
|
|
110
|
+
text?: string | undefined;
|
|
111
|
+
audioBase64?: string | undefined;
|
|
112
|
+
fileName?: string | undefined;
|
|
113
|
+
}, {
|
|
114
|
+
action: string;
|
|
115
|
+
success: boolean;
|
|
116
|
+
contentType?: string | undefined;
|
|
117
|
+
characterCount?: number | undefined;
|
|
118
|
+
text?: string | undefined;
|
|
119
|
+
audioBase64?: string | undefined;
|
|
120
|
+
error?: string | undefined;
|
|
121
|
+
}, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "agentforge-voice", unknown>;
|
|
122
|
+
|
|
123
|
+
export { DEFAULT_VOICE_CONFIG, MAX_STT_FILE_SIZE, MAX_TTS_TEXT_LENGTH, type SttRequest, type SttResponse, type TtsRequest, type TtsResponse, type VoiceConfig, createVoiceTool, sanitizeTtsText, speechToText, textToSpeech };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// src/voice-config.ts
|
|
2
|
+
var DEFAULT_VOICE_CONFIG = {
|
|
3
|
+
voiceId: "21m00Tcm4TlvDq8ikWAM",
|
|
4
|
+
speed: 1,
|
|
5
|
+
model: "eleven_multilingual_v2",
|
|
6
|
+
provider: "elevenlabs",
|
|
7
|
+
language: "en"
|
|
8
|
+
};
|
|
9
|
+
var MAX_TTS_TEXT_LENGTH = 5e3;
|
|
10
|
+
var MAX_STT_FILE_SIZE = 25 * 1024 * 1024;
|
|
11
|
+
function sanitizeTtsText(text) {
|
|
12
|
+
if (!text || typeof text !== "string") {
|
|
13
|
+
throw new Error("TTS text must be a non-empty string");
|
|
14
|
+
}
|
|
15
|
+
const sanitized = text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "").trim();
|
|
16
|
+
if (sanitized.length === 0) {
|
|
17
|
+
throw new Error("TTS text is empty after sanitization");
|
|
18
|
+
}
|
|
19
|
+
if (sanitized.length > MAX_TTS_TEXT_LENGTH) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`TTS text exceeds maximum length of ${MAX_TTS_TEXT_LENGTH} characters (got ${sanitized.length})`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return sanitized;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/tts-client.ts
|
|
28
|
+
var ELEVENLABS_API_BASE = "https://api.elevenlabs.io/v1";
|
|
29
|
+
async function textToSpeech(request) {
|
|
30
|
+
const apiKey = process.env.ELEVENLABS_API_KEY;
|
|
31
|
+
if (!apiKey) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"ELEVENLABS_API_KEY environment variable is required for TTS. Get your key at https://elevenlabs.io"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const sanitizedText = sanitizeTtsText(request.text);
|
|
37
|
+
const config = {
|
|
38
|
+
voiceId: request.config?.voiceId ?? DEFAULT_VOICE_CONFIG.voiceId,
|
|
39
|
+
model: request.config?.model ?? DEFAULT_VOICE_CONFIG.model,
|
|
40
|
+
speed: request.config?.speed ?? DEFAULT_VOICE_CONFIG.speed,
|
|
41
|
+
language: request.config?.language ?? DEFAULT_VOICE_CONFIG.language
|
|
42
|
+
};
|
|
43
|
+
const url = `${ELEVENLABS_API_BASE}/text-to-speech/${config.voiceId}`;
|
|
44
|
+
const body = {
|
|
45
|
+
text: sanitizedText,
|
|
46
|
+
model_id: config.model,
|
|
47
|
+
voice_settings: {
|
|
48
|
+
stability: 0.5,
|
|
49
|
+
similarity_boost: 0.75,
|
|
50
|
+
speed: config.speed
|
|
51
|
+
},
|
|
52
|
+
...config.language !== "en" ? { language_code: config.language } : {}
|
|
53
|
+
};
|
|
54
|
+
const response = await fetch(url, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
"xi-api-key": apiKey,
|
|
59
|
+
"Accept": "audio/mpeg"
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify(body)
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
65
|
+
throw new Error(
|
|
66
|
+
`ElevenLabs TTS API error (${response.status}): ${errorText}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const audio = await response.arrayBuffer();
|
|
70
|
+
const contentType = response.headers.get("content-type") || "audio/mpeg";
|
|
71
|
+
return {
|
|
72
|
+
audio,
|
|
73
|
+
contentType,
|
|
74
|
+
characterCount: sanitizedText.length
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/stt-client.ts
|
|
79
|
+
var OPENAI_API_BASE = "https://api.openai.com/v1";
|
|
80
|
+
async function speechToText(request) {
|
|
81
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
82
|
+
if (!apiKey) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
"OPENAI_API_KEY environment variable is required for STT. Get your key at https://platform.openai.com"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const audioBuffer = (() => {
|
|
88
|
+
if (request.audio instanceof ArrayBuffer) return request.audio;
|
|
89
|
+
const copy = new ArrayBuffer(request.audio.byteLength);
|
|
90
|
+
new Uint8Array(copy).set(request.audio);
|
|
91
|
+
return copy;
|
|
92
|
+
})();
|
|
93
|
+
if (audioBuffer.byteLength > MAX_STT_FILE_SIZE) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Audio file exceeds maximum size of ${MAX_STT_FILE_SIZE / (1024 * 1024)}MB (got ${(audioBuffer.byteLength / (1024 * 1024)).toFixed(1)}MB)`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (audioBuffer.byteLength === 0) {
|
|
99
|
+
throw new Error("Audio data is empty");
|
|
100
|
+
}
|
|
101
|
+
const fileName = request.fileName || "audio.ogg";
|
|
102
|
+
const model = request.model || "whisper-1";
|
|
103
|
+
const blob = new Blob([audioBuffer], { type: getMimeType(fileName) });
|
|
104
|
+
const formData = new FormData();
|
|
105
|
+
formData.append("file", blob, fileName);
|
|
106
|
+
formData.append("model", model);
|
|
107
|
+
if (request.language) {
|
|
108
|
+
formData.append("language", request.language);
|
|
109
|
+
}
|
|
110
|
+
const response = await fetch(`${OPENAI_API_BASE}/audio/transcriptions`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: {
|
|
113
|
+
"Authorization": `Bearer ${apiKey}`
|
|
114
|
+
},
|
|
115
|
+
body: formData
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
119
|
+
throw new Error(
|
|
120
|
+
`OpenAI Whisper STT API error (${response.status}): ${errorText}`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const result = await response.json();
|
|
124
|
+
return {
|
|
125
|
+
text: result.text,
|
|
126
|
+
language: result.language ?? request.language
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function getMimeType(fileName) {
|
|
130
|
+
const ext = fileName.split(".").pop()?.toLowerCase();
|
|
131
|
+
const mimeMap = {
|
|
132
|
+
mp3: "audio/mpeg",
|
|
133
|
+
mp4: "audio/mp4",
|
|
134
|
+
mpeg: "audio/mpeg",
|
|
135
|
+
mpga: "audio/mpeg",
|
|
136
|
+
m4a: "audio/mp4",
|
|
137
|
+
wav: "audio/wav",
|
|
138
|
+
webm: "audio/webm",
|
|
139
|
+
ogg: "audio/ogg",
|
|
140
|
+
oga: "audio/ogg",
|
|
141
|
+
flac: "audio/flac"
|
|
142
|
+
};
|
|
143
|
+
return mimeMap[ext || ""] || "audio/ogg";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/voice-tool.ts
|
|
147
|
+
import { createTool } from "@mastra/core/tools";
|
|
148
|
+
import { z } from "zod";
|
|
149
|
+
function createVoiceTool(defaultConfig) {
|
|
150
|
+
return createTool({
|
|
151
|
+
id: "agentforge-voice",
|
|
152
|
+
description: "Voice capabilities: convert text to speech (TTS) using ElevenLabs, or transcribe speech to text (STT) using OpenAI Whisper.",
|
|
153
|
+
inputSchema: z.object({
|
|
154
|
+
action: z.enum(["text-to-speech", "speech-to-text"]).describe(
|
|
155
|
+
"The voice action to perform"
|
|
156
|
+
),
|
|
157
|
+
text: z.string().optional().describe(
|
|
158
|
+
"Text to convert to speech (required for text-to-speech action)"
|
|
159
|
+
),
|
|
160
|
+
audioBase64: z.string().optional().describe(
|
|
161
|
+
"Base64-encoded audio data (required for speech-to-text action)"
|
|
162
|
+
),
|
|
163
|
+
fileName: z.string().optional().describe(
|
|
164
|
+
'Audio file name with extension for STT (e.g., "audio.ogg")'
|
|
165
|
+
),
|
|
166
|
+
language: z.string().optional().describe(
|
|
167
|
+
'Language code (e.g., "en", "es"). Used for both TTS language and STT hint.'
|
|
168
|
+
),
|
|
169
|
+
voiceId: z.string().optional().describe(
|
|
170
|
+
"ElevenLabs voice ID override"
|
|
171
|
+
),
|
|
172
|
+
speed: z.number().min(0.5).max(2).optional().describe(
|
|
173
|
+
"Speech speed multiplier (0.5\u20132.0)"
|
|
174
|
+
)
|
|
175
|
+
}),
|
|
176
|
+
outputSchema: z.object({
|
|
177
|
+
success: z.boolean(),
|
|
178
|
+
action: z.string(),
|
|
179
|
+
text: z.string().optional(),
|
|
180
|
+
audioBase64: z.string().optional(),
|
|
181
|
+
contentType: z.string().optional(),
|
|
182
|
+
characterCount: z.number().optional(),
|
|
183
|
+
error: z.string().optional()
|
|
184
|
+
}),
|
|
185
|
+
execute: async (inputData) => {
|
|
186
|
+
try {
|
|
187
|
+
if (inputData.action === "text-to-speech") {
|
|
188
|
+
if (!inputData.text) {
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
action: "text-to-speech",
|
|
192
|
+
error: "Text is required for text-to-speech action"
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const result = await textToSpeech({
|
|
196
|
+
text: inputData.text,
|
|
197
|
+
config: {
|
|
198
|
+
...defaultConfig,
|
|
199
|
+
...inputData.voiceId ? { voiceId: inputData.voiceId } : {},
|
|
200
|
+
...inputData.speed ? { speed: inputData.speed } : {},
|
|
201
|
+
...inputData.language ? { language: inputData.language } : {}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const bytes = new Uint8Array(result.audio);
|
|
205
|
+
let binary = "";
|
|
206
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
207
|
+
binary += String.fromCharCode(bytes[i]);
|
|
208
|
+
}
|
|
209
|
+
const audioBase64 = btoa(binary);
|
|
210
|
+
return {
|
|
211
|
+
success: true,
|
|
212
|
+
action: "text-to-speech",
|
|
213
|
+
audioBase64,
|
|
214
|
+
contentType: result.contentType,
|
|
215
|
+
characterCount: result.characterCount
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (inputData.action === "speech-to-text") {
|
|
219
|
+
if (!inputData.audioBase64) {
|
|
220
|
+
return {
|
|
221
|
+
success: false,
|
|
222
|
+
action: "speech-to-text",
|
|
223
|
+
error: "audioBase64 is required for speech-to-text action"
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const binaryString = atob(inputData.audioBase64);
|
|
227
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
228
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
229
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
230
|
+
}
|
|
231
|
+
const result = await speechToText({
|
|
232
|
+
audio: bytes,
|
|
233
|
+
fileName: inputData.fileName,
|
|
234
|
+
language: inputData.language
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
success: true,
|
|
238
|
+
action: "speech-to-text",
|
|
239
|
+
text: result.text
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
success: false,
|
|
244
|
+
action: inputData.action,
|
|
245
|
+
error: `Unknown action: ${inputData.action}`
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return {
|
|
249
|
+
success: false,
|
|
250
|
+
action: inputData.action,
|
|
251
|
+
error: error instanceof Error ? error.message : String(error)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
export {
|
|
258
|
+
DEFAULT_VOICE_CONFIG,
|
|
259
|
+
MAX_STT_FILE_SIZE,
|
|
260
|
+
MAX_TTS_TEXT_LENGTH,
|
|
261
|
+
createVoiceTool,
|
|
262
|
+
sanitizeTtsText,
|
|
263
|
+
speechToText,
|
|
264
|
+
textToSpeech
|
|
265
|
+
};
|
|
266
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/voice-config.ts","../src/tts-client.ts","../src/stt-client.ts","../src/voice-tool.ts"],"sourcesContent":["/**\n * Voice configuration types for AgentForge voice tools.\n */\n\nexport interface VoiceConfig {\n /** ElevenLabs voice ID */\n voiceId?: string;\n /** Speech speed multiplier (0.5–2.0). Default: 1.0 */\n speed?: number;\n /** TTS model ID (e.g., 'eleven_multilingual_v2'). Default: 'eleven_multilingual_v2' */\n model?: string;\n /** Voice provider. Default: 'elevenlabs' */\n provider?: 'elevenlabs';\n /** Language code (e.g., 'en', 'es'). Default: 'en' */\n language?: string;\n}\n\nexport const DEFAULT_VOICE_CONFIG: Required<VoiceConfig> = {\n voiceId: '21m00Tcm4TlvDq8ikWAM',\n speed: 1.0,\n model: 'eleven_multilingual_v2',\n provider: 'elevenlabs',\n language: 'en',\n};\n\n/** Maximum text length for TTS input (ElevenLabs limit) */\nexport const MAX_TTS_TEXT_LENGTH = 5000;\n\n/** Maximum audio file size for STT (OpenAI Whisper limit: 25MB) */\nexport const MAX_STT_FILE_SIZE = 25 * 1024 * 1024;\n\n/**\n * Sanitize text input for TTS.\n * Strips control characters and trims whitespace.\n * Throws if text exceeds maximum length.\n */\nexport function sanitizeTtsText(text: string): string {\n if (!text || typeof text !== 'string') {\n throw new Error('TTS text must be a non-empty string');\n }\n\n // Strip control characters (except newline, tab)\n const sanitized = text.replace(/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]/g, '').trim();\n\n if (sanitized.length === 0) {\n throw new Error('TTS text is empty after sanitization');\n }\n\n if (sanitized.length > MAX_TTS_TEXT_LENGTH) {\n throw new Error(\n `TTS text exceeds maximum length of ${MAX_TTS_TEXT_LENGTH} characters (got ${sanitized.length})`\n );\n }\n\n return sanitized;\n}\n","/**\n * ElevenLabs TTS Client for AgentForge.\n *\n * Sends text to the ElevenLabs text-to-speech API and returns audio data.\n * API Reference: https://elevenlabs.io/docs/api-reference/text-to-speech\n */\n\nimport { DEFAULT_VOICE_CONFIG, sanitizeTtsText } from './voice-config.js';\nimport type { VoiceConfig } from './voice-config.js';\n\nconst ELEVENLABS_API_BASE = 'https://api.elevenlabs.io/v1';\n\nexport interface TtsRequest {\n /** Text to convert to speech */\n text: string;\n /** Voice configuration overrides */\n config?: Partial<VoiceConfig>;\n}\n\nexport interface TtsResponse {\n /** Audio data as ArrayBuffer */\n audio: ArrayBuffer;\n /** Content type of the audio (e.g., 'audio/mpeg') */\n contentType: string;\n /** Character count of the input text */\n characterCount: number;\n}\n\n/**\n * Convert text to speech using the ElevenLabs API.\n *\n * @throws Error if ELEVENLABS_API_KEY is not set\n * @throws Error if the API request fails\n * @throws Error if text validation fails\n */\nexport async function textToSpeech(request: TtsRequest): Promise<TtsResponse> {\n const apiKey = process.env.ELEVENLABS_API_KEY;\n if (!apiKey) {\n throw new Error(\n 'ELEVENLABS_API_KEY environment variable is required for TTS. ' +\n 'Get your key at https://elevenlabs.io'\n );\n }\n\n const sanitizedText = sanitizeTtsText(request.text);\n\n const config = {\n voiceId: request.config?.voiceId ?? DEFAULT_VOICE_CONFIG.voiceId,\n model: request.config?.model ?? DEFAULT_VOICE_CONFIG.model,\n speed: request.config?.speed ?? DEFAULT_VOICE_CONFIG.speed,\n language: request.config?.language ?? DEFAULT_VOICE_CONFIG.language,\n };\n\n const url = `${ELEVENLABS_API_BASE}/text-to-speech/${config.voiceId}`;\n\n const body = {\n text: sanitizedText,\n model_id: config.model,\n voice_settings: {\n stability: 0.5,\n similarity_boost: 0.75,\n speed: config.speed,\n },\n ...(config.language !== 'en' ? { language_code: config.language } : {}),\n };\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'xi-api-key': apiKey,\n 'Accept': 'audio/mpeg',\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => 'Unknown error');\n throw new Error(\n `ElevenLabs TTS API error (${response.status}): ${errorText}`\n );\n }\n\n const audio = await response.arrayBuffer();\n const contentType = response.headers.get('content-type') || 'audio/mpeg';\n\n return {\n audio,\n contentType,\n characterCount: sanitizedText.length,\n };\n}\n","/**\n * OpenAI Whisper STT Client for AgentForge.\n *\n * Sends audio data to the OpenAI Whisper transcription API.\n * API Reference: https://platform.openai.com/docs/guides/speech-to-text\n */\n\nimport { MAX_STT_FILE_SIZE } from './voice-config.js';\n\nconst OPENAI_API_BASE = 'https://api.openai.com/v1';\n\nexport interface SttRequest {\n /** Audio data as ArrayBuffer or Uint8Array (cross-platform; no Node.js Buffer) */\n audio: ArrayBuffer | Uint8Array;\n /** Audio file name with extension (used for MIME type detection). Default: 'audio.ogg' */\n fileName?: string;\n /** Language hint (ISO-639-1 code). Optional. */\n language?: string;\n /** Whisper model to use. Default: 'whisper-1' */\n model?: string;\n}\n\nexport interface SttResponse {\n /** Transcribed text */\n text: string;\n /** Language detected or used */\n language?: string;\n}\n\n/**\n * Transcribe audio to text using the OpenAI Whisper API.\n *\n * @throws Error if OPENAI_API_KEY is not set\n * @throws Error if the API request fails\n * @throws Error if audio exceeds size limit\n */\nexport async function speechToText(request: SttRequest): Promise<SttResponse> {\n const apiKey = process.env.OPENAI_API_KEY;\n if (!apiKey) {\n throw new Error(\n 'OPENAI_API_KEY environment variable is required for STT. ' +\n 'Get your key at https://platform.openai.com'\n );\n }\n\n // Normalize to a plain ArrayBuffer (cross-platform — no SharedArrayBuffer, no Node Buffer)\n const audioBuffer: ArrayBuffer = (() => {\n if (request.audio instanceof ArrayBuffer) return request.audio;\n const copy = new ArrayBuffer(request.audio.byteLength);\n new Uint8Array(copy).set(request.audio);\n return copy;\n })();\n\n if (audioBuffer.byteLength > MAX_STT_FILE_SIZE) {\n throw new Error(\n `Audio file exceeds maximum size of ${MAX_STT_FILE_SIZE / (1024 * 1024)}MB ` +\n `(got ${(audioBuffer.byteLength / (1024 * 1024)).toFixed(1)}MB)`\n );\n }\n\n if (audioBuffer.byteLength === 0) {\n throw new Error('Audio data is empty');\n }\n\n const fileName = request.fileName || 'audio.ogg';\n const model = request.model || 'whisper-1';\n\n // Build multipart form data\n const blob = new Blob([audioBuffer], { type: getMimeType(fileName) });\n const formData = new FormData();\n formData.append('file', blob, fileName);\n formData.append('model', model);\n\n if (request.language) {\n formData.append('language', request.language);\n }\n\n const response = await fetch(`${OPENAI_API_BASE}/audio/transcriptions`, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${apiKey}`,\n },\n body: formData,\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => 'Unknown error');\n throw new Error(\n `OpenAI Whisper STT API error (${response.status}): ${errorText}`\n );\n }\n\n const result = await response.json() as { text: string; language?: string };\n\n return {\n text: result.text,\n language: result.language ?? request.language,\n };\n}\n\nfunction getMimeType(fileName: string): string {\n const ext = fileName.split('.').pop()?.toLowerCase();\n const mimeMap: Record<string, string> = {\n mp3: 'audio/mpeg',\n mp4: 'audio/mp4',\n mpeg: 'audio/mpeg',\n mpga: 'audio/mpeg',\n m4a: 'audio/mp4',\n wav: 'audio/wav',\n webm: 'audio/webm',\n ogg: 'audio/ogg',\n oga: 'audio/ogg',\n flac: 'audio/flac',\n };\n return mimeMap[ext || ''] || 'audio/ogg';\n}\n","/**\n * Mastra Voice Tool for AgentForge.\n *\n * Wraps ElevenLabs TTS and OpenAI Whisper STT as a Mastra-compatible tool.\n */\n\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { textToSpeech } from './tts-client.js';\nimport { speechToText } from './stt-client.js';\nimport type { VoiceConfig } from './voice-config.js';\n\n/**\n * Create a Mastra voice tool that provides TTS and STT capabilities.\n *\n * @param defaultConfig - Default voice configuration for TTS\n * @returns A Mastra tool with text-to-speech and speech-to-text actions\n *\n * @example\n * ```typescript\n * import { createVoiceTool } from '@agentforge-ai/tools-voice';\n *\n * const voiceTool = createVoiceTool({ voiceId: 'custom-voice-id' });\n * // Register with Mastra agent\n * ```\n */\nexport function createVoiceTool(defaultConfig?: Partial<VoiceConfig>) {\n return createTool({\n id: 'agentforge-voice',\n description:\n 'Voice capabilities: convert text to speech (TTS) using ElevenLabs, ' +\n 'or transcribe speech to text (STT) using OpenAI Whisper.',\n inputSchema: z.object({\n action: z.enum(['text-to-speech', 'speech-to-text']).describe(\n 'The voice action to perform'\n ),\n text: z.string().optional().describe(\n 'Text to convert to speech (required for text-to-speech action)'\n ),\n audioBase64: z.string().optional().describe(\n 'Base64-encoded audio data (required for speech-to-text action)'\n ),\n fileName: z.string().optional().describe(\n 'Audio file name with extension for STT (e.g., \"audio.ogg\")'\n ),\n language: z.string().optional().describe(\n 'Language code (e.g., \"en\", \"es\"). Used for both TTS language and STT hint.'\n ),\n voiceId: z.string().optional().describe(\n 'ElevenLabs voice ID override'\n ),\n speed: z.number().min(0.5).max(2.0).optional().describe(\n 'Speech speed multiplier (0.5–2.0)'\n ),\n }),\n outputSchema: z.object({\n success: z.boolean(),\n action: z.string(),\n text: z.string().optional(),\n audioBase64: z.string().optional(),\n contentType: z.string().optional(),\n characterCount: z.number().optional(),\n error: z.string().optional(),\n }),\n execute: async (inputData) => {\n try {\n if (inputData.action === 'text-to-speech') {\n if (!inputData.text) {\n return {\n success: false,\n action: 'text-to-speech',\n error: 'Text is required for text-to-speech action',\n };\n }\n\n const result = await textToSpeech({\n text: inputData.text,\n config: {\n ...defaultConfig,\n ...(inputData.voiceId ? { voiceId: inputData.voiceId } : {}),\n ...(inputData.speed ? { speed: inputData.speed } : {}),\n ...(inputData.language ? { language: inputData.language } : {}),\n },\n });\n\n // Convert ArrayBuffer to base64 (Web Crypto-compatible, no Buffer)\n const bytes = new Uint8Array(result.audio);\n let binary = '';\n for (let i = 0; i < bytes.byteLength; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n const audioBase64 = btoa(binary);\n\n return {\n success: true,\n action: 'text-to-speech',\n audioBase64,\n contentType: result.contentType,\n characterCount: result.characterCount,\n };\n }\n\n if (inputData.action === 'speech-to-text') {\n if (!inputData.audioBase64) {\n return {\n success: false,\n action: 'speech-to-text',\n error: 'audioBase64 is required for speech-to-text action',\n };\n }\n\n // Decode base64 to Uint8Array (cross-platform — no Buffer)\n const binaryString = atob(inputData.audioBase64);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n\n const result = await speechToText({\n audio: bytes,\n fileName: inputData.fileName,\n language: inputData.language,\n });\n\n return {\n success: true,\n action: 'speech-to-text',\n text: result.text,\n };\n }\n\n return {\n success: false,\n action: inputData.action,\n error: `Unknown action: ${inputData.action}`,\n };\n } catch (error) {\n return {\n success: false,\n action: inputData.action,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n },\n });\n}\n"],"mappings":";AAiBO,IAAM,uBAA8C;AAAA,EACzD,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,UAAU;AAAA,EACV,UAAU;AACZ;AAGO,IAAM,sBAAsB;AAG5B,IAAM,oBAAoB,KAAK,OAAO;AAOtC,SAAS,gBAAgB,MAAsB;AACpD,MAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;AACrC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAGA,QAAM,YAAY,KAAK,QAAQ,qCAAqC,EAAE,EAAE,KAAK;AAE7E,MAAI,UAAU,WAAW,GAAG;AAC1B,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AAEA,MAAI,UAAU,SAAS,qBAAqB;AAC1C,UAAM,IAAI;AAAA,MACR,sCAAsC,mBAAmB,oBAAoB,UAAU,MAAM;AAAA,IAC/F;AAAA,EACF;AAEA,SAAO;AACT;;;AC7CA,IAAM,sBAAsB;AAyB5B,eAAsB,aAAa,SAA2C;AAC5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ACT;AAAA,UACF;AAGA,gBAAM,eAAe,KAAK,UAAU,WAAW;AAC/C,gBAAM,QAAQ,IAAI,WAAW,aAAa,MAAM;AAChD,mBAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,kBAAM,CAAC,IAAI,aAAa,WAAW,CAAC;AAAA,UACtC;AAEA,gBAAM,SAAS,MAAM,aAAa;AAAA,YAChC,OAAO;AAAA,YACP,UAAU,UAAU;AAAA,YACpB,UAAU,UAAU;AAAA,UACtB,CAAC;AAED,iBAAO;AAAA,YACL,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,MAAM,OAAO;AAAA,UACf;AAAA,QACF;AAEA,eAAO;AAAA,UACL,SAAS;AAAA,UACT,QAAQ,UAAU;AAAA,UAClB,OAAO,mBAAmB,UAAU,MAAM;AAAA,QAC5C;AAAA,MACF,SAAS,OAAO;AACd,eAAO;AAAA,UACL,SAAS;AAAA,UACT,QAAQ,UAAU;AAAA,UAClB,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentforge-ai/tools-voice",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Voice tools for AgentForge — ElevenLabs TTS + OpenAI Whisper STT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@mastra/core": "^1.5.0",
|
|
20
|
+
"zod": "^3.23.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsup": "^8.0.0",
|
|
24
|
+
"typescript": "^5.5.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"ai",
|
|
28
|
+
"agents",
|
|
29
|
+
"voice",
|
|
30
|
+
"tts",
|
|
31
|
+
"stt",
|
|
32
|
+
"elevenlabs",
|
|
33
|
+
"whisper",
|
|
34
|
+
"mastra"
|
|
35
|
+
],
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/Agentic-Engineering-Agency/agentforge.git",
|
|
40
|
+
"directory": "packages/tools-voice"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"clean": "rm -rf dist"
|
|
46
|
+
}
|
|
47
|
+
}
|