@livekit/agents-plugin-rime 1.0.1
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 +15 -0
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/models.cjs +17 -0
- package/dist/models.cjs.map +1 -0
- package/dist/models.d.cts +5 -0
- package/dist/models.d.ts +5 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +1 -0
- package/dist/models.js.map +1 -0
- package/dist/tts.cjs +150 -0
- package/dist/tts.cjs.map +1 -0
- package/dist/tts.d.cts +66 -0
- package/dist/tts.d.ts +66 -0
- package/dist/tts.d.ts.map +1 -0
- package/dist/tts.js +125 -0
- package/dist/tts.js.map +1 -0
- package/dist/tts.test.cjs +9 -0
- package/dist/tts.test.cjs.map +1 -0
- package/dist/tts.test.d.cts +2 -0
- package/dist/tts.test.d.ts +2 -0
- package/dist/tts.test.d.ts.map +1 -0
- package/dist/tts.test.js +8 -0
- package/dist/tts.test.js.map +1 -0
- package/package.json +54 -0
- package/src/index.ts +19 -0
- package/src/models.ts +9 -0
- package/src/tts.test.ts +11 -0
- package/src/tts.ts +172 -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 [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
3
|
+
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
-->
|
|
6
|
+
# Rime plugin for LiveKit Agents
|
|
7
|
+
|
|
8
|
+
The Agents Framework is designed for building realtime, programmable
|
|
9
|
+
participants that run on servers. Use it to create conversational, multi-modal
|
|
10
|
+
voice agents that can see, hear, and understand.
|
|
11
|
+
|
|
12
|
+
This package contains the Rime plugin, which provides high-quality text-to-speech (TTS) capabilities for voice synthesis. Refer to the
|
|
13
|
+
[documentation](https://docs.livekit.io/agents/overview/) for information on how
|
|
14
|
+
See the [repository](https://github.com/livekit/agents-js) for more information
|
|
15
|
+
about the framework as a whole.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
var import_agents = require("@livekit/agents");
|
|
19
|
+
__reExport(index_exports, require("./models.cjs"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("./tts.cjs"), module.exports);
|
|
21
|
+
class RimePlugin extends import_agents.Plugin {
|
|
22
|
+
constructor() {
|
|
23
|
+
super({
|
|
24
|
+
title: "rime",
|
|
25
|
+
version: "0.1.0",
|
|
26
|
+
package: "@livekit/agents-plugin-rime"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
import_agents.Plugin.registerPlugin(new RimePlugin());
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
...require("./models.cjs"),
|
|
34
|
+
...require("./tts.cjs")
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './models.js';\nexport * from './tts.js';\n\nclass RimePlugin extends Plugin {\n constructor() {\n super({\n title: 'rime',\n version: '0.1.0',\n package: '@livekit/agents-plugin-rime',\n });\n }\n}\n\nPlugin.registerPlugin(new RimePlugin());\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAGA,oBAAuB;AAEvB,0BAAc,wBALd;AAMA,0BAAc,qBANd;AAQA,MAAM,mBAAmB,qBAAO;AAAA,EAC9B,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,qBAAO,eAAe,IAAI,WAAW,CAAC;","names":[]}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from "@livekit/agents";
|
|
2
|
+
export * from "./models.js";
|
|
3
|
+
export * from "./tts.js";
|
|
4
|
+
class RimePlugin extends Plugin {
|
|
5
|
+
constructor() {
|
|
6
|
+
super({
|
|
7
|
+
title: "rime",
|
|
8
|
+
version: "0.1.0",
|
|
9
|
+
package: "@livekit/agents-plugin-rime"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
Plugin.registerPlugin(new RimePlugin());
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './models.js';\nexport * from './tts.js';\n\nclass RimePlugin extends Plugin {\n constructor() {\n super({\n title: 'rime',\n version: '0.1.0',\n package: '@livekit/agents-plugin-rime',\n });\n }\n}\n\nPlugin.registerPlugin(new RimePlugin());\n"],"mappings":"AAGA,SAAS,cAAc;AAEvB,cAAc;AACd,cAAc;AAEd,MAAM,mBAAmB,OAAO;AAAA,EAC9B,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,OAAO,eAAe,IAAI,WAAW,CAAC;","names":[]}
|
package/dist/models.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var models_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(models_exports);
|
|
17
|
+
//# sourceMappingURL=models.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/** Supported Rime AI TTS models */\nexport type TTSModels = 'arcana' | 'mistv2';\n\n/** Supported default languages for Rime AI TTS */\nexport type DefaultLanguages = 'eng' | 'spa' | 'fra' | 'ger';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAIA,mCAAmC;AACnC,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5C,kDAAkD;AAClD,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/tts.cjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tts_exports = {};
|
|
20
|
+
__export(tts_exports, {
|
|
21
|
+
ChunkedStream: () => ChunkedStream,
|
|
22
|
+
TTS: () => TTS
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(tts_exports);
|
|
25
|
+
var import_agents = require("@livekit/agents");
|
|
26
|
+
const RIME_BASE_URL = "https://users.rime.ai/v1/rime-tts";
|
|
27
|
+
const RIME_TTS_SAMPLE_RATE = 24e3;
|
|
28
|
+
const RIME_TTS_CHANNELS = 1;
|
|
29
|
+
function getSampleRate(opts) {
|
|
30
|
+
if ((opts == null ? void 0 : opts.samplingRate) && typeof opts.samplingRate === "number") {
|
|
31
|
+
return opts.samplingRate;
|
|
32
|
+
}
|
|
33
|
+
switch (opts == null ? void 0 : opts.modelId) {
|
|
34
|
+
case "arcana":
|
|
35
|
+
return 24e3;
|
|
36
|
+
case "mistv2":
|
|
37
|
+
return 16e3;
|
|
38
|
+
default:
|
|
39
|
+
return RIME_TTS_SAMPLE_RATE;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const defaultTTSOptions = {
|
|
43
|
+
modelId: "arcana",
|
|
44
|
+
speaker: "luna",
|
|
45
|
+
apiKey: process.env.RIME_API_KEY,
|
|
46
|
+
baseURL: RIME_BASE_URL
|
|
47
|
+
};
|
|
48
|
+
class TTS extends import_agents.tts.TTS {
|
|
49
|
+
opts;
|
|
50
|
+
label = "rime.TTS";
|
|
51
|
+
/**
|
|
52
|
+
* Create a new instance of Rime TTS.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* `apiKey` must be set to your Rime AI API key, either using the argument or by setting the
|
|
56
|
+
* `RIME_API_KEY` environmental variable.
|
|
57
|
+
*
|
|
58
|
+
* @param opts - Configuration options for the TTS instance
|
|
59
|
+
*/
|
|
60
|
+
constructor(opts = defaultTTSOptions) {
|
|
61
|
+
const sampleRate = getSampleRate(opts);
|
|
62
|
+
super(sampleRate, RIME_TTS_CHANNELS, {
|
|
63
|
+
streaming: false
|
|
64
|
+
});
|
|
65
|
+
this.opts = { ...defaultTTSOptions, ...opts };
|
|
66
|
+
if (this.opts.apiKey === void 0) {
|
|
67
|
+
throw new Error("RIME API key is required, whether as an argument or as $RIME_API_KEY");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Update TTS options after initialization
|
|
72
|
+
*
|
|
73
|
+
* @param opts - Partial options to update
|
|
74
|
+
*/
|
|
75
|
+
updateOptions(opts) {
|
|
76
|
+
this.opts = { ...this.opts, ...opts };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Synthesize text to audio using Rime AI TTS.
|
|
80
|
+
*
|
|
81
|
+
* @param text - Text to synthesize
|
|
82
|
+
* @returns A chunked stream of synthesized audio
|
|
83
|
+
*/
|
|
84
|
+
synthesize(text) {
|
|
85
|
+
return new ChunkedStream(this, text, this.opts);
|
|
86
|
+
}
|
|
87
|
+
stream() {
|
|
88
|
+
throw new Error("Streaming is not supported on RimeTTS");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class ChunkedStream extends import_agents.tts.ChunkedStream {
|
|
92
|
+
label = "rime-tts.ChunkedStream";
|
|
93
|
+
opts;
|
|
94
|
+
text;
|
|
95
|
+
/**
|
|
96
|
+
* Create a new ChunkedStream instance.
|
|
97
|
+
*
|
|
98
|
+
* @param tts - The parent TTS instance
|
|
99
|
+
* @param text - Text to synthesize
|
|
100
|
+
* @param opts - TTS configuration options
|
|
101
|
+
*/
|
|
102
|
+
constructor(tts2, text, opts) {
|
|
103
|
+
super(text, tts2);
|
|
104
|
+
this.text = text;
|
|
105
|
+
this.opts = opts;
|
|
106
|
+
}
|
|
107
|
+
async run() {
|
|
108
|
+
const requestId = (0, import_agents.shortuuid)();
|
|
109
|
+
const response = await fetch(`${this.opts.baseURL}`, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
headers: {
|
|
112
|
+
Accept: "audio/pcm",
|
|
113
|
+
Authorization: `Bearer ${this.opts.apiKey}`,
|
|
114
|
+
"Content-Type": "application/json"
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify({
|
|
117
|
+
...Object.fromEntries(
|
|
118
|
+
Object.entries(this.opts).filter(([k]) => !["apiKey", "baseURL"].includes(k))
|
|
119
|
+
),
|
|
120
|
+
text: this.text
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
throw new Error(`Rime AI TTS request failed: ${response.status} ${response.statusText}`);
|
|
125
|
+
}
|
|
126
|
+
const buffer = await response.arrayBuffer();
|
|
127
|
+
const sampleRate = getSampleRate(this.opts);
|
|
128
|
+
const audioByteStream = new import_agents.AudioByteStream(sampleRate, RIME_TTS_CHANNELS);
|
|
129
|
+
const frames = audioByteStream.write(buffer);
|
|
130
|
+
let lastFrame;
|
|
131
|
+
const sendLastFrame = (segmentId, final) => {
|
|
132
|
+
if (lastFrame) {
|
|
133
|
+
this.queue.put({ requestId, segmentId, frame: lastFrame, final });
|
|
134
|
+
lastFrame = void 0;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
for (const frame of frames) {
|
|
138
|
+
sendLastFrame(requestId, false);
|
|
139
|
+
lastFrame = frame;
|
|
140
|
+
}
|
|
141
|
+
sendLastFrame(requestId, true);
|
|
142
|
+
this.queue.close();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
ChunkedStream,
|
|
148
|
+
TTS
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=tts.cjs.map
|
package/dist/tts.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tts.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioByteStream, shortuuid, tts } from '@livekit/agents';\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport type { DefaultLanguages, TTSModels } from './models.js';\n\nconst RIME_BASE_URL = 'https://users.rime.ai/v1/rime-tts';\nconst RIME_TTS_SAMPLE_RATE = 24000;\nconst RIME_TTS_CHANNELS = 1;\n\n/**\n * Get the appropriate sample rate based on TTS options.\n *\n * @param opts - Optional TTS configuration options\n * @returns The sample rate in Hz. Returns the explicit samplingRate if provided,\n * otherwise returns model-specific defaults (24000 for arcana, 16000 for mistv2,\n * or the default RIME_TTS_SAMPLE_RATE for other models)\n */\nfunction getSampleRate(opts?: Partial<TTSOptions>): number {\n if (opts?.samplingRate && typeof opts.samplingRate === 'number') {\n return opts.samplingRate;\n }\n switch (opts?.modelId) {\n case 'arcana':\n return 24000;\n case 'mistv2':\n return 16000;\n default:\n return RIME_TTS_SAMPLE_RATE;\n }\n}\n\n/** Configuration options for Rime AI TTS */\nexport interface TTSOptions {\n speaker: string;\n modelId: TTSModels | string;\n baseURL?: string;\n apiKey?: string;\n lang?: DefaultLanguages | string;\n repetition_penalty?: number;\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n samplingRate?: number;\n speedAlpha?: number;\n pauseBetweenBrackets?: boolean;\n phonemizeBetweenBrackets?: boolean;\n inlineSpeedAlpha?: string;\n noTextNormalization?: boolean;\n saveOovs?: boolean;\n /** Additional Rime API parameters */\n [key: string]: string | number | boolean | undefined;\n}\n\nconst defaultTTSOptions: TTSOptions = {\n modelId: 'arcana',\n speaker: 'luna',\n apiKey: process.env.RIME_API_KEY,\n baseURL: RIME_BASE_URL,\n};\n\nexport class TTS extends tts.TTS {\n private opts: TTSOptions;\n label = 'rime.TTS';\n\n /**\n * Create a new instance of Rime TTS.\n *\n * @remarks\n * `apiKey` must be set to your Rime AI API key, either using the argument or by setting the\n * `RIME_API_KEY` environmental variable.\n *\n * @param opts - Configuration options for the TTS instance\n */\n\n constructor(opts: Partial<TTSOptions> = defaultTTSOptions) {\n const sampleRate = getSampleRate(opts);\n super(sampleRate, RIME_TTS_CHANNELS, {\n streaming: false,\n });\n\n this.opts = { ...defaultTTSOptions, ...opts };\n if (this.opts.apiKey === undefined) {\n throw new Error('RIME API key is required, whether as an argument or as $RIME_API_KEY');\n }\n }\n\n /**\n * Update TTS options after initialization\n *\n * @param opts - Partial options to update\n */\n updateOptions(opts: Partial<TTSOptions>) {\n this.opts = { ...this.opts, ...opts };\n }\n\n /**\n * Synthesize text to audio using Rime AI TTS.\n *\n * @param text - Text to synthesize\n * @returns A chunked stream of synthesized audio\n */\n synthesize(text: string): ChunkedStream {\n return new ChunkedStream(this, text, this.opts);\n }\n\n stream(): tts.SynthesizeStream {\n throw new Error('Streaming is not supported on RimeTTS');\n }\n}\n\nexport class ChunkedStream extends tts.ChunkedStream {\n label = 'rime-tts.ChunkedStream';\n private opts: TTSOptions;\n private text: string;\n\n /**\n * Create a new ChunkedStream instance.\n *\n * @param tts - The parent TTS instance\n * @param text - Text to synthesize\n * @param opts - TTS configuration options\n */\n constructor(tts: TTS, text: string, opts: TTSOptions) {\n super(text, tts);\n this.text = text;\n this.opts = opts;\n }\n\n protected async run() {\n const requestId = shortuuid();\n const response = await fetch(`${this.opts.baseURL}`, {\n method: 'POST',\n headers: {\n Accept: 'audio/pcm',\n Authorization: `Bearer ${this.opts.apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n ...Object.fromEntries(\n Object.entries(this.opts).filter(([k]) => !['apiKey', 'baseURL'].includes(k)),\n ),\n text: this.text,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Rime AI TTS request failed: ${response.status} ${response.statusText}`);\n }\n\n const buffer = await response.arrayBuffer();\n const sampleRate = getSampleRate(this.opts);\n const audioByteStream = new AudioByteStream(sampleRate, RIME_TTS_CHANNELS);\n const frames = audioByteStream.write(buffer);\n let lastFrame: AudioFrame | undefined;\n const sendLastFrame = (segmentId: string, final: boolean) => {\n if (lastFrame) {\n this.queue.put({ requestId, segmentId, frame: lastFrame, final });\n lastFrame = undefined;\n }\n };\n\n for (const frame of frames) {\n sendLastFrame(requestId, false);\n lastFrame = frame;\n }\n sendLastFrame(requestId, true);\n\n this.queue.close();\n }\n}\n"],"mappings":"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","names":["tts"]}
|
package/dist/tts.d.cts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { tts } from '@livekit/agents';
|
|
2
|
+
import type { DefaultLanguages, TTSModels } from './models.js';
|
|
3
|
+
/** Configuration options for Rime AI TTS */
|
|
4
|
+
export interface TTSOptions {
|
|
5
|
+
speaker: string;
|
|
6
|
+
modelId: TTSModels | string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
lang?: DefaultLanguages | string;
|
|
10
|
+
repetition_penalty?: number;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
top_p?: number;
|
|
13
|
+
max_tokens?: number;
|
|
14
|
+
samplingRate?: number;
|
|
15
|
+
speedAlpha?: number;
|
|
16
|
+
pauseBetweenBrackets?: boolean;
|
|
17
|
+
phonemizeBetweenBrackets?: boolean;
|
|
18
|
+
inlineSpeedAlpha?: string;
|
|
19
|
+
noTextNormalization?: boolean;
|
|
20
|
+
saveOovs?: boolean;
|
|
21
|
+
/** Additional Rime API parameters */
|
|
22
|
+
[key: string]: string | number | boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare class TTS extends tts.TTS {
|
|
25
|
+
private opts;
|
|
26
|
+
label: string;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new instance of Rime TTS.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* `apiKey` must be set to your Rime AI API key, either using the argument or by setting the
|
|
32
|
+
* `RIME_API_KEY` environmental variable.
|
|
33
|
+
*
|
|
34
|
+
* @param opts - Configuration options for the TTS instance
|
|
35
|
+
*/
|
|
36
|
+
constructor(opts?: Partial<TTSOptions>);
|
|
37
|
+
/**
|
|
38
|
+
* Update TTS options after initialization
|
|
39
|
+
*
|
|
40
|
+
* @param opts - Partial options to update
|
|
41
|
+
*/
|
|
42
|
+
updateOptions(opts: Partial<TTSOptions>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Synthesize text to audio using Rime AI TTS.
|
|
45
|
+
*
|
|
46
|
+
* @param text - Text to synthesize
|
|
47
|
+
* @returns A chunked stream of synthesized audio
|
|
48
|
+
*/
|
|
49
|
+
synthesize(text: string): ChunkedStream;
|
|
50
|
+
stream(): tts.SynthesizeStream;
|
|
51
|
+
}
|
|
52
|
+
export declare class ChunkedStream extends tts.ChunkedStream {
|
|
53
|
+
label: string;
|
|
54
|
+
private opts;
|
|
55
|
+
private text;
|
|
56
|
+
/**
|
|
57
|
+
* Create a new ChunkedStream instance.
|
|
58
|
+
*
|
|
59
|
+
* @param tts - The parent TTS instance
|
|
60
|
+
* @param text - Text to synthesize
|
|
61
|
+
* @param opts - TTS configuration options
|
|
62
|
+
*/
|
|
63
|
+
constructor(tts: TTS, text: string, opts: TTSOptions);
|
|
64
|
+
protected run(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=tts.d.ts.map
|
package/dist/tts.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { tts } from '@livekit/agents';
|
|
2
|
+
import type { DefaultLanguages, TTSModels } from './models.js';
|
|
3
|
+
/** Configuration options for Rime AI TTS */
|
|
4
|
+
export interface TTSOptions {
|
|
5
|
+
speaker: string;
|
|
6
|
+
modelId: TTSModels | string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
lang?: DefaultLanguages | string;
|
|
10
|
+
repetition_penalty?: number;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
top_p?: number;
|
|
13
|
+
max_tokens?: number;
|
|
14
|
+
samplingRate?: number;
|
|
15
|
+
speedAlpha?: number;
|
|
16
|
+
pauseBetweenBrackets?: boolean;
|
|
17
|
+
phonemizeBetweenBrackets?: boolean;
|
|
18
|
+
inlineSpeedAlpha?: string;
|
|
19
|
+
noTextNormalization?: boolean;
|
|
20
|
+
saveOovs?: boolean;
|
|
21
|
+
/** Additional Rime API parameters */
|
|
22
|
+
[key: string]: string | number | boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare class TTS extends tts.TTS {
|
|
25
|
+
private opts;
|
|
26
|
+
label: string;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new instance of Rime TTS.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* `apiKey` must be set to your Rime AI API key, either using the argument or by setting the
|
|
32
|
+
* `RIME_API_KEY` environmental variable.
|
|
33
|
+
*
|
|
34
|
+
* @param opts - Configuration options for the TTS instance
|
|
35
|
+
*/
|
|
36
|
+
constructor(opts?: Partial<TTSOptions>);
|
|
37
|
+
/**
|
|
38
|
+
* Update TTS options after initialization
|
|
39
|
+
*
|
|
40
|
+
* @param opts - Partial options to update
|
|
41
|
+
*/
|
|
42
|
+
updateOptions(opts: Partial<TTSOptions>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Synthesize text to audio using Rime AI TTS.
|
|
45
|
+
*
|
|
46
|
+
* @param text - Text to synthesize
|
|
47
|
+
* @returns A chunked stream of synthesized audio
|
|
48
|
+
*/
|
|
49
|
+
synthesize(text: string): ChunkedStream;
|
|
50
|
+
stream(): tts.SynthesizeStream;
|
|
51
|
+
}
|
|
52
|
+
export declare class ChunkedStream extends tts.ChunkedStream {
|
|
53
|
+
label: string;
|
|
54
|
+
private opts;
|
|
55
|
+
private text;
|
|
56
|
+
/**
|
|
57
|
+
* Create a new ChunkedStream instance.
|
|
58
|
+
*
|
|
59
|
+
* @param tts - The parent TTS instance
|
|
60
|
+
* @param text - Text to synthesize
|
|
61
|
+
* @param opts - TTS configuration options
|
|
62
|
+
*/
|
|
63
|
+
constructor(tts: TTS, text: string, opts: TTSOptions);
|
|
64
|
+
protected run(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=tts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts.d.ts","sourceRoot":"","sources":["../src/tts.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA4B/D,4CAA4C;AAC5C,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACtD;AASD,qBAAa,GAAI,SAAQ,GAAG,CAAC,GAAG;IAC9B,OAAO,CAAC,IAAI,CAAa;IACzB,KAAK,SAAc;IAEnB;;;;;;;;OAQG;gBAES,IAAI,GAAE,OAAO,CAAC,UAAU,CAAqB;IAYzD;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC;IAIvC;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;IAIvC,MAAM,IAAI,GAAG,CAAC,gBAAgB;CAG/B;AAED,qBAAa,aAAc,SAAQ,GAAG,CAAC,aAAa;IAClD,KAAK,SAA4B;IACjC,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,IAAI,CAAS;IAErB;;;;;;OAMG;gBACS,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU;cAMpC,GAAG;CAyCpB"}
|
package/dist/tts.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { AudioByteStream, shortuuid, tts } from "@livekit/agents";
|
|
2
|
+
const RIME_BASE_URL = "https://users.rime.ai/v1/rime-tts";
|
|
3
|
+
const RIME_TTS_SAMPLE_RATE = 24e3;
|
|
4
|
+
const RIME_TTS_CHANNELS = 1;
|
|
5
|
+
function getSampleRate(opts) {
|
|
6
|
+
if ((opts == null ? void 0 : opts.samplingRate) && typeof opts.samplingRate === "number") {
|
|
7
|
+
return opts.samplingRate;
|
|
8
|
+
}
|
|
9
|
+
switch (opts == null ? void 0 : opts.modelId) {
|
|
10
|
+
case "arcana":
|
|
11
|
+
return 24e3;
|
|
12
|
+
case "mistv2":
|
|
13
|
+
return 16e3;
|
|
14
|
+
default:
|
|
15
|
+
return RIME_TTS_SAMPLE_RATE;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const defaultTTSOptions = {
|
|
19
|
+
modelId: "arcana",
|
|
20
|
+
speaker: "luna",
|
|
21
|
+
apiKey: process.env.RIME_API_KEY,
|
|
22
|
+
baseURL: RIME_BASE_URL
|
|
23
|
+
};
|
|
24
|
+
class TTS extends tts.TTS {
|
|
25
|
+
opts;
|
|
26
|
+
label = "rime.TTS";
|
|
27
|
+
/**
|
|
28
|
+
* Create a new instance of Rime TTS.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* `apiKey` must be set to your Rime AI API key, either using the argument or by setting the
|
|
32
|
+
* `RIME_API_KEY` environmental variable.
|
|
33
|
+
*
|
|
34
|
+
* @param opts - Configuration options for the TTS instance
|
|
35
|
+
*/
|
|
36
|
+
constructor(opts = defaultTTSOptions) {
|
|
37
|
+
const sampleRate = getSampleRate(opts);
|
|
38
|
+
super(sampleRate, RIME_TTS_CHANNELS, {
|
|
39
|
+
streaming: false
|
|
40
|
+
});
|
|
41
|
+
this.opts = { ...defaultTTSOptions, ...opts };
|
|
42
|
+
if (this.opts.apiKey === void 0) {
|
|
43
|
+
throw new Error("RIME API key is required, whether as an argument or as $RIME_API_KEY");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Update TTS options after initialization
|
|
48
|
+
*
|
|
49
|
+
* @param opts - Partial options to update
|
|
50
|
+
*/
|
|
51
|
+
updateOptions(opts) {
|
|
52
|
+
this.opts = { ...this.opts, ...opts };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Synthesize text to audio using Rime AI TTS.
|
|
56
|
+
*
|
|
57
|
+
* @param text - Text to synthesize
|
|
58
|
+
* @returns A chunked stream of synthesized audio
|
|
59
|
+
*/
|
|
60
|
+
synthesize(text) {
|
|
61
|
+
return new ChunkedStream(this, text, this.opts);
|
|
62
|
+
}
|
|
63
|
+
stream() {
|
|
64
|
+
throw new Error("Streaming is not supported on RimeTTS");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class ChunkedStream extends tts.ChunkedStream {
|
|
68
|
+
label = "rime-tts.ChunkedStream";
|
|
69
|
+
opts;
|
|
70
|
+
text;
|
|
71
|
+
/**
|
|
72
|
+
* Create a new ChunkedStream instance.
|
|
73
|
+
*
|
|
74
|
+
* @param tts - The parent TTS instance
|
|
75
|
+
* @param text - Text to synthesize
|
|
76
|
+
* @param opts - TTS configuration options
|
|
77
|
+
*/
|
|
78
|
+
constructor(tts2, text, opts) {
|
|
79
|
+
super(text, tts2);
|
|
80
|
+
this.text = text;
|
|
81
|
+
this.opts = opts;
|
|
82
|
+
}
|
|
83
|
+
async run() {
|
|
84
|
+
const requestId = shortuuid();
|
|
85
|
+
const response = await fetch(`${this.opts.baseURL}`, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: {
|
|
88
|
+
Accept: "audio/pcm",
|
|
89
|
+
Authorization: `Bearer ${this.opts.apiKey}`,
|
|
90
|
+
"Content-Type": "application/json"
|
|
91
|
+
},
|
|
92
|
+
body: JSON.stringify({
|
|
93
|
+
...Object.fromEntries(
|
|
94
|
+
Object.entries(this.opts).filter(([k]) => !["apiKey", "baseURL"].includes(k))
|
|
95
|
+
),
|
|
96
|
+
text: this.text
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
throw new Error(`Rime AI TTS request failed: ${response.status} ${response.statusText}`);
|
|
101
|
+
}
|
|
102
|
+
const buffer = await response.arrayBuffer();
|
|
103
|
+
const sampleRate = getSampleRate(this.opts);
|
|
104
|
+
const audioByteStream = new AudioByteStream(sampleRate, RIME_TTS_CHANNELS);
|
|
105
|
+
const frames = audioByteStream.write(buffer);
|
|
106
|
+
let lastFrame;
|
|
107
|
+
const sendLastFrame = (segmentId, final) => {
|
|
108
|
+
if (lastFrame) {
|
|
109
|
+
this.queue.put({ requestId, segmentId, frame: lastFrame, final });
|
|
110
|
+
lastFrame = void 0;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
for (const frame of frames) {
|
|
114
|
+
sendLastFrame(requestId, false);
|
|
115
|
+
lastFrame = frame;
|
|
116
|
+
}
|
|
117
|
+
sendLastFrame(requestId, true);
|
|
118
|
+
this.queue.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
ChunkedStream,
|
|
123
|
+
TTS
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=tts.js.map
|
package/dist/tts.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tts.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioByteStream, shortuuid, tts } from '@livekit/agents';\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport type { DefaultLanguages, TTSModels } from './models.js';\n\nconst RIME_BASE_URL = 'https://users.rime.ai/v1/rime-tts';\nconst RIME_TTS_SAMPLE_RATE = 24000;\nconst RIME_TTS_CHANNELS = 1;\n\n/**\n * Get the appropriate sample rate based on TTS options.\n *\n * @param opts - Optional TTS configuration options\n * @returns The sample rate in Hz. Returns the explicit samplingRate if provided,\n * otherwise returns model-specific defaults (24000 for arcana, 16000 for mistv2,\n * or the default RIME_TTS_SAMPLE_RATE for other models)\n */\nfunction getSampleRate(opts?: Partial<TTSOptions>): number {\n if (opts?.samplingRate && typeof opts.samplingRate === 'number') {\n return opts.samplingRate;\n }\n switch (opts?.modelId) {\n case 'arcana':\n return 24000;\n case 'mistv2':\n return 16000;\n default:\n return RIME_TTS_SAMPLE_RATE;\n }\n}\n\n/** Configuration options for Rime AI TTS */\nexport interface TTSOptions {\n speaker: string;\n modelId: TTSModels | string;\n baseURL?: string;\n apiKey?: string;\n lang?: DefaultLanguages | string;\n repetition_penalty?: number;\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n samplingRate?: number;\n speedAlpha?: number;\n pauseBetweenBrackets?: boolean;\n phonemizeBetweenBrackets?: boolean;\n inlineSpeedAlpha?: string;\n noTextNormalization?: boolean;\n saveOovs?: boolean;\n /** Additional Rime API parameters */\n [key: string]: string | number | boolean | undefined;\n}\n\nconst defaultTTSOptions: TTSOptions = {\n modelId: 'arcana',\n speaker: 'luna',\n apiKey: process.env.RIME_API_KEY,\n baseURL: RIME_BASE_URL,\n};\n\nexport class TTS extends tts.TTS {\n private opts: TTSOptions;\n label = 'rime.TTS';\n\n /**\n * Create a new instance of Rime TTS.\n *\n * @remarks\n * `apiKey` must be set to your Rime AI API key, either using the argument or by setting the\n * `RIME_API_KEY` environmental variable.\n *\n * @param opts - Configuration options for the TTS instance\n */\n\n constructor(opts: Partial<TTSOptions> = defaultTTSOptions) {\n const sampleRate = getSampleRate(opts);\n super(sampleRate, RIME_TTS_CHANNELS, {\n streaming: false,\n });\n\n this.opts = { ...defaultTTSOptions, ...opts };\n if (this.opts.apiKey === undefined) {\n throw new Error('RIME API key is required, whether as an argument or as $RIME_API_KEY');\n }\n }\n\n /**\n * Update TTS options after initialization\n *\n * @param opts - Partial options to update\n */\n updateOptions(opts: Partial<TTSOptions>) {\n this.opts = { ...this.opts, ...opts };\n }\n\n /**\n * Synthesize text to audio using Rime AI TTS.\n *\n * @param text - Text to synthesize\n * @returns A chunked stream of synthesized audio\n */\n synthesize(text: string): ChunkedStream {\n return new ChunkedStream(this, text, this.opts);\n }\n\n stream(): tts.SynthesizeStream {\n throw new Error('Streaming is not supported on RimeTTS');\n }\n}\n\nexport class ChunkedStream extends tts.ChunkedStream {\n label = 'rime-tts.ChunkedStream';\n private opts: TTSOptions;\n private text: string;\n\n /**\n * Create a new ChunkedStream instance.\n *\n * @param tts - The parent TTS instance\n * @param text - Text to synthesize\n * @param opts - TTS configuration options\n */\n constructor(tts: TTS, text: string, opts: TTSOptions) {\n super(text, tts);\n this.text = text;\n this.opts = opts;\n }\n\n protected async run() {\n const requestId = shortuuid();\n const response = await fetch(`${this.opts.baseURL}`, {\n method: 'POST',\n headers: {\n Accept: 'audio/pcm',\n Authorization: `Bearer ${this.opts.apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n ...Object.fromEntries(\n Object.entries(this.opts).filter(([k]) => !['apiKey', 'baseURL'].includes(k)),\n ),\n text: this.text,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Rime AI TTS request failed: ${response.status} ${response.statusText}`);\n }\n\n const buffer = await response.arrayBuffer();\n const sampleRate = getSampleRate(this.opts);\n const audioByteStream = new AudioByteStream(sampleRate, RIME_TTS_CHANNELS);\n const frames = audioByteStream.write(buffer);\n let lastFrame: AudioFrame | undefined;\n const sendLastFrame = (segmentId: string, final: boolean) => {\n if (lastFrame) {\n this.queue.put({ requestId, segmentId, frame: lastFrame, final });\n lastFrame = undefined;\n }\n };\n\n for (const frame of frames) {\n sendLastFrame(requestId, false);\n lastFrame = frame;\n }\n sendLastFrame(requestId, true);\n\n this.queue.close();\n }\n}\n"],"mappings":"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","names":["tts"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_agents_plugin_openai = require("@livekit/agents-plugin-openai");
|
|
3
|
+
var import_agents_plugins_test = require("@livekit/agents-plugins-test");
|
|
4
|
+
var import_vitest = require("vitest");
|
|
5
|
+
var import_tts = require("./tts.cjs");
|
|
6
|
+
(0, import_vitest.describe)("Rime TTS", async () => {
|
|
7
|
+
await (0, import_agents_plugins_test.tts)(new import_tts.TTS(), new import_agents_plugin_openai.STT());
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=tts.test.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tts.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { STT } from '@livekit/agents-plugin-openai';\nimport { tts } from '@livekit/agents-plugins-test';\nimport { describe } from 'vitest';\nimport { TTS } from './tts.js';\n\ndescribe('Rime TTS', async () => {\n await tts(new TTS(), new STT());\n});\n"],"mappings":";AAGA,kCAAoB;AACpB,iCAAoB;AACpB,oBAAyB;AACzB,iBAAoB;AAAA,IAEpB,wBAAS,YAAY,YAAY;AAC/B,YAAM,gCAAI,IAAI,eAAI,GAAG,IAAI,gCAAI,CAAC;AAChC,CAAC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts.test.d.ts","sourceRoot":"","sources":["../src/tts.test.ts"],"names":[],"mappings":""}
|
package/dist/tts.test.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { STT } from "@livekit/agents-plugin-openai";
|
|
2
|
+
import { tts } from "@livekit/agents-plugins-test";
|
|
3
|
+
import { describe } from "vitest";
|
|
4
|
+
import { TTS } from "./tts.js";
|
|
5
|
+
describe("Rime TTS", async () => {
|
|
6
|
+
await tts(new TTS(), new STT());
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=tts.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tts.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { STT } from '@livekit/agents-plugin-openai';\nimport { tts } from '@livekit/agents-plugins-test';\nimport { describe } from 'vitest';\nimport { TTS } from './tts.js';\n\ndescribe('Rime TTS', async () => {\n await tts(new TTS(), new STT());\n});\n"],"mappings":"AAGA,SAAS,WAAW;AACpB,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,WAAW;AAEpB,SAAS,YAAY,YAAY;AAC/B,QAAM,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC;AAChC,CAAC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@livekit/agents-plugin-rime",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Rime plugin for LiveKit Node Agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"require": "dist/index.cjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "LiveKit",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"repository": "git@github.com:livekit/agents-js.git",
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@livekit/rtc-node": "^0.13.12",
|
|
29
|
+
"@microsoft/api-extractor": "^7.35.0",
|
|
30
|
+
"@types/ws": "^8.5.10",
|
|
31
|
+
"tsup": "^8.3.5",
|
|
32
|
+
"typescript": "^5.0.0",
|
|
33
|
+
"@livekit/agents": "1.0.8",
|
|
34
|
+
"@livekit/agents-plugin-openai": "1.0.8",
|
|
35
|
+
"@livekit/agents-plugin-silero": "1.0.8",
|
|
36
|
+
"@livekit/agents-plugins-test": "1.0.8"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"ws": "^8.16.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@livekit/rtc-node": "^0.13.12",
|
|
43
|
+
"@livekit/agents": "1.0.8"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup --onSuccess \"pnpm build:types\"",
|
|
47
|
+
"build:types": "tsc --declaration --emitDeclarationOnly && node ../../scripts/copyDeclarationOutput.js",
|
|
48
|
+
"clean": "rm -rf dist",
|
|
49
|
+
"clean:build": "pnpm clean && pnpm build",
|
|
50
|
+
"lint": "eslint -f unix \"src/**/*.{ts,js}\"",
|
|
51
|
+
"api:check": "api-extractor run --typescript-compiler-folder ../../node_modules/typescript",
|
|
52
|
+
"api:update": "api-extractor run --local --typescript-compiler-folder ../../node_modules/typescript --verbose"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2025 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { Plugin } from '@livekit/agents';
|
|
5
|
+
|
|
6
|
+
export * from './models.js';
|
|
7
|
+
export * from './tts.js';
|
|
8
|
+
|
|
9
|
+
class RimePlugin extends Plugin {
|
|
10
|
+
constructor() {
|
|
11
|
+
super({
|
|
12
|
+
title: 'rime',
|
|
13
|
+
version: '0.1.0',
|
|
14
|
+
package: '@livekit/agents-plugin-rime',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Plugin.registerPlugin(new RimePlugin());
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/** Supported Rime AI TTS models */
|
|
6
|
+
export type TTSModels = 'arcana' | 'mistv2';
|
|
7
|
+
|
|
8
|
+
/** Supported default languages for Rime AI TTS */
|
|
9
|
+
export type DefaultLanguages = 'eng' | 'spa' | 'fra' | 'ger';
|
package/src/tts.test.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { STT } from '@livekit/agents-plugin-openai';
|
|
5
|
+
import { tts } from '@livekit/agents-plugins-test';
|
|
6
|
+
import { describe } from 'vitest';
|
|
7
|
+
import { TTS } from './tts.js';
|
|
8
|
+
|
|
9
|
+
describe('Rime TTS', async () => {
|
|
10
|
+
await tts(new TTS(), new STT());
|
|
11
|
+
});
|
package/src/tts.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { AudioByteStream, shortuuid, tts } from '@livekit/agents';
|
|
5
|
+
import type { AudioFrame } from '@livekit/rtc-node';
|
|
6
|
+
import type { DefaultLanguages, TTSModels } from './models.js';
|
|
7
|
+
|
|
8
|
+
const RIME_BASE_URL = 'https://users.rime.ai/v1/rime-tts';
|
|
9
|
+
const RIME_TTS_SAMPLE_RATE = 24000;
|
|
10
|
+
const RIME_TTS_CHANNELS = 1;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get the appropriate sample rate based on TTS options.
|
|
14
|
+
*
|
|
15
|
+
* @param opts - Optional TTS configuration options
|
|
16
|
+
* @returns The sample rate in Hz. Returns the explicit samplingRate if provided,
|
|
17
|
+
* otherwise returns model-specific defaults (24000 for arcana, 16000 for mistv2,
|
|
18
|
+
* or the default RIME_TTS_SAMPLE_RATE for other models)
|
|
19
|
+
*/
|
|
20
|
+
function getSampleRate(opts?: Partial<TTSOptions>): number {
|
|
21
|
+
if (opts?.samplingRate && typeof opts.samplingRate === 'number') {
|
|
22
|
+
return opts.samplingRate;
|
|
23
|
+
}
|
|
24
|
+
switch (opts?.modelId) {
|
|
25
|
+
case 'arcana':
|
|
26
|
+
return 24000;
|
|
27
|
+
case 'mistv2':
|
|
28
|
+
return 16000;
|
|
29
|
+
default:
|
|
30
|
+
return RIME_TTS_SAMPLE_RATE;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Configuration options for Rime AI TTS */
|
|
35
|
+
export interface TTSOptions {
|
|
36
|
+
speaker: string;
|
|
37
|
+
modelId: TTSModels | string;
|
|
38
|
+
baseURL?: string;
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
lang?: DefaultLanguages | string;
|
|
41
|
+
repetition_penalty?: number;
|
|
42
|
+
temperature?: number;
|
|
43
|
+
top_p?: number;
|
|
44
|
+
max_tokens?: number;
|
|
45
|
+
samplingRate?: number;
|
|
46
|
+
speedAlpha?: number;
|
|
47
|
+
pauseBetweenBrackets?: boolean;
|
|
48
|
+
phonemizeBetweenBrackets?: boolean;
|
|
49
|
+
inlineSpeedAlpha?: string;
|
|
50
|
+
noTextNormalization?: boolean;
|
|
51
|
+
saveOovs?: boolean;
|
|
52
|
+
/** Additional Rime API parameters */
|
|
53
|
+
[key: string]: string | number | boolean | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const defaultTTSOptions: TTSOptions = {
|
|
57
|
+
modelId: 'arcana',
|
|
58
|
+
speaker: 'luna',
|
|
59
|
+
apiKey: process.env.RIME_API_KEY,
|
|
60
|
+
baseURL: RIME_BASE_URL,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export class TTS extends tts.TTS {
|
|
64
|
+
private opts: TTSOptions;
|
|
65
|
+
label = 'rime.TTS';
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Create a new instance of Rime TTS.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* `apiKey` must be set to your Rime AI API key, either using the argument or by setting the
|
|
72
|
+
* `RIME_API_KEY` environmental variable.
|
|
73
|
+
*
|
|
74
|
+
* @param opts - Configuration options for the TTS instance
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
constructor(opts: Partial<TTSOptions> = defaultTTSOptions) {
|
|
78
|
+
const sampleRate = getSampleRate(opts);
|
|
79
|
+
super(sampleRate, RIME_TTS_CHANNELS, {
|
|
80
|
+
streaming: false,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
this.opts = { ...defaultTTSOptions, ...opts };
|
|
84
|
+
if (this.opts.apiKey === undefined) {
|
|
85
|
+
throw new Error('RIME API key is required, whether as an argument or as $RIME_API_KEY');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Update TTS options after initialization
|
|
91
|
+
*
|
|
92
|
+
* @param opts - Partial options to update
|
|
93
|
+
*/
|
|
94
|
+
updateOptions(opts: Partial<TTSOptions>) {
|
|
95
|
+
this.opts = { ...this.opts, ...opts };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Synthesize text to audio using Rime AI TTS.
|
|
100
|
+
*
|
|
101
|
+
* @param text - Text to synthesize
|
|
102
|
+
* @returns A chunked stream of synthesized audio
|
|
103
|
+
*/
|
|
104
|
+
synthesize(text: string): ChunkedStream {
|
|
105
|
+
return new ChunkedStream(this, text, this.opts);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
stream(): tts.SynthesizeStream {
|
|
109
|
+
throw new Error('Streaming is not supported on RimeTTS');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class ChunkedStream extends tts.ChunkedStream {
|
|
114
|
+
label = 'rime-tts.ChunkedStream';
|
|
115
|
+
private opts: TTSOptions;
|
|
116
|
+
private text: string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Create a new ChunkedStream instance.
|
|
120
|
+
*
|
|
121
|
+
* @param tts - The parent TTS instance
|
|
122
|
+
* @param text - Text to synthesize
|
|
123
|
+
* @param opts - TTS configuration options
|
|
124
|
+
*/
|
|
125
|
+
constructor(tts: TTS, text: string, opts: TTSOptions) {
|
|
126
|
+
super(text, tts);
|
|
127
|
+
this.text = text;
|
|
128
|
+
this.opts = opts;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected async run() {
|
|
132
|
+
const requestId = shortuuid();
|
|
133
|
+
const response = await fetch(`${this.opts.baseURL}`, {
|
|
134
|
+
method: 'POST',
|
|
135
|
+
headers: {
|
|
136
|
+
Accept: 'audio/pcm',
|
|
137
|
+
Authorization: `Bearer ${this.opts.apiKey}`,
|
|
138
|
+
'Content-Type': 'application/json',
|
|
139
|
+
},
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
...Object.fromEntries(
|
|
142
|
+
Object.entries(this.opts).filter(([k]) => !['apiKey', 'baseURL'].includes(k)),
|
|
143
|
+
),
|
|
144
|
+
text: this.text,
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
throw new Error(`Rime AI TTS request failed: ${response.status} ${response.statusText}`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const buffer = await response.arrayBuffer();
|
|
153
|
+
const sampleRate = getSampleRate(this.opts);
|
|
154
|
+
const audioByteStream = new AudioByteStream(sampleRate, RIME_TTS_CHANNELS);
|
|
155
|
+
const frames = audioByteStream.write(buffer);
|
|
156
|
+
let lastFrame: AudioFrame | undefined;
|
|
157
|
+
const sendLastFrame = (segmentId: string, final: boolean) => {
|
|
158
|
+
if (lastFrame) {
|
|
159
|
+
this.queue.put({ requestId, segmentId, frame: lastFrame, final });
|
|
160
|
+
lastFrame = undefined;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
for (const frame of frames) {
|
|
165
|
+
sendLastFrame(requestId, false);
|
|
166
|
+
lastFrame = frame;
|
|
167
|
+
}
|
|
168
|
+
sendLastFrame(requestId, true);
|
|
169
|
+
|
|
170
|
+
this.queue.close();
|
|
171
|
+
}
|
|
172
|
+
}
|