@livekit/agents 0.5.1 → 0.6.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/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/index.cjs +2 -0
- package/dist/llm/index.cjs.map +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +2 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/llm.cjs +47 -3
- package/dist/llm/llm.cjs.map +1 -1
- package/dist/llm/llm.d.ts +15 -2
- package/dist/llm/llm.d.ts.map +1 -1
- package/dist/llm/llm.js +46 -3
- package/dist/llm/llm.js.map +1 -1
- package/dist/metrics/base.cjs +44 -0
- package/dist/metrics/base.cjs.map +1 -0
- package/dist/metrics/base.d.ts +96 -0
- package/dist/metrics/base.d.ts.map +1 -0
- package/dist/metrics/base.js +20 -0
- package/dist/metrics/base.js.map +1 -0
- package/dist/metrics/index.cjs +35 -0
- package/dist/metrics/index.cjs.map +1 -0
- package/dist/metrics/index.d.ts +5 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +9 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/usage_collector.cjs +53 -0
- package/dist/metrics/usage_collector.cjs.map +1 -0
- package/dist/metrics/usage_collector.d.ts +14 -0
- package/dist/metrics/usage_collector.d.ts.map +1 -0
- package/dist/metrics/usage_collector.js +29 -0
- package/dist/metrics/usage_collector.js.map +1 -0
- package/dist/metrics/utils.cjs +104 -0
- package/dist/metrics/utils.cjs.map +1 -0
- package/dist/metrics/utils.d.ts +10 -0
- package/dist/metrics/utils.d.ts.map +1 -0
- package/dist/metrics/utils.js +73 -0
- package/dist/metrics/utils.js.map +1 -0
- package/dist/multimodal/multimodal_agent.cjs +7 -13
- package/dist/multimodal/multimodal_agent.cjs.map +1 -1
- package/dist/multimodal/multimodal_agent.d.ts +1 -4
- package/dist/multimodal/multimodal_agent.d.ts.map +1 -1
- package/dist/multimodal/multimodal_agent.js +7 -13
- package/dist/multimodal/multimodal_agent.js.map +1 -1
- package/dist/pipeline/agent_output.cjs +9 -2
- package/dist/pipeline/agent_output.cjs.map +1 -1
- package/dist/pipeline/agent_output.d.ts +1 -0
- package/dist/pipeline/agent_output.d.ts.map +1 -1
- package/dist/pipeline/agent_output.js +9 -2
- package/dist/pipeline/agent_output.js.map +1 -1
- package/dist/pipeline/index.cjs +2 -0
- package/dist/pipeline/index.cjs.map +1 -1
- package/dist/pipeline/index.d.ts +1 -1
- package/dist/pipeline/index.d.ts.map +1 -1
- package/dist/pipeline/index.js +3 -1
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/pipeline_agent.cjs +168 -70
- package/dist/pipeline/pipeline_agent.cjs.map +1 -1
- package/dist/pipeline/pipeline_agent.d.ts +10 -4
- package/dist/pipeline/pipeline_agent.d.ts.map +1 -1
- package/dist/pipeline/pipeline_agent.js +171 -73
- package/dist/pipeline/pipeline_agent.js.map +1 -1
- package/dist/pipeline/speech_handle.cjs +49 -1
- package/dist/pipeline/speech_handle.cjs.map +1 -1
- package/dist/pipeline/speech_handle.d.ts +12 -2
- package/dist/pipeline/speech_handle.d.ts.map +1 -1
- package/dist/pipeline/speech_handle.js +50 -2
- package/dist/pipeline/speech_handle.js.map +1 -1
- package/dist/stt/index.cjs.map +1 -1
- package/dist/stt/index.d.ts +1 -1
- package/dist/stt/index.d.ts.map +1 -1
- package/dist/stt/index.js.map +1 -1
- package/dist/stt/stream_adapter.cjs +15 -5
- package/dist/stt/stream_adapter.cjs.map +1 -1
- package/dist/stt/stream_adapter.d.ts +4 -1
- package/dist/stt/stream_adapter.d.ts.map +1 -1
- package/dist/stt/stream_adapter.js +15 -5
- package/dist/stt/stream_adapter.js.map +1 -1
- package/dist/stt/stt.cjs +46 -2
- package/dist/stt/stt.cjs.map +1 -1
- package/dist/stt/stt.d.ts +25 -3
- package/dist/stt/stt.d.ts.map +1 -1
- package/dist/stt/stt.js +46 -2
- package/dist/stt/stt.js.map +1 -1
- package/dist/tts/index.cjs +4 -2
- package/dist/tts/index.cjs.map +1 -1
- package/dist/tts/index.d.ts +1 -1
- package/dist/tts/index.d.ts.map +1 -1
- package/dist/tts/index.js +3 -1
- package/dist/tts/index.js.map +1 -1
- package/dist/tts/stream_adapter.cjs +14 -3
- package/dist/tts/stream_adapter.cjs.map +1 -1
- package/dist/tts/stream_adapter.d.ts +3 -0
- package/dist/tts/stream_adapter.d.ts.map +1 -1
- package/dist/tts/stream_adapter.js +15 -4
- package/dist/tts/stream_adapter.js.map +1 -1
- package/dist/tts/tts.cjs +109 -6
- package/dist/tts/tts.cjs.map +1 -1
- package/dist/tts/tts.d.ts +24 -1
- package/dist/tts/tts.d.ts.map +1 -1
- package/dist/tts/tts.js +107 -5
- package/dist/tts/tts.js.map +1 -1
- package/dist/vad.cjs +43 -2
- package/dist/vad.cjs.map +1 -1
- package/dist/vad.d.ts +21 -4
- package/dist/vad.d.ts.map +1 -1
- package/dist/vad.js +43 -2
- package/dist/vad.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/llm/index.ts +2 -0
- package/src/llm/llm.ts +55 -3
- package/src/metrics/base.ts +127 -0
- package/src/metrics/index.ts +20 -0
- package/src/metrics/usage_collector.ts +40 -0
- package/src/metrics/utils.ts +100 -0
- package/src/multimodal/multimodal_agent.ts +12 -17
- package/src/pipeline/agent_output.ts +14 -7
- package/src/pipeline/index.ts +1 -1
- package/src/pipeline/pipeline_agent.ts +210 -95
- package/src/pipeline/speech_handle.ts +67 -2
- package/src/stt/index.ts +2 -0
- package/src/stt/stream_adapter.ts +17 -5
- package/src/stt/stt.ts +67 -3
- package/src/tts/index.ts +2 -0
- package/src/tts/stream_adapter.ts +17 -4
- package/src/tts/tts.ts +127 -4
- package/src/vad.ts +61 -4
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { SynthesizeStream, TTS } from "./tts.js";
|
|
1
|
+
import { SynthesizeStream, TTS, TTSEvent } from "./tts.js";
|
|
2
2
|
class StreamAdapter extends TTS {
|
|
3
3
|
#tts;
|
|
4
4
|
#sentenceTokenizer;
|
|
5
|
+
label;
|
|
5
6
|
constructor(tts, sentenceTokenizer) {
|
|
6
7
|
super(tts.sampleRate, tts.numChannels, { streaming: true });
|
|
7
8
|
this.#tts = tts;
|
|
8
9
|
this.#sentenceTokenizer = sentenceTokenizer;
|
|
10
|
+
this.label = this.#tts.label;
|
|
11
|
+
this.label = `tts.StreamAdapter<${this.#tts.label}>`;
|
|
12
|
+
this.#tts.on(TTSEvent.METRICS_COLLECTED, (metrics) => {
|
|
13
|
+
this.emit(TTSEvent.METRICS_COLLECTED, metrics);
|
|
14
|
+
});
|
|
9
15
|
}
|
|
10
16
|
synthesize(text) {
|
|
11
17
|
return this.#tts.synthesize(text);
|
|
@@ -17,12 +23,17 @@ class StreamAdapter extends TTS {
|
|
|
17
23
|
class StreamAdapterWrapper extends SynthesizeStream {
|
|
18
24
|
#tts;
|
|
19
25
|
#sentenceStream;
|
|
26
|
+
label;
|
|
20
27
|
constructor(tts, sentenceTokenizer) {
|
|
21
|
-
super();
|
|
28
|
+
super(tts);
|
|
22
29
|
this.#tts = tts;
|
|
23
30
|
this.#sentenceStream = sentenceTokenizer.stream();
|
|
31
|
+
this.label = `tts.StreamAdapterWrapper<${this.#tts.label}>`;
|
|
24
32
|
this.#run();
|
|
25
33
|
}
|
|
34
|
+
async monitorMetrics() {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
26
37
|
async #run() {
|
|
27
38
|
const forwardInput = async () => {
|
|
28
39
|
for await (const input of this.input) {
|
|
@@ -38,10 +49,10 @@ class StreamAdapterWrapper extends SynthesizeStream {
|
|
|
38
49
|
const synthesize = async () => {
|
|
39
50
|
for await (const ev of this.#sentenceStream) {
|
|
40
51
|
for await (const audio of this.#tts.synthesize(ev.token)) {
|
|
41
|
-
this.
|
|
52
|
+
this.output.put(audio);
|
|
42
53
|
}
|
|
43
54
|
}
|
|
44
|
-
this.
|
|
55
|
+
this.output.put(SynthesizeStream.END_OF_STREAM);
|
|
45
56
|
};
|
|
46
57
|
Promise.all([forwardInput(), synthesize()]);
|
|
47
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tts/stream_adapter.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { SentenceStream, SentenceTokenizer } from '../tokenize/index.js';\nimport type { ChunkedStream } from './tts.js';\nimport { SynthesizeStream, TTS } from './tts.js';\n\nexport class StreamAdapter extends TTS {\n #tts: TTS;\n #sentenceTokenizer: SentenceTokenizer;\n\n constructor(tts: TTS, sentenceTokenizer: SentenceTokenizer) {\n super(tts.sampleRate, tts.numChannels, { streaming: true });\n this.#tts = tts;\n this.#sentenceTokenizer = sentenceTokenizer;\n }\n\n synthesize(text: string): ChunkedStream {\n return this.#tts.synthesize(text);\n }\n\n stream(): StreamAdapterWrapper {\n return new StreamAdapterWrapper(this.#tts, this.#sentenceTokenizer);\n }\n}\n\nexport class StreamAdapterWrapper extends SynthesizeStream {\n #tts: TTS;\n #sentenceStream: SentenceStream;\n\n constructor(tts: TTS, sentenceTokenizer: SentenceTokenizer) {\n super();\n this.#tts = tts;\n this.#sentenceStream = sentenceTokenizer.stream();\n\n this.#run();\n }\n\n async #run() {\n const forwardInput = async () => {\n for await (const input of this.input) {\n if (input === SynthesizeStream.FLUSH_SENTINEL) {\n this.#sentenceStream.flush();\n } else {\n this.#sentenceStream.pushText(input);\n }\n }\n this.#sentenceStream.endInput();\n this.#sentenceStream.close();\n };\n\n const synthesize = async () => {\n for await (const ev of this.#sentenceStream) {\n for await (const audio of this.#tts.synthesize(ev.token)) {\n this.
|
|
1
|
+
{"version":3,"sources":["../../src/tts/stream_adapter.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { SentenceStream, SentenceTokenizer } from '../tokenize/index.js';\nimport type { ChunkedStream } from './tts.js';\nimport { SynthesizeStream, TTS, TTSEvent } from './tts.js';\n\nexport class StreamAdapter extends TTS {\n #tts: TTS;\n #sentenceTokenizer: SentenceTokenizer;\n label: string;\n\n constructor(tts: TTS, sentenceTokenizer: SentenceTokenizer) {\n super(tts.sampleRate, tts.numChannels, { streaming: true });\n this.#tts = tts;\n this.#sentenceTokenizer = sentenceTokenizer;\n this.label = this.#tts.label;\n this.label = `tts.StreamAdapter<${this.#tts.label}>`;\n\n this.#tts.on(TTSEvent.METRICS_COLLECTED, (metrics) => {\n this.emit(TTSEvent.METRICS_COLLECTED, metrics);\n });\n }\n\n synthesize(text: string): ChunkedStream {\n return this.#tts.synthesize(text);\n }\n\n stream(): StreamAdapterWrapper {\n return new StreamAdapterWrapper(this.#tts, this.#sentenceTokenizer);\n }\n}\n\nexport class StreamAdapterWrapper extends SynthesizeStream {\n #tts: TTS;\n #sentenceStream: SentenceStream;\n label: string;\n\n constructor(tts: TTS, sentenceTokenizer: SentenceTokenizer) {\n super(tts);\n this.#tts = tts;\n this.#sentenceStream = sentenceTokenizer.stream();\n this.label = `tts.StreamAdapterWrapper<${this.#tts.label}>`;\n\n this.#run();\n }\n\n async monitorMetrics() {\n return; // do nothing\n }\n\n async #run() {\n const forwardInput = async () => {\n for await (const input of this.input) {\n if (input === SynthesizeStream.FLUSH_SENTINEL) {\n this.#sentenceStream.flush();\n } else {\n this.#sentenceStream.pushText(input);\n }\n }\n this.#sentenceStream.endInput();\n this.#sentenceStream.close();\n };\n\n const synthesize = async () => {\n for await (const ev of this.#sentenceStream) {\n for await (const audio of this.#tts.synthesize(ev.token)) {\n this.output.put(audio);\n }\n }\n this.output.put(SynthesizeStream.END_OF_STREAM);\n };\n\n Promise.all([forwardInput(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M,KAAK,iBAAiB;AAC3C,yBAAiB,SAAS,KAAK,KAAK,WAAW,GAAG,KAAK,GAAG;AACxD,eAAK,OAAO,IAAI,KAAK;AAAA,QACvB;AAAA,MACF;AACA,WAAK,OAAO,IAAI,iBAAiB,aAAa;AAAA,IAChD;AAEA,YAAQ,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,CAAC;AAAA,EAC5C;AACF;","names":[]}
|
package/dist/tts/tts.cjs
CHANGED
|
@@ -20,15 +20,22 @@ var tts_exports = {};
|
|
|
20
20
|
__export(tts_exports, {
|
|
21
21
|
ChunkedStream: () => ChunkedStream,
|
|
22
22
|
SynthesizeStream: () => SynthesizeStream,
|
|
23
|
-
TTS: () => TTS
|
|
23
|
+
TTS: () => TTS,
|
|
24
|
+
TTSEvent: () => TTSEvent
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(tts_exports);
|
|
27
|
+
var import_node_events = require("node:events");
|
|
26
28
|
var import_utils = require("../utils.cjs");
|
|
27
|
-
|
|
29
|
+
var TTSEvent = /* @__PURE__ */ ((TTSEvent2) => {
|
|
30
|
+
TTSEvent2[TTSEvent2["METRICS_COLLECTED"] = 0] = "METRICS_COLLECTED";
|
|
31
|
+
return TTSEvent2;
|
|
32
|
+
})(TTSEvent || {});
|
|
33
|
+
class TTS extends import_node_events.EventEmitter {
|
|
28
34
|
#capabilities;
|
|
29
35
|
#sampleRate;
|
|
30
36
|
#numChannels;
|
|
31
37
|
constructor(sampleRate, numChannels, capabilities) {
|
|
38
|
+
super();
|
|
32
39
|
this.#capabilities = capabilities;
|
|
33
40
|
this.#sampleRate = sampleRate;
|
|
34
41
|
this.#numChannels = numChannels;
|
|
@@ -51,9 +58,62 @@ class SynthesizeStream {
|
|
|
51
58
|
static END_OF_STREAM = Symbol("END_OF_STREAM");
|
|
52
59
|
input = new import_utils.AsyncIterableQueue();
|
|
53
60
|
queue = new import_utils.AsyncIterableQueue();
|
|
61
|
+
output = new import_utils.AsyncIterableQueue();
|
|
54
62
|
closed = false;
|
|
63
|
+
#tts;
|
|
64
|
+
#metricsPendingTexts = [];
|
|
65
|
+
#metricsText = "";
|
|
66
|
+
#monitorMetricsTask;
|
|
67
|
+
constructor(tts) {
|
|
68
|
+
this.#tts = tts;
|
|
69
|
+
}
|
|
70
|
+
async monitorMetrics() {
|
|
71
|
+
const startTime = process.hrtime.bigint();
|
|
72
|
+
let audioDuration = 0;
|
|
73
|
+
let ttfb;
|
|
74
|
+
let requestId = "";
|
|
75
|
+
const emit = () => {
|
|
76
|
+
if (this.#metricsPendingTexts.length) {
|
|
77
|
+
const text = this.#metricsPendingTexts.shift();
|
|
78
|
+
const duration = process.hrtime.bigint() - startTime;
|
|
79
|
+
const metrics = {
|
|
80
|
+
timestamp: Date.now(),
|
|
81
|
+
requestId,
|
|
82
|
+
ttfb: Math.trunc(Number(ttfb / BigInt(1e6))),
|
|
83
|
+
duration: Math.trunc(Number(duration / BigInt(1e6))),
|
|
84
|
+
charactersCount: text.length,
|
|
85
|
+
audioDuration,
|
|
86
|
+
cancelled: false,
|
|
87
|
+
// XXX(nbsp)
|
|
88
|
+
label: this.label,
|
|
89
|
+
streamed: false
|
|
90
|
+
};
|
|
91
|
+
this.#tts.emit(0 /* METRICS_COLLECTED */, metrics);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
for await (const audio of this.queue) {
|
|
95
|
+
this.output.put(audio);
|
|
96
|
+
if (audio === SynthesizeStream.END_OF_STREAM) continue;
|
|
97
|
+
requestId = audio.requestId;
|
|
98
|
+
if (!ttfb) {
|
|
99
|
+
ttfb = process.hrtime.bigint() - startTime;
|
|
100
|
+
}
|
|
101
|
+
audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;
|
|
102
|
+
if (audio.final) {
|
|
103
|
+
emit();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (requestId) {
|
|
107
|
+
emit();
|
|
108
|
+
}
|
|
109
|
+
this.output.close();
|
|
110
|
+
}
|
|
55
111
|
/** Push a string of text to the TTS */
|
|
56
112
|
pushText(text) {
|
|
113
|
+
if (!this.#monitorMetricsTask) {
|
|
114
|
+
this.#monitorMetricsTask = this.monitorMetrics();
|
|
115
|
+
}
|
|
116
|
+
this.#metricsText += text;
|
|
57
117
|
if (this.input.closed) {
|
|
58
118
|
throw new Error("Input is closed");
|
|
59
119
|
}
|
|
@@ -64,6 +124,10 @@ class SynthesizeStream {
|
|
|
64
124
|
}
|
|
65
125
|
/** Flush the TTS, causing it to process all pending text */
|
|
66
126
|
flush() {
|
|
127
|
+
if (this.#metricsText) {
|
|
128
|
+
this.#metricsPendingTexts.push(this.#metricsText);
|
|
129
|
+
this.#metricsText = "";
|
|
130
|
+
}
|
|
67
131
|
if (this.input.closed) {
|
|
68
132
|
throw new Error("Input is closed");
|
|
69
133
|
}
|
|
@@ -83,12 +147,12 @@ class SynthesizeStream {
|
|
|
83
147
|
this.input.close();
|
|
84
148
|
}
|
|
85
149
|
next() {
|
|
86
|
-
return this.
|
|
150
|
+
return this.output.next();
|
|
87
151
|
}
|
|
88
152
|
/** Close both the input and output of the TTS stream */
|
|
89
153
|
close() {
|
|
90
154
|
this.input.close();
|
|
91
|
-
this.
|
|
155
|
+
this.output.close();
|
|
92
156
|
this.closed = true;
|
|
93
157
|
}
|
|
94
158
|
[Symbol.asyncIterator]() {
|
|
@@ -97,7 +161,44 @@ class SynthesizeStream {
|
|
|
97
161
|
}
|
|
98
162
|
class ChunkedStream {
|
|
99
163
|
queue = new import_utils.AsyncIterableQueue();
|
|
164
|
+
output = new import_utils.AsyncIterableQueue();
|
|
100
165
|
closed = false;
|
|
166
|
+
#text;
|
|
167
|
+
#tts;
|
|
168
|
+
constructor(text, tts) {
|
|
169
|
+
this.#text = text;
|
|
170
|
+
this.#tts = tts;
|
|
171
|
+
this.monitorMetrics();
|
|
172
|
+
}
|
|
173
|
+
async monitorMetrics() {
|
|
174
|
+
const startTime = process.hrtime.bigint();
|
|
175
|
+
let audioDuration = 0;
|
|
176
|
+
let ttfb;
|
|
177
|
+
let requestId = "";
|
|
178
|
+
for await (const audio of this.queue) {
|
|
179
|
+
this.output.put(audio);
|
|
180
|
+
requestId = audio.requestId;
|
|
181
|
+
if (!ttfb) {
|
|
182
|
+
ttfb = process.hrtime.bigint() - startTime;
|
|
183
|
+
}
|
|
184
|
+
audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;
|
|
185
|
+
}
|
|
186
|
+
this.output.close();
|
|
187
|
+
const duration = process.hrtime.bigint() - startTime;
|
|
188
|
+
const metrics = {
|
|
189
|
+
timestamp: Date.now(),
|
|
190
|
+
requestId,
|
|
191
|
+
ttfb: Math.trunc(Number(ttfb / BigInt(1e6))),
|
|
192
|
+
duration: Math.trunc(Number(duration / BigInt(1e6))),
|
|
193
|
+
charactersCount: this.#text.length,
|
|
194
|
+
audioDuration,
|
|
195
|
+
cancelled: false,
|
|
196
|
+
// XXX(nbsp)
|
|
197
|
+
label: this.label,
|
|
198
|
+
streamed: false
|
|
199
|
+
};
|
|
200
|
+
this.#tts.emit(0 /* METRICS_COLLECTED */, metrics);
|
|
201
|
+
}
|
|
101
202
|
/** Collect every frame into one in a single call */
|
|
102
203
|
async collect() {
|
|
103
204
|
const frames = [];
|
|
@@ -107,11 +208,12 @@ class ChunkedStream {
|
|
|
107
208
|
return (0, import_utils.mergeFrames)(frames);
|
|
108
209
|
}
|
|
109
210
|
next() {
|
|
110
|
-
return this.
|
|
211
|
+
return this.output.next();
|
|
111
212
|
}
|
|
112
213
|
/** Close both the input and output of the TTS stream */
|
|
113
214
|
close() {
|
|
114
215
|
this.queue.close();
|
|
216
|
+
this.output.close();
|
|
115
217
|
this.closed = true;
|
|
116
218
|
}
|
|
117
219
|
[Symbol.asyncIterator]() {
|
|
@@ -122,6 +224,7 @@ class ChunkedStream {
|
|
|
122
224
|
0 && (module.exports = {
|
|
123
225
|
ChunkedStream,
|
|
124
226
|
SynthesizeStream,
|
|
125
|
-
TTS
|
|
227
|
+
TTS,
|
|
228
|
+
TTSEvent
|
|
126
229
|
});
|
|
127
230
|
//# sourceMappingURL=tts.cjs.map
|
package/dist/tts/tts.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tts/tts.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport { AsyncIterableQueue, mergeFrames } from '../utils.js';\n\n/** SynthesizedAudio is a packet of speech synthesis as returned by the TTS. */\nexport interface SynthesizedAudio {\n /** Request ID (one segment could be made up of multiple requests) */\n requestId: string;\n /** Segment ID, each segment is separated by a flush */\n segmentId: string;\n /** Synthesized audio frame */\n frame: AudioFrame;\n /** Current segment of the synthesized audio */\n deltaText?: string;\n}\n\n/**\n * Describes the capabilities of the TTS provider.\n *\n * @remarks\n * At present, only `streaming` is supplied to this interface, and the framework only supports\n * providers that do have a streaming endpoint.\n */\nexport interface TTSCapabilities {\n streaming: boolean;\n}\n\n/**\n * An instance of a text-to-speech adapter.\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child TTS class, which inherits this class's methods.\n */\nexport abstract class TTS {\n #capabilities: TTSCapabilities;\n #sampleRate: number;\n #numChannels: number;\n\n constructor(sampleRate: number, numChannels: number, capabilities: TTSCapabilities) {\n this.#capabilities = capabilities;\n this.#sampleRate = sampleRate;\n this.#numChannels = numChannels;\n }\n\n /** Returns this TTS's capabilities */\n get capabilities(): TTSCapabilities {\n return this.#capabilities;\n }\n\n /** Returns the sample rate of audio frames returned by this TTS */\n get sampleRate(): number {\n return this.#sampleRate;\n }\n\n /** Returns the channel count of audio frames returned by this TTS */\n get numChannels(): number {\n return this.#numChannels;\n }\n\n /**\n * Receives text and returns synthesis in the form of a {@link ChunkedStream}\n */\n abstract synthesize(text: string): ChunkedStream;\n\n /**\n * Returns a {@link SynthesizeStream} that can be used to push text and receive audio data\n */\n abstract stream(): SynthesizeStream;\n}\n\n/**\n * An instance of a text-to-speech stream, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child SynthesizeStream class, which inherits this class's methods.\n */\nexport abstract class SynthesizeStream\n implements AsyncIterableIterator<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>\n{\n protected static readonly FLUSH_SENTINEL = Symbol('FLUSH_SENTINEL');\n static readonly END_OF_STREAM = Symbol('END_OF_STREAM');\n protected input = new AsyncIterableQueue<string | typeof SynthesizeStream.FLUSH_SENTINEL>();\n protected queue = new AsyncIterableQueue<\n SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM\n >();\n protected closed = false;\n\n /** Push a string of text to the TTS */\n pushText(text: string) {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(text);\n }\n\n /** Flush the TTS, causing it to process all pending text */\n flush() {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(SynthesizeStream.FLUSH_SENTINEL);\n }\n\n /** Mark the input as ended and forbid additional pushes */\n endInput() {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.close();\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>> {\n return this.queue.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.input.close();\n this.queue.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): SynthesizeStream {\n return this;\n }\n}\n\n/**\n * An instance of a text-to-speech response, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child ChunkedStream class, which inherits this class's methods.\n */\nexport abstract class ChunkedStream implements AsyncIterableIterator<SynthesizedAudio> {\n protected queue = new AsyncIterableQueue<SynthesizedAudio>();\n protected closed = false;\n\n /** Collect every frame into one in a single call */\n async collect(): Promise<AudioFrame> {\n const frames = [];\n for await (const event of this) {\n frames.push(event.frame);\n }\n return mergeFrames(frames);\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio>> {\n return this.queue.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.queue.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): ChunkedStream {\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAgD;AAgCzC,MAAe,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,YAAoB,aAAqB,cAA+B;AAClF,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,eAAgC;AAClC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,aAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,cAAsB;AACxB,WAAO,KAAK;AAAA,EACd;AAWF;AAgBO,MAAe,iBAEtB;AAAA,EACE,OAA0B,iBAAiB,OAAO,gBAAgB;AAAA,EAClE,OAAgB,gBAAgB,OAAO,eAAe;AAAA,EAC5C,QAAQ,IAAI,gCAAoE;AAAA,EAChF,QAAQ,IAAI,gCAEpB;AAAA,EACQ,SAAS;AAAA;AAAA,EAGnB,SAAS,MAAc;AACrB,QAAI,KAAK,MAAM,QAAQ;AACrB,YAAM,IAAI,MAAM,iBAAiB;AAAA,IACnC;AACA,QAAI,KAAK,QAAQ;AACf,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,S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License-Identifier: Apache-2.0\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';\nimport { EventEmitter } from 'node:events';\nimport type { TTSMetrics } from '../metrics/base.js';\nimport { AsyncIterableQueue, mergeFrames } from '../utils.js';\n\n/** SynthesizedAudio is a packet of speech synthesis as returned by the TTS. */\nexport interface SynthesizedAudio {\n /** Request ID (one segment could be made up of multiple requests) */\n requestId: string;\n /** Segment ID, each segment is separated by a flush */\n segmentId: string;\n /** Synthesized audio frame */\n frame: AudioFrame;\n /** Current segment of the synthesized audio */\n deltaText?: string;\n /** Whether this is the last frame of the segment (streaming only) */\n final: boolean;\n}\n\n/**\n * Describes the capabilities of the TTS provider.\n *\n * @remarks\n * At present, only `streaming` is supplied to this interface, and the framework only supports\n * providers that do have a streaming endpoint.\n */\nexport interface TTSCapabilities {\n streaming: boolean;\n}\n\nexport enum TTSEvent {\n METRICS_COLLECTED,\n}\n\nexport type TTSCallbacks = {\n [TTSEvent.METRICS_COLLECTED]: (metrics: TTSMetrics) => void;\n};\n\n/**\n * An instance of a text-to-speech adapter.\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child TTS class, which inherits this class's methods.\n */\nexport abstract class TTS extends (EventEmitter as new () => TypedEmitter<TTSCallbacks>) {\n #capabilities: TTSCapabilities;\n #sampleRate: number;\n #numChannels: number;\n abstract label: string;\n\n constructor(sampleRate: number, numChannels: number, capabilities: TTSCapabilities) {\n super();\n this.#capabilities = capabilities;\n this.#sampleRate = sampleRate;\n this.#numChannels = numChannels;\n }\n\n /** Returns this TTS's capabilities */\n get capabilities(): TTSCapabilities {\n return this.#capabilities;\n }\n\n /** Returns the sample rate of audio frames returned by this TTS */\n get sampleRate(): number {\n return this.#sampleRate;\n }\n\n /** Returns the channel count of audio frames returned by this TTS */\n get numChannels(): number {\n return this.#numChannels;\n }\n\n /**\n * Receives text and returns synthesis in the form of a {@link ChunkedStream}\n */\n abstract synthesize(text: string): ChunkedStream;\n\n /**\n * Returns a {@link SynthesizeStream} that can be used to push text and receive audio data\n */\n abstract stream(): SynthesizeStream;\n}\n\n/**\n * An instance of a text-to-speech stream, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child SynthesizeStream class, which inherits this class's methods.\n */\nexport abstract class SynthesizeStream\n implements AsyncIterableIterator<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>\n{\n protected static readonly FLUSH_SENTINEL = Symbol('FLUSH_SENTINEL');\n static readonly END_OF_STREAM = Symbol('END_OF_STREAM');\n protected input = new AsyncIterableQueue<string | typeof SynthesizeStream.FLUSH_SENTINEL>();\n protected queue = new AsyncIterableQueue<\n SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM\n >();\n protected output = new AsyncIterableQueue<\n SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM\n >();\n protected closed = false;\n abstract label: string;\n #tts: TTS;\n #metricsPendingTexts: string[] = [];\n #metricsText = '';\n #monitorMetricsTask?: Promise<void>;\n\n constructor(tts: TTS) {\n this.#tts = tts;\n }\n\n protected async monitorMetrics() {\n const startTime = process.hrtime.bigint();\n let audioDuration = 0;\n let ttfb: bigint | undefined;\n let requestId = '';\n\n const emit = () => {\n if (this.#metricsPendingTexts.length) {\n const text = this.#metricsPendingTexts.shift()!;\n const duration = process.hrtime.bigint() - startTime;\n const metrics: TTSMetrics = {\n timestamp: Date.now(),\n requestId,\n ttfb: Math.trunc(Number(ttfb! / BigInt(1000000))),\n duration: Math.trunc(Number(duration / BigInt(1000000))),\n charactersCount: text.length,\n audioDuration,\n cancelled: false, // XXX(nbsp)\n label: this.label,\n streamed: false,\n };\n this.#tts.emit(TTSEvent.METRICS_COLLECTED, metrics);\n }\n };\n\n for await (const audio of this.queue) {\n this.output.put(audio);\n if (audio === SynthesizeStream.END_OF_STREAM) continue;\n requestId = audio.requestId;\n if (!ttfb) {\n ttfb = process.hrtime.bigint() - startTime;\n }\n audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;\n if (audio.final) {\n emit();\n }\n }\n\n if (requestId) {\n emit();\n }\n this.output.close();\n }\n\n /** Push a string of text to the TTS */\n pushText(text: string) {\n if (!this.#monitorMetricsTask) {\n this.#monitorMetricsTask = this.monitorMetrics();\n }\n this.#metricsText += text;\n\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(text);\n }\n\n /** Flush the TTS, causing it to process all pending text */\n flush() {\n if (this.#metricsText) {\n this.#metricsPendingTexts.push(this.#metricsText);\n this.#metricsText = '';\n }\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(SynthesizeStream.FLUSH_SENTINEL);\n }\n\n /** Mark the input as ended and forbid additional pushes */\n endInput() {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.close();\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>> {\n return this.output.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.input.close();\n this.output.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): SynthesizeStream {\n return this;\n }\n}\n\n/**\n * An instance of a text-to-speech response, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child ChunkedStream class, which inherits this class's methods.\n */\nexport abstract class ChunkedStream implements AsyncIterableIterator<SynthesizedAudio> {\n protected queue = new AsyncIterableQueue<SynthesizedAudio>();\n protected output = new AsyncIterableQueue<SynthesizedAudio>();\n protected closed = false;\n abstract label: string;\n #text: string;\n #tts: TTS;\n\n constructor(text: string, tts: TTS) {\n this.#text = text;\n this.#tts = tts;\n\n this.monitorMetrics();\n }\n\n protected async monitorMetrics() {\n const startTime = process.hrtime.bigint();\n let audioDuration = 0;\n let ttfb: bigint | undefined;\n let requestId = '';\n\n for await (const audio of this.queue) {\n this.output.put(audio);\n requestId = audio.requestId;\n if (!ttfb) {\n ttfb = process.hrtime.bigint() - startTime;\n }\n audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;\n }\n this.output.close();\n\n const duration = process.hrtime.bigint() - startTime;\n const metrics: TTSMetrics = {\n timestamp: Date.now(),\n requestId,\n ttfb: Math.trunc(Number(ttfb! / BigInt(1000000))),\n duration: Math.trunc(Number(duration / BigInt(1000000))),\n charactersCount: this.#text.length,\n audioDuration,\n cancelled: false, // XXX(nbsp)\n label: this.label,\n streamed: false,\n };\n this.#tts.emit(TTSEvent.METRICS_COLLECTED, metrics);\n }\n\n /** Collect every frame into one in a single call */\n async collect(): Promise<AudioFrame> {\n const frames = [];\n for await (const event of this) {\n frames.push(event.frame);\n }\n return mergeFrames(frames);\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio>> {\n return this.output.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.queue.close();\n this.output.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): ChunkedStream {\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,yBAA6B;AAE7B,mBAAgD;AA2BzC,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA;AADU,SAAAA;AAAA,GAAA;AAeL,MAAe,YAAa,gCAAsD;AAAA,EACvF;AAAA,EACA;AAAA,EACA;AAAA,EAGA,YAAY,YAAoB,aAAqB,cAA+B;AAClF,UAAM;AACN,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,eAAe;A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zB;AACA,eAAO,0BAAY,MAAM;AAAA,EAC3B;AAAA,EAEA,OAAkD;AAChD,WAAO,KAAK,OAAO,KAAK;AAAA,EAC1B;AAAA;AAAA,EAGA,QAAQ;AACN,SAAK,MAAM,MAAM;AACjB,SAAK,OAAO,MAAM;AAClB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAmB;AACtC,WAAO;AAAA,EACT;AACF;","names":["TTSEvent"]}
|
package/dist/tts/tts.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { AudioFrame } from '@livekit/rtc-node';
|
|
2
|
+
import type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';
|
|
3
|
+
import type { TTSMetrics } from '../metrics/base.js';
|
|
2
4
|
import { AsyncIterableQueue } from '../utils.js';
|
|
3
5
|
/** SynthesizedAudio is a packet of speech synthesis as returned by the TTS. */
|
|
4
6
|
export interface SynthesizedAudio {
|
|
@@ -10,6 +12,8 @@ export interface SynthesizedAudio {
|
|
|
10
12
|
frame: AudioFrame;
|
|
11
13
|
/** Current segment of the synthesized audio */
|
|
12
14
|
deltaText?: string;
|
|
15
|
+
/** Whether this is the last frame of the segment (streaming only) */
|
|
16
|
+
final: boolean;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* Describes the capabilities of the TTS provider.
|
|
@@ -21,6 +25,13 @@ export interface SynthesizedAudio {
|
|
|
21
25
|
export interface TTSCapabilities {
|
|
22
26
|
streaming: boolean;
|
|
23
27
|
}
|
|
28
|
+
export declare enum TTSEvent {
|
|
29
|
+
METRICS_COLLECTED = 0
|
|
30
|
+
}
|
|
31
|
+
export type TTSCallbacks = {
|
|
32
|
+
[TTSEvent.METRICS_COLLECTED]: (metrics: TTSMetrics) => void;
|
|
33
|
+
};
|
|
34
|
+
declare const TTS_base: new () => TypedEmitter<TTSCallbacks>;
|
|
24
35
|
/**
|
|
25
36
|
* An instance of a text-to-speech adapter.
|
|
26
37
|
*
|
|
@@ -28,8 +39,9 @@ export interface TTSCapabilities {
|
|
|
28
39
|
* This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that
|
|
29
40
|
* exports its own child TTS class, which inherits this class's methods.
|
|
30
41
|
*/
|
|
31
|
-
export declare abstract class TTS {
|
|
42
|
+
export declare abstract class TTS extends TTS_base {
|
|
32
43
|
#private;
|
|
44
|
+
abstract label: string;
|
|
33
45
|
constructor(sampleRate: number, numChannels: number, capabilities: TTSCapabilities);
|
|
34
46
|
/** Returns this TTS's capabilities */
|
|
35
47
|
get capabilities(): TTSCapabilities;
|
|
@@ -61,11 +73,16 @@ export declare abstract class TTS {
|
|
|
61
73
|
* exports its own child SynthesizeStream class, which inherits this class's methods.
|
|
62
74
|
*/
|
|
63
75
|
export declare abstract class SynthesizeStream implements AsyncIterableIterator<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM> {
|
|
76
|
+
#private;
|
|
64
77
|
protected static readonly FLUSH_SENTINEL: unique symbol;
|
|
65
78
|
static readonly END_OF_STREAM: unique symbol;
|
|
66
79
|
protected input: AsyncIterableQueue<string | typeof SynthesizeStream.FLUSH_SENTINEL>;
|
|
67
80
|
protected queue: AsyncIterableQueue<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>;
|
|
81
|
+
protected output: AsyncIterableQueue<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>;
|
|
68
82
|
protected closed: boolean;
|
|
83
|
+
abstract label: string;
|
|
84
|
+
constructor(tts: TTS);
|
|
85
|
+
protected monitorMetrics(): Promise<void>;
|
|
69
86
|
/** Push a string of text to the TTS */
|
|
70
87
|
pushText(text: string): void;
|
|
71
88
|
/** Flush the TTS, causing it to process all pending text */
|
|
@@ -92,8 +109,13 @@ export declare abstract class SynthesizeStream implements AsyncIterableIterator<
|
|
|
92
109
|
* exports its own child ChunkedStream class, which inherits this class's methods.
|
|
93
110
|
*/
|
|
94
111
|
export declare abstract class ChunkedStream implements AsyncIterableIterator<SynthesizedAudio> {
|
|
112
|
+
#private;
|
|
95
113
|
protected queue: AsyncIterableQueue<SynthesizedAudio>;
|
|
114
|
+
protected output: AsyncIterableQueue<SynthesizedAudio>;
|
|
96
115
|
protected closed: boolean;
|
|
116
|
+
abstract label: string;
|
|
117
|
+
constructor(text: string, tts: TTS);
|
|
118
|
+
protected monitorMetrics(): Promise<void>;
|
|
97
119
|
/** Collect every frame into one in a single call */
|
|
98
120
|
collect(): Promise<AudioFrame>;
|
|
99
121
|
next(): Promise<IteratorResult<SynthesizedAudio>>;
|
|
@@ -101,4 +123,5 @@ export declare abstract class ChunkedStream implements AsyncIterableIterator<Syn
|
|
|
101
123
|
close(): void;
|
|
102
124
|
[Symbol.asyncIterator](): ChunkedStream;
|
|
103
125
|
}
|
|
126
|
+
export {};
|
|
104
127
|
//# sourceMappingURL=tts.d.ts.map
|
package/dist/tts/tts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tts.d.ts","sourceRoot":"","sources":["../../src/tts/tts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAe,MAAM,aAAa,CAAC;AAE9D,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,KAAK,EAAE,UAAU,CAAC;IAClB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"tts.d.ts","sourceRoot":"","sources":["../../src/tts/tts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,KAAK,EAAE,UAAU,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* @__PURE__ */ ((TTSEvent2) => {
|
|
4
|
+
TTSEvent2[TTSEvent2["METRICS_COLLECTED"] = 0] = "METRICS_COLLECTED";
|
|
5
|
+
return TTSEvent2;
|
|
6
|
+
})(TTSEvent || {});
|
|
7
|
+
class TTS extends EventEmitter {
|
|
3
8
|
#capabilities;
|
|
4
9
|
#sampleRate;
|
|
5
10
|
#numChannels;
|
|
6
11
|
constructor(sampleRate, numChannels, capabilities) {
|
|
12
|
+
super();
|
|
7
13
|
this.#capabilities = capabilities;
|
|
8
14
|
this.#sampleRate = sampleRate;
|
|
9
15
|
this.#numChannels = numChannels;
|
|
@@ -26,9 +32,62 @@ class SynthesizeStream {
|
|
|
26
32
|
static END_OF_STREAM = Symbol("END_OF_STREAM");
|
|
27
33
|
input = new AsyncIterableQueue();
|
|
28
34
|
queue = new AsyncIterableQueue();
|
|
35
|
+
output = new AsyncIterableQueue();
|
|
29
36
|
closed = false;
|
|
37
|
+
#tts;
|
|
38
|
+
#metricsPendingTexts = [];
|
|
39
|
+
#metricsText = "";
|
|
40
|
+
#monitorMetricsTask;
|
|
41
|
+
constructor(tts) {
|
|
42
|
+
this.#tts = tts;
|
|
43
|
+
}
|
|
44
|
+
async monitorMetrics() {
|
|
45
|
+
const startTime = process.hrtime.bigint();
|
|
46
|
+
let audioDuration = 0;
|
|
47
|
+
let ttfb;
|
|
48
|
+
let requestId = "";
|
|
49
|
+
const emit = () => {
|
|
50
|
+
if (this.#metricsPendingTexts.length) {
|
|
51
|
+
const text = this.#metricsPendingTexts.shift();
|
|
52
|
+
const duration = process.hrtime.bigint() - startTime;
|
|
53
|
+
const metrics = {
|
|
54
|
+
timestamp: Date.now(),
|
|
55
|
+
requestId,
|
|
56
|
+
ttfb: Math.trunc(Number(ttfb / BigInt(1e6))),
|
|
57
|
+
duration: Math.trunc(Number(duration / BigInt(1e6))),
|
|
58
|
+
charactersCount: text.length,
|
|
59
|
+
audioDuration,
|
|
60
|
+
cancelled: false,
|
|
61
|
+
// XXX(nbsp)
|
|
62
|
+
label: this.label,
|
|
63
|
+
streamed: false
|
|
64
|
+
};
|
|
65
|
+
this.#tts.emit(0 /* METRICS_COLLECTED */, metrics);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
for await (const audio of this.queue) {
|
|
69
|
+
this.output.put(audio);
|
|
70
|
+
if (audio === SynthesizeStream.END_OF_STREAM) continue;
|
|
71
|
+
requestId = audio.requestId;
|
|
72
|
+
if (!ttfb) {
|
|
73
|
+
ttfb = process.hrtime.bigint() - startTime;
|
|
74
|
+
}
|
|
75
|
+
audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;
|
|
76
|
+
if (audio.final) {
|
|
77
|
+
emit();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (requestId) {
|
|
81
|
+
emit();
|
|
82
|
+
}
|
|
83
|
+
this.output.close();
|
|
84
|
+
}
|
|
30
85
|
/** Push a string of text to the TTS */
|
|
31
86
|
pushText(text) {
|
|
87
|
+
if (!this.#monitorMetricsTask) {
|
|
88
|
+
this.#monitorMetricsTask = this.monitorMetrics();
|
|
89
|
+
}
|
|
90
|
+
this.#metricsText += text;
|
|
32
91
|
if (this.input.closed) {
|
|
33
92
|
throw new Error("Input is closed");
|
|
34
93
|
}
|
|
@@ -39,6 +98,10 @@ class SynthesizeStream {
|
|
|
39
98
|
}
|
|
40
99
|
/** Flush the TTS, causing it to process all pending text */
|
|
41
100
|
flush() {
|
|
101
|
+
if (this.#metricsText) {
|
|
102
|
+
this.#metricsPendingTexts.push(this.#metricsText);
|
|
103
|
+
this.#metricsText = "";
|
|
104
|
+
}
|
|
42
105
|
if (this.input.closed) {
|
|
43
106
|
throw new Error("Input is closed");
|
|
44
107
|
}
|
|
@@ -58,12 +121,12 @@ class SynthesizeStream {
|
|
|
58
121
|
this.input.close();
|
|
59
122
|
}
|
|
60
123
|
next() {
|
|
61
|
-
return this.
|
|
124
|
+
return this.output.next();
|
|
62
125
|
}
|
|
63
126
|
/** Close both the input and output of the TTS stream */
|
|
64
127
|
close() {
|
|
65
128
|
this.input.close();
|
|
66
|
-
this.
|
|
129
|
+
this.output.close();
|
|
67
130
|
this.closed = true;
|
|
68
131
|
}
|
|
69
132
|
[Symbol.asyncIterator]() {
|
|
@@ -72,7 +135,44 @@ class SynthesizeStream {
|
|
|
72
135
|
}
|
|
73
136
|
class ChunkedStream {
|
|
74
137
|
queue = new AsyncIterableQueue();
|
|
138
|
+
output = new AsyncIterableQueue();
|
|
75
139
|
closed = false;
|
|
140
|
+
#text;
|
|
141
|
+
#tts;
|
|
142
|
+
constructor(text, tts) {
|
|
143
|
+
this.#text = text;
|
|
144
|
+
this.#tts = tts;
|
|
145
|
+
this.monitorMetrics();
|
|
146
|
+
}
|
|
147
|
+
async monitorMetrics() {
|
|
148
|
+
const startTime = process.hrtime.bigint();
|
|
149
|
+
let audioDuration = 0;
|
|
150
|
+
let ttfb;
|
|
151
|
+
let requestId = "";
|
|
152
|
+
for await (const audio of this.queue) {
|
|
153
|
+
this.output.put(audio);
|
|
154
|
+
requestId = audio.requestId;
|
|
155
|
+
if (!ttfb) {
|
|
156
|
+
ttfb = process.hrtime.bigint() - startTime;
|
|
157
|
+
}
|
|
158
|
+
audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;
|
|
159
|
+
}
|
|
160
|
+
this.output.close();
|
|
161
|
+
const duration = process.hrtime.bigint() - startTime;
|
|
162
|
+
const metrics = {
|
|
163
|
+
timestamp: Date.now(),
|
|
164
|
+
requestId,
|
|
165
|
+
ttfb: Math.trunc(Number(ttfb / BigInt(1e6))),
|
|
166
|
+
duration: Math.trunc(Number(duration / BigInt(1e6))),
|
|
167
|
+
charactersCount: this.#text.length,
|
|
168
|
+
audioDuration,
|
|
169
|
+
cancelled: false,
|
|
170
|
+
// XXX(nbsp)
|
|
171
|
+
label: this.label,
|
|
172
|
+
streamed: false
|
|
173
|
+
};
|
|
174
|
+
this.#tts.emit(0 /* METRICS_COLLECTED */, metrics);
|
|
175
|
+
}
|
|
76
176
|
/** Collect every frame into one in a single call */
|
|
77
177
|
async collect() {
|
|
78
178
|
const frames = [];
|
|
@@ -82,11 +182,12 @@ class ChunkedStream {
|
|
|
82
182
|
return mergeFrames(frames);
|
|
83
183
|
}
|
|
84
184
|
next() {
|
|
85
|
-
return this.
|
|
185
|
+
return this.output.next();
|
|
86
186
|
}
|
|
87
187
|
/** Close both the input and output of the TTS stream */
|
|
88
188
|
close() {
|
|
89
189
|
this.queue.close();
|
|
190
|
+
this.output.close();
|
|
90
191
|
this.closed = true;
|
|
91
192
|
}
|
|
92
193
|
[Symbol.asyncIterator]() {
|
|
@@ -96,6 +197,7 @@ class ChunkedStream {
|
|
|
96
197
|
export {
|
|
97
198
|
ChunkedStream,
|
|
98
199
|
SynthesizeStream,
|
|
99
|
-
TTS
|
|
200
|
+
TTS,
|
|
201
|
+
TTSEvent
|
|
100
202
|
};
|
|
101
203
|
//# sourceMappingURL=tts.js.map
|
package/dist/tts/tts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tts/tts.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport { AsyncIterableQueue, mergeFrames } from '../utils.js';\n\n/** SynthesizedAudio is a packet of speech synthesis as returned by the TTS. */\nexport interface SynthesizedAudio {\n /** Request ID (one segment could be made up of multiple requests) */\n requestId: string;\n /** Segment ID, each segment is separated by a flush */\n segmentId: string;\n /** Synthesized audio frame */\n frame: AudioFrame;\n /** Current segment of the synthesized audio */\n deltaText?: string;\n}\n\n/**\n * Describes the capabilities of the TTS provider.\n *\n * @remarks\n * At present, only `streaming` is supplied to this interface, and the framework only supports\n * providers that do have a streaming endpoint.\n */\nexport interface TTSCapabilities {\n streaming: boolean;\n}\n\n/**\n * An instance of a text-to-speech adapter.\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child TTS class, which inherits this class's methods.\n */\nexport abstract class TTS {\n #capabilities: TTSCapabilities;\n #sampleRate: number;\n #numChannels: number;\n\n constructor(sampleRate: number, numChannels: number, capabilities: TTSCapabilities) {\n this.#capabilities = capabilities;\n this.#sampleRate = sampleRate;\n this.#numChannels = numChannels;\n }\n\n /** Returns this TTS's capabilities */\n get capabilities(): TTSCapabilities {\n return this.#capabilities;\n }\n\n /** Returns the sample rate of audio frames returned by this TTS */\n get sampleRate(): number {\n return this.#sampleRate;\n }\n\n /** Returns the channel count of audio frames returned by this TTS */\n get numChannels(): number {\n return this.#numChannels;\n }\n\n /**\n * Receives text and returns synthesis in the form of a {@link ChunkedStream}\n */\n abstract synthesize(text: string): ChunkedStream;\n\n /**\n * Returns a {@link SynthesizeStream} that can be used to push text and receive audio data\n */\n abstract stream(): SynthesizeStream;\n}\n\n/**\n * An instance of a text-to-speech stream, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child SynthesizeStream class, which inherits this class's methods.\n */\nexport abstract class SynthesizeStream\n implements AsyncIterableIterator<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>\n{\n protected static readonly FLUSH_SENTINEL = Symbol('FLUSH_SENTINEL');\n static readonly END_OF_STREAM = Symbol('END_OF_STREAM');\n protected input = new AsyncIterableQueue<string | typeof SynthesizeStream.FLUSH_SENTINEL>();\n protected queue = new AsyncIterableQueue<\n SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM\n >();\n protected closed = false;\n\n /** Push a string of text to the TTS */\n pushText(text: string) {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(text);\n }\n\n /** Flush the TTS, causing it to process all pending text */\n flush() {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(SynthesizeStream.FLUSH_SENTINEL);\n }\n\n /** Mark the input as ended and forbid additional pushes */\n endInput() {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.close();\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>> {\n return this.queue.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.input.close();\n this.queue.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): SynthesizeStream {\n return this;\n }\n}\n\n/**\n * An instance of a text-to-speech response, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child ChunkedStream class, which inherits this class's methods.\n */\nexport abstract class ChunkedStream implements AsyncIterableIterator<SynthesizedAudio> {\n protected queue = new AsyncIterableQueue<SynthesizedAudio>();\n protected closed = false;\n\n /** Collect every frame into one in a single call */\n async collect(): Promise<AudioFrame> {\n const frames = [];\n for await (const event of this) {\n frames.push(event.frame);\n }\n return mergeFrames(frames);\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio>> {\n return this.queue.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.queue.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): ChunkedStream {\n return this;\n }\n}\n"],"mappings":"AAIA,SAAS,oBAAoB,mBAAmB;AAgCzC,MAAe,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,YAAoB,aAAqB,cAA+B;AAClF,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,eAAgC;AAClC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAA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A;AAAA,EAGnB,MAAM,UAA+B;AACnC,UAAM,SAAS,CAAC;AAChB,qBAAiB,SAAS,MAAM;AAC9B,aAAO,KAAK,MAAM,KAAK;AAAA,IACzB;AACA,WAAO,YAAY,MAAM;AAAA,EAC3B;AAAA,EAEA,OAAkD;AAChD,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA;AAAA,EAGA,QAAQ;AACN,SAAK,MAAM,MAAM;AACjB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAmB;AACtC,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/tts/tts.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AudioFrame } from '@livekit/rtc-node';\nimport type { TypedEventEmitter as TypedEmitter } from '@livekit/typed-emitter';\nimport { EventEmitter } from 'node:events';\nimport type { TTSMetrics } from '../metrics/base.js';\nimport { AsyncIterableQueue, mergeFrames } from '../utils.js';\n\n/** SynthesizedAudio is a packet of speech synthesis as returned by the TTS. */\nexport interface SynthesizedAudio {\n /** Request ID (one segment could be made up of multiple requests) */\n requestId: string;\n /** Segment ID, each segment is separated by a flush */\n segmentId: string;\n /** Synthesized audio frame */\n frame: AudioFrame;\n /** Current segment of the synthesized audio */\n deltaText?: string;\n /** Whether this is the last frame of the segment (streaming only) */\n final: boolean;\n}\n\n/**\n * Describes the capabilities of the TTS provider.\n *\n * @remarks\n * At present, only `streaming` is supplied to this interface, and the framework only supports\n * providers that do have a streaming endpoint.\n */\nexport interface TTSCapabilities {\n streaming: boolean;\n}\n\nexport enum TTSEvent {\n METRICS_COLLECTED,\n}\n\nexport type TTSCallbacks = {\n [TTSEvent.METRICS_COLLECTED]: (metrics: TTSMetrics) => void;\n};\n\n/**\n * An instance of a text-to-speech adapter.\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child TTS class, which inherits this class's methods.\n */\nexport abstract class TTS extends (EventEmitter as new () => TypedEmitter<TTSCallbacks>) {\n #capabilities: TTSCapabilities;\n #sampleRate: number;\n #numChannels: number;\n abstract label: string;\n\n constructor(sampleRate: number, numChannels: number, capabilities: TTSCapabilities) {\n super();\n this.#capabilities = capabilities;\n this.#sampleRate = sampleRate;\n this.#numChannels = numChannels;\n }\n\n /** Returns this TTS's capabilities */\n get capabilities(): TTSCapabilities {\n return this.#capabilities;\n }\n\n /** Returns the sample rate of audio frames returned by this TTS */\n get sampleRate(): number {\n return this.#sampleRate;\n }\n\n /** Returns the channel count of audio frames returned by this TTS */\n get numChannels(): number {\n return this.#numChannels;\n }\n\n /**\n * Receives text and returns synthesis in the form of a {@link ChunkedStream}\n */\n abstract synthesize(text: string): ChunkedStream;\n\n /**\n * Returns a {@link SynthesizeStream} that can be used to push text and receive audio data\n */\n abstract stream(): SynthesizeStream;\n}\n\n/**\n * An instance of a text-to-speech stream, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child SynthesizeStream class, which inherits this class's methods.\n */\nexport abstract class SynthesizeStream\n implements AsyncIterableIterator<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>\n{\n protected static readonly FLUSH_SENTINEL = Symbol('FLUSH_SENTINEL');\n static readonly END_OF_STREAM = Symbol('END_OF_STREAM');\n protected input = new AsyncIterableQueue<string | typeof SynthesizeStream.FLUSH_SENTINEL>();\n protected queue = new AsyncIterableQueue<\n SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM\n >();\n protected output = new AsyncIterableQueue<\n SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM\n >();\n protected closed = false;\n abstract label: string;\n #tts: TTS;\n #metricsPendingTexts: string[] = [];\n #metricsText = '';\n #monitorMetricsTask?: Promise<void>;\n\n constructor(tts: TTS) {\n this.#tts = tts;\n }\n\n protected async monitorMetrics() {\n const startTime = process.hrtime.bigint();\n let audioDuration = 0;\n let ttfb: bigint | undefined;\n let requestId = '';\n\n const emit = () => {\n if (this.#metricsPendingTexts.length) {\n const text = this.#metricsPendingTexts.shift()!;\n const duration = process.hrtime.bigint() - startTime;\n const metrics: TTSMetrics = {\n timestamp: Date.now(),\n requestId,\n ttfb: Math.trunc(Number(ttfb! / BigInt(1000000))),\n duration: Math.trunc(Number(duration / BigInt(1000000))),\n charactersCount: text.length,\n audioDuration,\n cancelled: false, // XXX(nbsp)\n label: this.label,\n streamed: false,\n };\n this.#tts.emit(TTSEvent.METRICS_COLLECTED, metrics);\n }\n };\n\n for await (const audio of this.queue) {\n this.output.put(audio);\n if (audio === SynthesizeStream.END_OF_STREAM) continue;\n requestId = audio.requestId;\n if (!ttfb) {\n ttfb = process.hrtime.bigint() - startTime;\n }\n audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;\n if (audio.final) {\n emit();\n }\n }\n\n if (requestId) {\n emit();\n }\n this.output.close();\n }\n\n /** Push a string of text to the TTS */\n pushText(text: string) {\n if (!this.#monitorMetricsTask) {\n this.#monitorMetricsTask = this.monitorMetrics();\n }\n this.#metricsText += text;\n\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(text);\n }\n\n /** Flush the TTS, causing it to process all pending text */\n flush() {\n if (this.#metricsText) {\n this.#metricsPendingTexts.push(this.#metricsText);\n this.#metricsText = '';\n }\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.put(SynthesizeStream.FLUSH_SENTINEL);\n }\n\n /** Mark the input as ended and forbid additional pushes */\n endInput() {\n if (this.input.closed) {\n throw new Error('Input is closed');\n }\n if (this.closed) {\n throw new Error('Stream is closed');\n }\n this.input.close();\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio | typeof SynthesizeStream.END_OF_STREAM>> {\n return this.output.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.input.close();\n this.output.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): SynthesizeStream {\n return this;\n }\n}\n\n/**\n * An instance of a text-to-speech response, as an asynchronous iterable iterator.\n *\n * @example Looping through frames\n * ```ts\n * for await (const event of stream) {\n * await source.captureFrame(event.frame);\n * }\n * ```\n *\n * @remarks\n * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that\n * exports its own child ChunkedStream class, which inherits this class's methods.\n */\nexport abstract class ChunkedStream implements AsyncIterableIterator<SynthesizedAudio> {\n protected queue = new AsyncIterableQueue<SynthesizedAudio>();\n protected output = new AsyncIterableQueue<SynthesizedAudio>();\n protected closed = false;\n abstract label: string;\n #text: string;\n #tts: TTS;\n\n constructor(text: string, tts: TTS) {\n this.#text = text;\n this.#tts = tts;\n\n this.monitorMetrics();\n }\n\n protected async monitorMetrics() {\n const startTime = process.hrtime.bigint();\n let audioDuration = 0;\n let ttfb: bigint | undefined;\n let requestId = '';\n\n for await (const audio of this.queue) {\n this.output.put(audio);\n requestId = audio.requestId;\n if (!ttfb) {\n ttfb = process.hrtime.bigint() - startTime;\n }\n audioDuration += audio.frame.samplesPerChannel / audio.frame.sampleRate;\n }\n this.output.close();\n\n const duration = process.hrtime.bigint() - startTime;\n const metrics: TTSMetrics = {\n timestamp: Date.now(),\n requestId,\n ttfb: Math.trunc(Number(ttfb! / BigInt(1000000))),\n duration: Math.trunc(Number(duration / BigInt(1000000))),\n charactersCount: this.#text.length,\n audioDuration,\n cancelled: false, // XXX(nbsp)\n label: this.label,\n streamed: false,\n };\n this.#tts.emit(TTSEvent.METRICS_COLLECTED, metrics);\n }\n\n /** Collect every frame into one in a single call */\n async collect(): Promise<AudioFrame> {\n const frames = [];\n for await (const event of this) {\n frames.push(event.frame);\n }\n return mergeFrames(frames);\n }\n\n next(): Promise<IteratorResult<SynthesizedAudio>> {\n return this.output.next();\n }\n\n /** Close both the input and output of the TTS stream */\n close() {\n this.queue.close();\n this.output.close();\n this.closed = true;\n }\n\n [Symbol.asyncIterator](): ChunkedStream {\n return this;\n }\n}\n"],"mappings":"AAKA,SAAS,oBAAoB;AAE7B,SAAS,oBAAoB,mBAAmB;AA2BzC,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA;AADU,SAAAA;AAAA,GAAA;AAeL,MAAe,YAAa,aAAsD;AAAA,EACvF;AAAA,EACA;AAAA,EACA;AAAA,EAGA,YAAY,YAAoB,aAAqB,cAA+B;AAClF,UAAM;AACN,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,eAAgC;AAClC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,aAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,cAAsB;AACxB,WAAO,KAAK;AAAA,EACd;AAWF;AAgBO,MAAe,iBAEtB;AAAA,EACE,OAA0B,iBAAiB,OAAO,gBAAgB;AAAA,EAClE,OAAgB,gBAAgB,OAAO,eAAe;AAAA,EAC5C,QAAQ,IAAI,mBAAoE;AAAA,EAChF,QAAQ,IAAI,mBAEpB;AAAA,EACQ,SAAS,IAAI,mBAErB;AAAA,EACQ,SAAS;AAAA,EAEnB;AAAA,EACA,uBAAiC,CAAC;AAAA,EAClC,eAAe;AAAA,EACf;AAAA,EAEA,YAAY,KAAU;AACpB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAgB,iBAAiB;AAC/B,UAAM,YAAY,QAAQ,OAAO,OAAO;AACxC,QAAI,gBAAgB;AACpB,QAAI;AACJ,QAAI,YAAY;AAEhB,UAAM,OAAO,MAAM;AACjB,UAAI,KAAK,qBAAqB,QAAQ;AACpC,cAAM,OAAO,KAAK,qBAAqB,MAAM;AAC7C,cAAM,WAAW,QAAQ,OAAO,OAAO,IAAI;AAC3C,cAAM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