@livekit/agents 0.4.5 → 0.5.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/README.md +17 -0
- package/dist/audio.cjs +77 -0
- package/dist/audio.cjs.map +1 -0
- package/dist/audio.js +48 -37
- package/dist/audio.js.map +1 -1
- package/dist/cli.cjs +131 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +96 -122
- package/dist/cli.js.map +1 -1
- package/dist/generator.cjs +36 -0
- package/dist/generator.cjs.map +1 -0
- package/dist/generator.js +8 -22
- package/dist/generator.js.map +1 -1
- package/dist/http_server.cjs +72 -0
- package/dist/http_server.cjs.map +1 -0
- package/dist/http_server.d.ts +1 -1
- package/dist/http_server.js +44 -47
- package/dist/http_server.js.map +1 -1
- package/dist/index.cjs +78 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +26 -28
- package/dist/index.js.map +1 -1
- package/dist/ipc/job_executor.cjs +33 -0
- package/dist/ipc/job_executor.cjs.map +1 -0
- package/dist/ipc/job_executor.js +7 -4
- package/dist/ipc/job_executor.js.map +1 -1
- package/dist/ipc/job_main.cjs +147 -0
- package/dist/ipc/job_main.cjs.map +1 -0
- package/dist/ipc/job_main.d.ts +1 -1
- package/dist/ipc/job_main.js +103 -103
- package/dist/ipc/job_main.js.map +1 -1
- package/dist/ipc/message.cjs +17 -0
- package/dist/ipc/message.cjs.map +1 -0
- package/dist/ipc/message.js +0 -1
- package/dist/ipc/message.js.map +1 -1
- package/dist/ipc/proc_job_executor.cjs +174 -0
- package/dist/ipc/proc_job_executor.cjs.map +1 -0
- package/dist/ipc/proc_job_executor.js +130 -126
- package/dist/ipc/proc_job_executor.js.map +1 -1
- package/dist/ipc/proc_pool.cjs +126 -0
- package/dist/ipc/proc_pool.cjs.map +1 -0
- package/dist/ipc/proc_pool.js +93 -96
- package/dist/ipc/proc_pool.js.map +1 -1
- package/dist/job.cjs +230 -0
- package/dist/job.cjs.map +1 -0
- package/dist/job.js +195 -198
- package/dist/job.js.map +1 -1
- package/dist/llm/chat_context.cjs +131 -0
- package/dist/llm/chat_context.cjs.map +1 -0
- package/dist/llm/chat_context.js +98 -86
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/function_context.cjs +103 -0
- package/dist/llm/function_context.cjs.map +1 -0
- package/dist/llm/function_context.js +72 -81
- package/dist/llm/function_context.js.map +1 -1
- package/dist/llm/function_context.test.cjs +218 -0
- package/dist/llm/function_context.test.cjs.map +1 -0
- package/dist/llm/function_context.test.js +209 -210
- package/dist/llm/function_context.test.js.map +1 -1
- package/dist/llm/index.cjs +43 -0
- package/dist/llm/index.cjs.map +1 -0
- package/dist/llm/index.js +22 -6
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/llm.cjs +76 -0
- package/dist/llm/llm.cjs.map +1 -0
- package/dist/llm/llm.js +48 -42
- package/dist/llm/llm.js.map +1 -1
- package/dist/log.cjs +57 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.js +27 -26
- package/dist/log.js.map +1 -1
- package/dist/multimodal/agent_playout.cjs +228 -0
- package/dist/multimodal/agent_playout.cjs.map +1 -0
- package/dist/multimodal/agent_playout.d.ts +1 -1
- package/dist/multimodal/agent_playout.js +193 -180
- package/dist/multimodal/agent_playout.js.map +1 -1
- package/dist/multimodal/index.cjs +25 -0
- package/dist/multimodal/index.cjs.map +1 -0
- package/dist/multimodal/index.js +2 -5
- package/dist/multimodal/index.js.map +1 -1
- package/dist/multimodal/multimodal_agent.cjs +404 -0
- package/dist/multimodal/multimodal_agent.cjs.map +1 -0
- package/dist/multimodal/multimodal_agent.d.ts +2 -2
- package/dist/multimodal/multimodal_agent.d.ts.map +1 -1
- package/dist/multimodal/multimodal_agent.js +351 -303
- package/dist/multimodal/multimodal_agent.js.map +1 -1
- package/dist/pipeline/agent_output.cjs +172 -0
- package/dist/pipeline/agent_output.cjs.map +1 -0
- package/dist/pipeline/agent_output.js +136 -138
- package/dist/pipeline/agent_output.js.map +1 -1
- package/dist/pipeline/agent_playout.cjs +169 -0
- package/dist/pipeline/agent_playout.cjs.map +1 -0
- package/dist/pipeline/agent_playout.js +126 -136
- package/dist/pipeline/agent_playout.js.map +1 -1
- package/dist/pipeline/human_input.cjs +158 -0
- package/dist/pipeline/human_input.cjs.map +1 -0
- package/dist/pipeline/human_input.js +124 -125
- package/dist/pipeline/human_input.js.map +1 -1
- package/dist/pipeline/index.cjs +31 -0
- package/dist/pipeline/index.cjs.map +1 -0
- package/dist/pipeline/index.js +8 -4
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/pipeline_agent.cjs +642 -0
- package/dist/pipeline/pipeline_agent.cjs.map +1 -0
- package/dist/pipeline/pipeline_agent.d.ts +1 -0
- package/dist/pipeline/pipeline_agent.d.ts.map +1 -1
- package/dist/pipeline/pipeline_agent.js +595 -650
- package/dist/pipeline/pipeline_agent.js.map +1 -1
- package/dist/pipeline/speech_handle.cjs +128 -0
- package/dist/pipeline/speech_handle.cjs.map +1 -0
- package/dist/pipeline/speech_handle.js +102 -100
- package/dist/pipeline/speech_handle.js.map +1 -1
- package/dist/plugin.cjs +46 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.js +20 -20
- package/dist/plugin.js.map +1 -1
- package/dist/stt/index.cjs +38 -0
- package/dist/stt/index.cjs.map +1 -0
- package/dist/stt/index.js +13 -5
- package/dist/stt/index.js.map +1 -1
- package/dist/stt/stream_adapter.cjs +87 -0
- package/dist/stt/stream_adapter.cjs.map +1 -0
- package/dist/stt/stream_adapter.js +58 -55
- package/dist/stt/stream_adapter.js.map +1 -1
- package/dist/stt/stt.cjs +98 -0
- package/dist/stt/stt.cjs.map +1 -0
- package/dist/stt/stt.js +63 -98
- package/dist/stt/stt.js.map +1 -1
- package/dist/tokenize/basic/basic.cjs +98 -0
- package/dist/tokenize/basic/basic.cjs.map +1 -0
- package/dist/tokenize/basic/basic.js +56 -45
- package/dist/tokenize/basic/basic.js.map +1 -1
- package/dist/tokenize/basic/hyphenator.cjs +425 -0
- package/dist/tokenize/basic/hyphenator.cjs.map +1 -0
- package/dist/tokenize/basic/hyphenator.js +66 -82
- package/dist/tokenize/basic/hyphenator.js.map +1 -1
- package/dist/tokenize/basic/index.cjs +35 -0
- package/dist/tokenize/basic/index.cjs.map +1 -0
- package/dist/tokenize/basic/index.js +7 -4
- package/dist/tokenize/basic/index.js.map +1 -1
- package/dist/tokenize/basic/paragraph.cjs +57 -0
- package/dist/tokenize/basic/paragraph.cjs.map +1 -0
- package/dist/tokenize/basic/paragraph.js +30 -35
- package/dist/tokenize/basic/paragraph.js.map +1 -1
- package/dist/tokenize/basic/sentence.cjs +83 -0
- package/dist/tokenize/basic/sentence.cjs.map +1 -0
- package/dist/tokenize/basic/sentence.js +56 -57
- package/dist/tokenize/basic/sentence.js.map +1 -1
- package/dist/tokenize/basic/word.cjs +44 -0
- package/dist/tokenize/basic/word.cjs.map +1 -0
- package/dist/tokenize/basic/word.js +17 -20
- package/dist/tokenize/basic/word.js.map +1 -1
- package/dist/tokenize/index.cjs +55 -0
- package/dist/tokenize/index.cjs.map +1 -0
- package/dist/tokenize/index.js +18 -7
- package/dist/tokenize/index.js.map +1 -1
- package/dist/tokenize/token_stream.cjs +164 -0
- package/dist/tokenize/token_stream.cjs.map +1 -0
- package/dist/tokenize/token_stream.js +133 -139
- package/dist/tokenize/token_stream.js.map +1 -1
- package/dist/tokenize/tokenizer.cjs +184 -0
- package/dist/tokenize/tokenizer.cjs.map +1 -0
- package/dist/tokenize/tokenizer.js +138 -99
- package/dist/tokenize/tokenizer.js.map +1 -1
- package/dist/transcription.cjs +131 -0
- package/dist/transcription.cjs.map +1 -0
- package/dist/transcription.d.ts +2 -0
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +99 -93
- package/dist/transcription.js.map +1 -1
- package/dist/tts/index.cjs +38 -0
- package/dist/tts/index.cjs.map +1 -0
- package/dist/tts/index.js +13 -5
- package/dist/tts/index.js.map +1 -1
- package/dist/tts/stream_adapter.cjs +78 -0
- package/dist/tts/stream_adapter.cjs.map +1 -0
- package/dist/tts/stream_adapter.js +50 -47
- package/dist/tts/stream_adapter.js.map +1 -1
- package/dist/tts/tts.cjs +127 -0
- package/dist/tts/tts.cjs.map +1 -0
- package/dist/tts/tts.js +90 -120
- package/dist/tts/tts.js.map +1 -1
- package/dist/utils.cjs +284 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +242 -247
- package/dist/utils.js.map +1 -1
- package/dist/vad.cjs +92 -0
- package/dist/vad.cjs.map +1 -0
- package/dist/vad.js +57 -52
- package/dist/vad.js.map +1 -1
- package/dist/version.cjs +29 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +4 -4
- package/dist/version.js.map +1 -1
- package/dist/worker.cjs +576 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +511 -484
- package/dist/worker.js.map +1 -1
- package/package.json +23 -7
- package/src/ipc/job_main.ts +66 -64
- package/src/multimodal/multimodal_agent.ts +29 -2
- package/src/pipeline/pipeline_agent.ts +25 -24
- package/src/transcription.ts +5 -0
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -165
- package/api-extractor.json +0 -20
- package/tsconfig.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
package/dist/transcription.js
CHANGED
|
@@ -1,101 +1,107 @@
|
|
|
1
|
-
import { log } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.#totalAudioDuration += frame.samplesPerChannel / frame.sampleRate;
|
|
32
|
-
}
|
|
33
|
-
pushText(text) {
|
|
34
|
-
this.#currentText += text;
|
|
35
|
-
}
|
|
36
|
-
#textIsComplete = false;
|
|
37
|
-
#audioIsComplete = false;
|
|
38
|
-
markTextComplete() {
|
|
39
|
-
this.#textIsComplete = true;
|
|
40
|
-
this.#adjustTimingIfBothFinished();
|
|
41
|
-
}
|
|
42
|
-
markAudioComplete() {
|
|
43
|
-
this.#audioIsComplete = true;
|
|
44
|
-
this.#adjustTimingIfBothFinished();
|
|
45
|
-
}
|
|
46
|
-
#adjustTimingIfBothFinished() {
|
|
47
|
-
if (this.#textIsComplete && this.#audioIsComplete) {
|
|
48
|
-
const actualDuration = this.#totalAudioDuration;
|
|
49
|
-
if (actualDuration > 0 && this.#currentText.length > 0) {
|
|
50
|
-
this.#charsPerSecond = this.#currentText.length / actualDuration;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
import { log } from "./log.js";
|
|
2
|
+
class BasicTranscriptionForwarder {
|
|
3
|
+
#room;
|
|
4
|
+
#participantIdentity;
|
|
5
|
+
#trackSid;
|
|
6
|
+
#currentText = "";
|
|
7
|
+
#totalAudioDuration = 0;
|
|
8
|
+
#currentPlayoutTime = 0;
|
|
9
|
+
#DEFAULT_CHARS_PER_SECOND = 16;
|
|
10
|
+
#charsPerSecond = this.#DEFAULT_CHARS_PER_SECOND;
|
|
11
|
+
#messageId;
|
|
12
|
+
#isRunning = false;
|
|
13
|
+
#logger = log();
|
|
14
|
+
currentCharacterIndex = 0;
|
|
15
|
+
constructor(room, participantIdentity, trackSid, messageId) {
|
|
16
|
+
this.#room = room;
|
|
17
|
+
this.#participantIdentity = participantIdentity;
|
|
18
|
+
this.#trackSid = trackSid;
|
|
19
|
+
this.#messageId = messageId;
|
|
20
|
+
}
|
|
21
|
+
get text() {
|
|
22
|
+
return this.#currentText;
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
if (!this.#isRunning) {
|
|
26
|
+
this.#isRunning = true;
|
|
27
|
+
this.#startPublishingLoop().catch((error) => {
|
|
28
|
+
this.#logger.error("Error in publishing loop:", error);
|
|
29
|
+
this.#isRunning = false;
|
|
30
|
+
});
|
|
53
31
|
}
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
}
|
|
33
|
+
pushAudio(frame) {
|
|
34
|
+
this.#totalAudioDuration += frame.samplesPerChannel / frame.sampleRate;
|
|
35
|
+
}
|
|
36
|
+
pushText(text) {
|
|
37
|
+
this.#currentText += text;
|
|
38
|
+
}
|
|
39
|
+
#textIsComplete = false;
|
|
40
|
+
#audioIsComplete = false;
|
|
41
|
+
markTextComplete() {
|
|
42
|
+
this.#textIsComplete = true;
|
|
43
|
+
this.#adjustTimingIfBothFinished();
|
|
44
|
+
}
|
|
45
|
+
markAudioComplete() {
|
|
46
|
+
this.#audioIsComplete = true;
|
|
47
|
+
this.#adjustTimingIfBothFinished();
|
|
48
|
+
}
|
|
49
|
+
#adjustTimingIfBothFinished() {
|
|
50
|
+
if (this.#textIsComplete && this.#audioIsComplete) {
|
|
51
|
+
const actualDuration = this.#totalAudioDuration;
|
|
52
|
+
if (actualDuration > 0 && this.#currentText.length > 0) {
|
|
53
|
+
this.#charsPerSecond = this.#currentText.length / actualDuration;
|
|
54
|
+
}
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
56
|
+
}
|
|
57
|
+
#computeSleepInterval() {
|
|
58
|
+
return Math.min(Math.max(1 / this.#charsPerSecond, 0.0625), 0.5);
|
|
59
|
+
}
|
|
60
|
+
async #startPublishingLoop() {
|
|
61
|
+
this.#isRunning = true;
|
|
62
|
+
let sleepInterval = this.#computeSleepInterval();
|
|
63
|
+
let isComplete = false;
|
|
64
|
+
while (this.#isRunning && !isComplete) {
|
|
65
|
+
this.#currentPlayoutTime += sleepInterval;
|
|
66
|
+
this.currentCharacterIndex = Math.floor(this.#currentPlayoutTime * this.#charsPerSecond);
|
|
67
|
+
isComplete = this.#textIsComplete && this.currentCharacterIndex >= this.#currentText.length;
|
|
68
|
+
await this.#publishTranscription(false);
|
|
69
|
+
if (this.#isRunning && !isComplete) {
|
|
70
|
+
sleepInterval = this.#computeSleepInterval();
|
|
71
|
+
await new Promise((resolve) => setTimeout(resolve, sleepInterval * 1e3));
|
|
72
|
+
}
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await this.#room.localParticipant?.publishTranscription({
|
|
78
|
-
participantIdentity: this.#participantIdentity,
|
|
79
|
-
trackSid: this.#trackSid,
|
|
80
|
-
segments: [
|
|
81
|
-
{
|
|
82
|
-
text: textToPublish,
|
|
83
|
-
final: final,
|
|
84
|
-
id: this.#messageId,
|
|
85
|
-
startTime: BigInt(0),
|
|
86
|
-
endTime: BigInt(0),
|
|
87
|
-
language: '',
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
});
|
|
74
|
+
if (this.#isRunning) {
|
|
75
|
+
this.close(false);
|
|
91
76
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
77
|
+
}
|
|
78
|
+
async #publishTranscription(final) {
|
|
79
|
+
var _a;
|
|
80
|
+
const textToPublish = this.#currentText.slice(0, this.currentCharacterIndex);
|
|
81
|
+
await ((_a = this.#room.localParticipant) == null ? void 0 : _a.publishTranscription({
|
|
82
|
+
participantIdentity: this.#participantIdentity,
|
|
83
|
+
trackSid: this.#trackSid,
|
|
84
|
+
segments: [
|
|
85
|
+
{
|
|
86
|
+
text: textToPublish,
|
|
87
|
+
final,
|
|
88
|
+
id: this.#messageId,
|
|
89
|
+
startTime: BigInt(0),
|
|
90
|
+
endTime: BigInt(0),
|
|
91
|
+
language: ""
|
|
97
92
|
}
|
|
98
|
-
|
|
93
|
+
]
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
async close(interrupt) {
|
|
97
|
+
this.#isRunning = false;
|
|
98
|
+
if (!interrupt) {
|
|
99
|
+
this.currentCharacterIndex = this.#currentText.length;
|
|
99
100
|
}
|
|
101
|
+
await this.#publishTranscription(true);
|
|
102
|
+
}
|
|
100
103
|
}
|
|
104
|
+
export {
|
|
105
|
+
BasicTranscriptionForwarder
|
|
106
|
+
};
|
|
101
107
|
//# sourceMappingURL=transcription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/transcription.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { AudioFrame, Room } from '@livekit/rtc-node';\nimport { log } from './log.js';\n\nexport interface TranscriptionForwarder {\n start(): void;\n pushAudio(frame: AudioFrame): void;\n pushText(text: string): void;\n markTextComplete(): void;\n markAudioComplete(): void;\n close(interrupt: boolean): Promise<void>;\n currentCharacterIndex: number;\n text: string;\n}\n\nexport class BasicTranscriptionForwarder implements TranscriptionForwarder {\n #room: Room;\n #participantIdentity: string;\n #trackSid: string;\n #currentText: string = '';\n #totalAudioDuration: number = 0;\n #currentPlayoutTime: number = 0;\n #DEFAULT_CHARS_PER_SECOND = 16;\n #charsPerSecond: number = this.#DEFAULT_CHARS_PER_SECOND;\n #messageId: string;\n #isRunning: boolean = false;\n #logger = log();\n currentCharacterIndex: number = 0;\n\n constructor(room: Room, participantIdentity: string, trackSid: string, messageId: string) {\n this.#room = room;\n this.#participantIdentity = participantIdentity;\n this.#trackSid = trackSid;\n this.#messageId = messageId;\n }\n\n get text(): string {\n return this.#currentText;\n }\n\n start(): void {\n if (!this.#isRunning) {\n this.#isRunning = true;\n this.#startPublishingLoop().catch((error) => {\n this.#logger.error('Error in publishing loop:', error);\n this.#isRunning = false;\n });\n }\n }\n\n pushAudio(frame: AudioFrame): void {\n this.#totalAudioDuration += frame.samplesPerChannel / frame.sampleRate;\n }\n\n pushText(text: string): void {\n this.#currentText += text;\n }\n\n #textIsComplete: boolean = false;\n #audioIsComplete: boolean = false;\n\n markTextComplete(): void {\n this.#textIsComplete = true;\n this.#adjustTimingIfBothFinished();\n }\n\n markAudioComplete(): void {\n this.#audioIsComplete = true;\n this.#adjustTimingIfBothFinished();\n }\n\n #adjustTimingIfBothFinished(): void {\n if (this.#textIsComplete && this.#audioIsComplete) {\n const actualDuration = this.#totalAudioDuration;\n if (actualDuration > 0 && this.#currentText.length > 0) {\n this.#charsPerSecond = this.#currentText.length / actualDuration;\n }\n }\n }\n\n #computeSleepInterval(): number {\n return Math.min(Math.max(1 / this.#charsPerSecond, 0.0625), 0.5);\n }\n\n async #startPublishingLoop(): Promise<void> {\n this.#isRunning = true;\n let sleepInterval = this.#computeSleepInterval();\n let isComplete = false;\n while (this.#isRunning && !isComplete) {\n this.#currentPlayoutTime += sleepInterval;\n this.currentCharacterIndex = Math.floor(this.#currentPlayoutTime * this.#charsPerSecond);\n isComplete = this.#textIsComplete && this.currentCharacterIndex >= this.#currentText.length;\n await this.#publishTranscription(false);\n if (this.#isRunning && !isComplete) {\n sleepInterval = this.#computeSleepInterval();\n await new Promise((resolve) => setTimeout(resolve, sleepInterval * 1000));\n }\n }\n\n if (this.#isRunning) {\n this.close(false);\n }\n }\n\n async #publishTranscription(final: boolean): Promise<void> {\n const textToPublish = this.#currentText.slice(0, this.currentCharacterIndex);\n await this.#room.localParticipant?.publishTranscription({\n participantIdentity: this.#participantIdentity,\n trackSid: this.#trackSid,\n segments: [\n {\n text: textToPublish,\n final: final,\n id: this.#messageId,\n startTime: BigInt(0),\n endTime: BigInt(0),\n language: '',\n },\n ],\n });\n }\n\n async close(interrupt: boolean): Promise<void> {\n this.#isRunning = false;\n\n // Publish whatever we had as final\n if (!interrupt) {\n this.currentCharac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","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
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: () => import_tts.ChunkedStream,
|
|
22
|
+
StreamAdapter: () => import_stream_adapter.StreamAdapter,
|
|
23
|
+
StreamAdapterWrapper: () => import_stream_adapter.StreamAdapterWrapper,
|
|
24
|
+
SynthesizeStream: () => import_tts.SynthesizeStream,
|
|
25
|
+
TTS: () => import_tts.TTS
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(tts_exports);
|
|
28
|
+
var import_tts = require("./tts.cjs");
|
|
29
|
+
var import_stream_adapter = require("./stream_adapter.cjs");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
ChunkedStream,
|
|
33
|
+
StreamAdapter,
|
|
34
|
+
StreamAdapterWrapper,
|
|
35
|
+
SynthesizeStream,
|
|
36
|
+
TTS
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tts/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nexport {\n type SynthesizedAudio,\n type TTSCapabilities,\n TTS,\n SynthesizeStream,\n ChunkedStream,\n} from './tts.js';\nexport { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAMO;AACP,4BAAoD;","names":[]}
|
package/dist/tts/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
TTS,
|
|
3
|
+
SynthesizeStream,
|
|
4
|
+
ChunkedStream
|
|
5
|
+
} from "./tts.js";
|
|
6
|
+
import { StreamAdapter, StreamAdapterWrapper } from "./stream_adapter.js";
|
|
7
|
+
export {
|
|
8
|
+
ChunkedStream,
|
|
9
|
+
StreamAdapter,
|
|
10
|
+
StreamAdapterWrapper,
|
|
11
|
+
SynthesizeStream,
|
|
12
|
+
TTS
|
|
13
|
+
};
|
|
6
14
|
//# sourceMappingURL=index.js.map
|
package/dist/tts/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/tts/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nexport {\n type SynthesizedAudio,\n type TTSCapabilities,\n TTS,\n SynthesizeStream,\n ChunkedStream,\n} from './tts.js';\nexport { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';\n"],"mappings":"AAGA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,4BAA4B;","names":[]}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 stream_adapter_exports = {};
|
|
20
|
+
__export(stream_adapter_exports, {
|
|
21
|
+
StreamAdapter: () => StreamAdapter,
|
|
22
|
+
StreamAdapterWrapper: () => StreamAdapterWrapper
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(stream_adapter_exports);
|
|
25
|
+
var import_tts = require("./tts.cjs");
|
|
26
|
+
class StreamAdapter extends import_tts.TTS {
|
|
27
|
+
#tts;
|
|
28
|
+
#sentenceTokenizer;
|
|
29
|
+
constructor(tts, sentenceTokenizer) {
|
|
30
|
+
super(tts.sampleRate, tts.numChannels, { streaming: true });
|
|
31
|
+
this.#tts = tts;
|
|
32
|
+
this.#sentenceTokenizer = sentenceTokenizer;
|
|
33
|
+
}
|
|
34
|
+
synthesize(text) {
|
|
35
|
+
return this.#tts.synthesize(text);
|
|
36
|
+
}
|
|
37
|
+
stream() {
|
|
38
|
+
return new StreamAdapterWrapper(this.#tts, this.#sentenceTokenizer);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class StreamAdapterWrapper extends import_tts.SynthesizeStream {
|
|
42
|
+
#tts;
|
|
43
|
+
#sentenceStream;
|
|
44
|
+
constructor(tts, sentenceTokenizer) {
|
|
45
|
+
super();
|
|
46
|
+
this.#tts = tts;
|
|
47
|
+
this.#sentenceStream = sentenceTokenizer.stream();
|
|
48
|
+
this.#run();
|
|
49
|
+
}
|
|
50
|
+
async #run() {
|
|
51
|
+
const forwardInput = async () => {
|
|
52
|
+
for await (const input of this.input) {
|
|
53
|
+
if (input === import_tts.SynthesizeStream.FLUSH_SENTINEL) {
|
|
54
|
+
this.#sentenceStream.flush();
|
|
55
|
+
} else {
|
|
56
|
+
this.#sentenceStream.pushText(input);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.#sentenceStream.endInput();
|
|
60
|
+
this.#sentenceStream.close();
|
|
61
|
+
};
|
|
62
|
+
const synthesize = async () => {
|
|
63
|
+
for await (const ev of this.#sentenceStream) {
|
|
64
|
+
for await (const audio of this.#tts.synthesize(ev.token)) {
|
|
65
|
+
this.queue.put(audio);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
this.queue.put(import_tts.SynthesizeStream.END_OF_STREAM);
|
|
69
|
+
};
|
|
70
|
+
Promise.all([forwardInput(), synthesize()]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
StreamAdapter,
|
|
76
|
+
StreamAdapterWrapper
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=stream_adapter.cjs.map
|
|
@@ -0,0 +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.queue.put(audio);\n }\n }\n this.queue.put(SynthesizeStream.END_OF_STREAM);\n };\n\n Promise.all([forwardInput(), synthesize()]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,iBAAsC;AAE/B,MAAM,sBAAsB,eAAI;AAAA,EACrC;AAAA,EACA;AAAA,EAEA,YAAY,KAAU,mBAAsC;AAC1D,UAAM,IAAI,YAAY,IAAI,aAAa,EAAE,WAAW,KAAK,CAAC;AAC1D,SAAK,OAAO;AACZ,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEA,WAAW,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
4
|
+
#sentenceTokenizer;
|
|
5
|
+
constructor(tts, sentenceTokenizer) {
|
|
6
|
+
super(tts.sampleRate, tts.numChannels, { streaming: true });
|
|
7
|
+
this.#tts = tts;
|
|
8
|
+
this.#sentenceTokenizer = sentenceTokenizer;
|
|
9
|
+
}
|
|
10
|
+
synthesize(text) {
|
|
11
|
+
return this.#tts.synthesize(text);
|
|
12
|
+
}
|
|
13
|
+
stream() {
|
|
14
|
+
return new StreamAdapterWrapper(this.#tts, this.#sentenceTokenizer);
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
17
|
+
class StreamAdapterWrapper extends SynthesizeStream {
|
|
18
|
+
#tts;
|
|
19
|
+
#sentenceStream;
|
|
20
|
+
constructor(tts, sentenceTokenizer) {
|
|
21
|
+
super();
|
|
22
|
+
this.#tts = tts;
|
|
23
|
+
this.#sentenceStream = sentenceTokenizer.stream();
|
|
24
|
+
this.#run();
|
|
25
|
+
}
|
|
26
|
+
async #run() {
|
|
27
|
+
const forwardInput = async () => {
|
|
28
|
+
for await (const input of this.input) {
|
|
29
|
+
if (input === SynthesizeStream.FLUSH_SENTINEL) {
|
|
30
|
+
this.#sentenceStream.flush();
|
|
31
|
+
} else {
|
|
32
|
+
this.#sentenceStream.pushText(input);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.#sentenceStream.endInput();
|
|
36
|
+
this.#sentenceStream.close();
|
|
37
|
+
};
|
|
38
|
+
const synthesize = async () => {
|
|
39
|
+
for await (const ev of this.#sentenceStream) {
|
|
40
|
+
for await (const audio of this.#tts.synthesize(ev.token)) {
|
|
41
|
+
this.queue.put(audio);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.queue.put(SynthesizeStream.END_OF_STREAM);
|
|
45
|
+
};
|
|
46
|
+
Promise.all([forwardInput(), synthesize()]);
|
|
47
|
+
}
|
|
49
48
|
}
|
|
49
|
+
export {
|
|
50
|
+
StreamAdapter,
|
|
51
|
+
StreamAdapterWrapper
|
|
52
|
+
};
|
|
50
53
|
//# sourceMappingURL=stream_adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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.queue.put(audio);\n }\n }\n this.queue.put(SynthesizeStream.END_OF_STREAM);\n };\n\n Promise.all([forwardInput(), synthesize()]);\n }\n}\n"],"mappings":"AAKA,SAAS,kBAAkB,WAAW;AAE/B,MAAM,sBAAsB,IAAI;AAAA,EACrC;AAAA,EACA;AAAA,EAEA,YAAY,KAAU,mBAAsC;AAC1D,UAAM,IAAI,YAAY,IAAI,aAAa,EAAE,WAAW,KAAK,CAAC;AAC1D,SAAK,OAAO;AACZ,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEA,WAAW,MAA6B;AACtC,WAAO,KAAK,KAAK,WAAW,IAAI;AAAA,EAClC;AAAA,EAEA,SAA+B;AAC7B,WAAO,IAAI,qBAAqB,KAAK,MAAM,KAAK,kBAAkB;AAAA,EACpE;AACF;AAEO,MAAM,6BAA6B,iBAAiB;AAAA,EACzD;AAAA,EACA;AAAA,EAEA,YAAY,KAAU,mBAAsC;AAC1D,UAAM;AACN,SAAK,OAAO;AACZ,SAAK,kBAAkB,kBAAkB,OAAO;AAEhD,SAAK,KAAK;AAAA,EACZ;AAAA,EAEA,MAAM,OAAO;AACX,UAAM,eAAe,YAAY;AAC/B,uBAAiB,SAAS,KAAK,OAAO;AACpC,YAAI,UAAU,iBAAiB,gBAAgB;AAC7C,eAAK,gBAAgB,MAAM;AAAA,QAC7B,OAAO;AACL,eAAK,gBAAgB,SAAS,KAAK;AAAA,QACrC;AAAA,MACF;AACA,WAAK,gBAAgB,SAAS;AAC9B,WAAK,gBAAgB,MAAM;AAAA,IAC7B;AAEA,UAAM,aAAa,YAAY;AAC7B,uBAAiB,MAAM,KAAK,iBAAiB;AAC3C,yBAAiB,SAAS,KAAK,KAAK,WAAW,GAAG,KAAK,GAAG;AACxD,eAAK,MAAM,IAAI,KAAK;AAAA,QACtB;AAAA,MACF;AACA,WAAK,MAAM,IAAI,iBAAiB,aAAa;AAAA,IAC/C;AAEA,YAAQ,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,CAAC;AAAA,EAC5C;AACF;","names":[]}
|
package/dist/tts/tts.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
SynthesizeStream: () => SynthesizeStream,
|
|
23
|
+
TTS: () => TTS
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tts_exports);
|
|
26
|
+
var import_utils = require("../utils.cjs");
|
|
27
|
+
class TTS {
|
|
28
|
+
#capabilities;
|
|
29
|
+
#sampleRate;
|
|
30
|
+
#numChannels;
|
|
31
|
+
constructor(sampleRate, numChannels, capabilities) {
|
|
32
|
+
this.#capabilities = capabilities;
|
|
33
|
+
this.#sampleRate = sampleRate;
|
|
34
|
+
this.#numChannels = numChannels;
|
|
35
|
+
}
|
|
36
|
+
/** Returns this TTS's capabilities */
|
|
37
|
+
get capabilities() {
|
|
38
|
+
return this.#capabilities;
|
|
39
|
+
}
|
|
40
|
+
/** Returns the sample rate of audio frames returned by this TTS */
|
|
41
|
+
get sampleRate() {
|
|
42
|
+
return this.#sampleRate;
|
|
43
|
+
}
|
|
44
|
+
/** Returns the channel count of audio frames returned by this TTS */
|
|
45
|
+
get numChannels() {
|
|
46
|
+
return this.#numChannels;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class SynthesizeStream {
|
|
50
|
+
static FLUSH_SENTINEL = Symbol("FLUSH_SENTINEL");
|
|
51
|
+
static END_OF_STREAM = Symbol("END_OF_STREAM");
|
|
52
|
+
input = new import_utils.AsyncIterableQueue();
|
|
53
|
+
queue = new import_utils.AsyncIterableQueue();
|
|
54
|
+
closed = false;
|
|
55
|
+
/** Push a string of text to the TTS */
|
|
56
|
+
pushText(text) {
|
|
57
|
+
if (this.input.closed) {
|
|
58
|
+
throw new Error("Input is closed");
|
|
59
|
+
}
|
|
60
|
+
if (this.closed) {
|
|
61
|
+
throw new Error("Stream is closed");
|
|
62
|
+
}
|
|
63
|
+
this.input.put(text);
|
|
64
|
+
}
|
|
65
|
+
/** Flush the TTS, causing it to process all pending text */
|
|
66
|
+
flush() {
|
|
67
|
+
if (this.input.closed) {
|
|
68
|
+
throw new Error("Input is closed");
|
|
69
|
+
}
|
|
70
|
+
if (this.closed) {
|
|
71
|
+
throw new Error("Stream is closed");
|
|
72
|
+
}
|
|
73
|
+
this.input.put(SynthesizeStream.FLUSH_SENTINEL);
|
|
74
|
+
}
|
|
75
|
+
/** Mark the input as ended and forbid additional pushes */
|
|
76
|
+
endInput() {
|
|
77
|
+
if (this.input.closed) {
|
|
78
|
+
throw new Error("Input is closed");
|
|
79
|
+
}
|
|
80
|
+
if (this.closed) {
|
|
81
|
+
throw new Error("Stream is closed");
|
|
82
|
+
}
|
|
83
|
+
this.input.close();
|
|
84
|
+
}
|
|
85
|
+
next() {
|
|
86
|
+
return this.queue.next();
|
|
87
|
+
}
|
|
88
|
+
/** Close both the input and output of the TTS stream */
|
|
89
|
+
close() {
|
|
90
|
+
this.input.close();
|
|
91
|
+
this.queue.close();
|
|
92
|
+
this.closed = true;
|
|
93
|
+
}
|
|
94
|
+
[Symbol.asyncIterator]() {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
class ChunkedStream {
|
|
99
|
+
queue = new import_utils.AsyncIterableQueue();
|
|
100
|
+
closed = false;
|
|
101
|
+
/** Collect every frame into one in a single call */
|
|
102
|
+
async collect() {
|
|
103
|
+
const frames = [];
|
|
104
|
+
for await (const event of this) {
|
|
105
|
+
frames.push(event.frame);
|
|
106
|
+
}
|
|
107
|
+
return (0, import_utils.mergeFrames)(frames);
|
|
108
|
+
}
|
|
109
|
+
next() {
|
|
110
|
+
return this.queue.next();
|
|
111
|
+
}
|
|
112
|
+
/** Close both the input and output of the TTS stream */
|
|
113
|
+
close() {
|
|
114
|
+
this.queue.close();
|
|
115
|
+
this.closed = true;
|
|
116
|
+
}
|
|
117
|
+
[Symbol.asyncIterator]() {
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
ChunkedStream,
|
|
124
|
+
SynthesizeStream,
|
|
125
|
+
TTS
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=tts.cjs.map
|