@livekit/agents 0.4.6 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +17 -0
  2. package/dist/audio.cjs +77 -0
  3. package/dist/audio.cjs.map +1 -0
  4. package/dist/audio.js +48 -37
  5. package/dist/audio.js.map +1 -1
  6. package/dist/cli.cjs +131 -0
  7. package/dist/cli.cjs.map +1 -0
  8. package/dist/cli.js +96 -122
  9. package/dist/cli.js.map +1 -1
  10. package/dist/generator.cjs +36 -0
  11. package/dist/generator.cjs.map +1 -0
  12. package/dist/generator.js +8 -22
  13. package/dist/generator.js.map +1 -1
  14. package/dist/http_server.cjs +72 -0
  15. package/dist/http_server.cjs.map +1 -0
  16. package/dist/http_server.d.ts +1 -1
  17. package/dist/http_server.js +44 -47
  18. package/dist/http_server.js.map +1 -1
  19. package/dist/index.cjs +78 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.js +26 -28
  22. package/dist/index.js.map +1 -1
  23. package/dist/ipc/job_executor.cjs +33 -0
  24. package/dist/ipc/job_executor.cjs.map +1 -0
  25. package/dist/ipc/job_executor.js +7 -4
  26. package/dist/ipc/job_executor.js.map +1 -1
  27. package/dist/ipc/job_main.cjs +147 -0
  28. package/dist/ipc/job_main.cjs.map +1 -0
  29. package/dist/ipc/job_main.d.ts +1 -1
  30. package/dist/ipc/job_main.js +103 -103
  31. package/dist/ipc/job_main.js.map +1 -1
  32. package/dist/ipc/message.cjs +17 -0
  33. package/dist/ipc/message.cjs.map +1 -0
  34. package/dist/ipc/message.js +0 -1
  35. package/dist/ipc/message.js.map +1 -1
  36. package/dist/ipc/proc_job_executor.cjs +174 -0
  37. package/dist/ipc/proc_job_executor.cjs.map +1 -0
  38. package/dist/ipc/proc_job_executor.js +130 -126
  39. package/dist/ipc/proc_job_executor.js.map +1 -1
  40. package/dist/ipc/proc_pool.cjs +126 -0
  41. package/dist/ipc/proc_pool.cjs.map +1 -0
  42. package/dist/ipc/proc_pool.js +93 -96
  43. package/dist/ipc/proc_pool.js.map +1 -1
  44. package/dist/job.cjs +230 -0
  45. package/dist/job.cjs.map +1 -0
  46. package/dist/job.d.ts +6 -1
  47. package/dist/job.d.ts.map +1 -1
  48. package/dist/job.js +195 -198
  49. package/dist/job.js.map +1 -1
  50. package/dist/llm/chat_context.cjs +131 -0
  51. package/dist/llm/chat_context.cjs.map +1 -0
  52. package/dist/llm/chat_context.js +98 -86
  53. package/dist/llm/chat_context.js.map +1 -1
  54. package/dist/llm/function_context.cjs +103 -0
  55. package/dist/llm/function_context.cjs.map +1 -0
  56. package/dist/llm/function_context.js +72 -81
  57. package/dist/llm/function_context.js.map +1 -1
  58. package/dist/llm/function_context.test.cjs +218 -0
  59. package/dist/llm/function_context.test.cjs.map +1 -0
  60. package/dist/llm/function_context.test.js +209 -210
  61. package/dist/llm/function_context.test.js.map +1 -1
  62. package/dist/llm/index.cjs +43 -0
  63. package/dist/llm/index.cjs.map +1 -0
  64. package/dist/llm/index.js +22 -6
  65. package/dist/llm/index.js.map +1 -1
  66. package/dist/llm/llm.cjs +76 -0
  67. package/dist/llm/llm.cjs.map +1 -0
  68. package/dist/llm/llm.js +48 -42
  69. package/dist/llm/llm.js.map +1 -1
  70. package/dist/log.cjs +57 -0
  71. package/dist/log.cjs.map +1 -0
  72. package/dist/log.js +27 -26
  73. package/dist/log.js.map +1 -1
  74. package/dist/multimodal/agent_playout.cjs +228 -0
  75. package/dist/multimodal/agent_playout.cjs.map +1 -0
  76. package/dist/multimodal/agent_playout.d.ts +1 -1
  77. package/dist/multimodal/agent_playout.js +193 -180
  78. package/dist/multimodal/agent_playout.js.map +1 -1
  79. package/dist/multimodal/index.cjs +25 -0
  80. package/dist/multimodal/index.cjs.map +1 -0
  81. package/dist/multimodal/index.js +2 -5
  82. package/dist/multimodal/index.js.map +1 -1
  83. package/dist/multimodal/multimodal_agent.cjs +404 -0
  84. package/dist/multimodal/multimodal_agent.cjs.map +1 -0
  85. package/dist/multimodal/multimodal_agent.d.ts +1 -1
  86. package/dist/multimodal/multimodal_agent.js +351 -330
  87. package/dist/multimodal/multimodal_agent.js.map +1 -1
  88. package/dist/pipeline/agent_output.cjs +172 -0
  89. package/dist/pipeline/agent_output.cjs.map +1 -0
  90. package/dist/pipeline/agent_output.js +136 -138
  91. package/dist/pipeline/agent_output.js.map +1 -1
  92. package/dist/pipeline/agent_playout.cjs +169 -0
  93. package/dist/pipeline/agent_playout.cjs.map +1 -0
  94. package/dist/pipeline/agent_playout.js +126 -136
  95. package/dist/pipeline/agent_playout.js.map +1 -1
  96. package/dist/pipeline/human_input.cjs +158 -0
  97. package/dist/pipeline/human_input.cjs.map +1 -0
  98. package/dist/pipeline/human_input.js +124 -125
  99. package/dist/pipeline/human_input.js.map +1 -1
  100. package/dist/pipeline/index.cjs +31 -0
  101. package/dist/pipeline/index.cjs.map +1 -0
  102. package/dist/pipeline/index.js +8 -4
  103. package/dist/pipeline/index.js.map +1 -1
  104. package/dist/pipeline/pipeline_agent.cjs +642 -0
  105. package/dist/pipeline/pipeline_agent.cjs.map +1 -0
  106. package/dist/pipeline/pipeline_agent.js +595 -651
  107. package/dist/pipeline/pipeline_agent.js.map +1 -1
  108. package/dist/pipeline/speech_handle.cjs +128 -0
  109. package/dist/pipeline/speech_handle.cjs.map +1 -0
  110. package/dist/pipeline/speech_handle.js +102 -100
  111. package/dist/pipeline/speech_handle.js.map +1 -1
  112. package/dist/plugin.cjs +46 -0
  113. package/dist/plugin.cjs.map +1 -0
  114. package/dist/plugin.js +20 -20
  115. package/dist/plugin.js.map +1 -1
  116. package/dist/stt/index.cjs +38 -0
  117. package/dist/stt/index.cjs.map +1 -0
  118. package/dist/stt/index.js +13 -5
  119. package/dist/stt/index.js.map +1 -1
  120. package/dist/stt/stream_adapter.cjs +87 -0
  121. package/dist/stt/stream_adapter.cjs.map +1 -0
  122. package/dist/stt/stream_adapter.js +58 -55
  123. package/dist/stt/stream_adapter.js.map +1 -1
  124. package/dist/stt/stt.cjs +98 -0
  125. package/dist/stt/stt.cjs.map +1 -0
  126. package/dist/stt/stt.js +63 -98
  127. package/dist/stt/stt.js.map +1 -1
  128. package/dist/tokenize/basic/basic.cjs +98 -0
  129. package/dist/tokenize/basic/basic.cjs.map +1 -0
  130. package/dist/tokenize/basic/basic.d.ts +1 -1
  131. package/dist/tokenize/basic/basic.d.ts.map +1 -1
  132. package/dist/tokenize/basic/basic.js +56 -45
  133. package/dist/tokenize/basic/basic.js.map +1 -1
  134. package/dist/tokenize/basic/hyphenator.cjs +425 -0
  135. package/dist/tokenize/basic/hyphenator.cjs.map +1 -0
  136. package/dist/tokenize/basic/hyphenator.js +66 -82
  137. package/dist/tokenize/basic/hyphenator.js.map +1 -1
  138. package/dist/tokenize/basic/index.cjs +35 -0
  139. package/dist/tokenize/basic/index.cjs.map +1 -0
  140. package/dist/tokenize/basic/index.js +7 -4
  141. package/dist/tokenize/basic/index.js.map +1 -1
  142. package/dist/tokenize/basic/paragraph.cjs +57 -0
  143. package/dist/tokenize/basic/paragraph.cjs.map +1 -0
  144. package/dist/tokenize/basic/paragraph.js +30 -35
  145. package/dist/tokenize/basic/paragraph.js.map +1 -1
  146. package/dist/tokenize/basic/sentence.cjs +89 -0
  147. package/dist/tokenize/basic/sentence.cjs.map +1 -0
  148. package/dist/tokenize/basic/sentence.d.ts.map +1 -1
  149. package/dist/tokenize/basic/sentence.js +62 -57
  150. package/dist/tokenize/basic/sentence.js.map +1 -1
  151. package/dist/tokenize/basic/word.cjs +44 -0
  152. package/dist/tokenize/basic/word.cjs.map +1 -0
  153. package/dist/tokenize/basic/word.js +17 -20
  154. package/dist/tokenize/basic/word.js.map +1 -1
  155. package/dist/tokenize/index.cjs +55 -0
  156. package/dist/tokenize/index.cjs.map +1 -0
  157. package/dist/tokenize/index.js +18 -7
  158. package/dist/tokenize/index.js.map +1 -1
  159. package/dist/tokenize/token_stream.cjs +164 -0
  160. package/dist/tokenize/token_stream.cjs.map +1 -0
  161. package/dist/tokenize/token_stream.js +133 -139
  162. package/dist/tokenize/token_stream.js.map +1 -1
  163. package/dist/tokenize/tokenizer.cjs +184 -0
  164. package/dist/tokenize/tokenizer.cjs.map +1 -0
  165. package/dist/tokenize/tokenizer.js +138 -99
  166. package/dist/tokenize/tokenizer.js.map +1 -1
  167. package/dist/tokenize/tokenizer.test.cjs +220 -0
  168. package/dist/tokenize/tokenizer.test.cjs.map +1 -0
  169. package/dist/tokenize/tokenizer.test.d.ts +2 -0
  170. package/dist/tokenize/tokenizer.test.d.ts.map +1 -0
  171. package/dist/tokenize/tokenizer.test.js +219 -0
  172. package/dist/tokenize/tokenizer.test.js.map +1 -0
  173. package/dist/transcription.cjs +131 -0
  174. package/dist/transcription.cjs.map +1 -0
  175. package/dist/transcription.js +99 -96
  176. package/dist/transcription.js.map +1 -1
  177. package/dist/tts/index.cjs +38 -0
  178. package/dist/tts/index.cjs.map +1 -0
  179. package/dist/tts/index.js +13 -5
  180. package/dist/tts/index.js.map +1 -1
  181. package/dist/tts/stream_adapter.cjs +78 -0
  182. package/dist/tts/stream_adapter.cjs.map +1 -0
  183. package/dist/tts/stream_adapter.js +50 -47
  184. package/dist/tts/stream_adapter.js.map +1 -1
  185. package/dist/tts/tts.cjs +127 -0
  186. package/dist/tts/tts.cjs.map +1 -0
  187. package/dist/tts/tts.js +90 -120
  188. package/dist/tts/tts.js.map +1 -1
  189. package/dist/utils.cjs +284 -0
  190. package/dist/utils.cjs.map +1 -0
  191. package/dist/utils.js +242 -247
  192. package/dist/utils.js.map +1 -1
  193. package/dist/vad.cjs +92 -0
  194. package/dist/vad.cjs.map +1 -0
  195. package/dist/vad.js +57 -52
  196. package/dist/vad.js.map +1 -1
  197. package/dist/version.cjs +29 -0
  198. package/dist/version.cjs.map +1 -0
  199. package/dist/version.js +4 -4
  200. package/dist/version.js.map +1 -1
  201. package/dist/worker.cjs +577 -0
  202. package/dist/worker.cjs.map +1 -0
  203. package/dist/worker.d.ts +1 -1
  204. package/dist/worker.d.ts.map +1 -1
  205. package/dist/worker.js +512 -484
  206. package/dist/worker.js.map +1 -1
  207. package/package.json +18 -8
  208. package/src/ipc/job_main.ts +66 -64
  209. package/src/job.ts +3 -2
  210. package/src/pipeline/pipeline_agent.ts +23 -23
  211. package/src/tokenize/basic/basic.ts +1 -1
  212. package/src/tokenize/basic/sentence.ts +14 -8
  213. package/src/tokenize/tokenizer.test.ts +255 -0
  214. package/src/worker.ts +1 -0
@@ -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
- // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
- //
3
- // SPDX-License-Identifier: Apache-2.0
4
- export { TTS, SynthesizeStream, ChunkedStream, } from './tts.js';
5
- export { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tts/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,sCAAsC;AACtC,OAAO,EAGL,GAAG,EACH,gBAAgB,EAChB,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
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,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,4BAAiB;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,4BAAiB,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,4BAAiB,aAAa;AAAA,IAC/C;AAEA,YAAQ,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,CAAC;AAAA,EAC5C;AACF;","names":[]}
@@ -1,50 +1,53 @@
1
- import { SynthesizeStream, TTS } from './tts.js';
2
- export class StreamAdapter extends TTS {
3
- #tts;
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
- }
1
+ import { SynthesizeStream, TTS } from "./tts.js";
2
+ class StreamAdapter extends TTS {
3
+ #tts;
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
- export 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
- }
32
- else {
33
- this.#sentenceStream.pushText(input);
34
- }
35
- }
36
- this.#sentenceStream.endInput();
37
- this.#sentenceStream.close();
38
- };
39
- const synthesize = async () => {
40
- for await (const ev of this.#sentenceStream) {
41
- for await (const audio of this.#tts.synthesize(ev.token)) {
42
- this.queue.put(audio);
43
- }
44
- }
45
- this.queue.put(SynthesizeStream.END_OF_STREAM);
46
- };
47
- Promise.all([forwardInput(), synthesize()]);
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,"file":"stream_adapter.js","sourceRoot":"","sources":["../../src/tts/stream_adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,OAAO,aAAc,SAAQ,GAAG;IACpC,IAAI,CAAM;IACV,kBAAkB,CAAoB;IAEtC,YAAY,GAAQ,EAAE,iBAAoC;QACxD,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAC9C,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACtE,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IACxD,IAAI,CAAM;IACV,eAAe,CAAiB;IAEhC,YAAY,GAAQ,EAAE,iBAAoC;QACxD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,eAAe,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC;QAElD,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;YAC9B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACrC,IAAI,KAAK,KAAK,gBAAgB,CAAC,cAAc,EAAE,CAAC;oBAC9C,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;gBAC/B,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;YACD,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEF,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;YAC5B,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBAC5C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACjD,CAAC,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;CACF"}
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":[]}
@@ -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
@@ -0,0 +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,SAAK,MAAM,IAAI,IAAI;AAAA,EACrB;AAAA;AAAA,EAGA,QAAQ;AACN,QAAI,KAAK,MAAM,QAAQ;AACrB,YAAM,IAAI,MAAM,iBAAiB;AAAA,IACnC;AACA,QAAI,KAAK,QAAQ;AACf,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,SAAK,MAAM,IAAI,iBAAiB,cAAc;AAAA,EAChD;AAAA;AAAA,EAGA,WAAW;AACT,QAAI,KAAK,MAAM,QAAQ;AACrB,YAAM,IAAI,MAAM,iBAAiB;AAAA,IACnC;AACA,QAAI,KAAK,QAAQ;AACf,YAAM,IAAI,MAAM,kBAAkB;AAAA,IACpC;AACA,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,OAA0F;AACxF,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA;AAAA,EAGA,QAAQ;AACN,SAAK,MAAM,MAAM;AACjB,SAAK,MAAM,MAAM;AACjB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAsB;AACzC,WAAO;AAAA,EACT;AACF;AAgBO,MAAe,cAAiE;AAAA,EAC3E,QAAQ,IAAI,gCAAqC;AAAA,EACjD,SAAS;AAAA;AAAA,EAGnB,MAAM,UAA+B;AACnC,UAAM,SAAS,CAAC;AAChB,qBAAiB,SAAS,MAAM;AAC9B,aAAO,KAAK,MAAM,KAAK;AAAA,IACzB;AACA,eAAO,0BAAY,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":[]}
package/dist/tts/tts.js CHANGED
@@ -1,131 +1,101 @@
1
- import { AsyncIterableQueue, mergeFrames } from '../utils.js';
2
- /**
3
- * An instance of a text-to-speech adapter.
4
- *
5
- * @remarks
6
- * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that
7
- * exports its own child TTS class, which inherits this class's methods.
8
- */
9
- export class TTS {
10
- #capabilities;
11
- #sampleRate;
12
- #numChannels;
13
- constructor(sampleRate, numChannels, capabilities) {
14
- this.#capabilities = capabilities;
15
- this.#sampleRate = sampleRate;
16
- this.#numChannels = numChannels;
17
- }
18
- /** Returns this TTS's capabilities */
19
- get capabilities() {
20
- return this.#capabilities;
21
- }
22
- /** Returns the sample rate of audio frames returned by this TTS */
23
- get sampleRate() {
24
- return this.#sampleRate;
25
- }
26
- /** Returns the channel count of audio frames returned by this TTS */
27
- get numChannels() {
28
- return this.#numChannels;
29
- }
1
+ import { AsyncIterableQueue, mergeFrames } from "../utils.js";
2
+ class TTS {
3
+ #capabilities;
4
+ #sampleRate;
5
+ #numChannels;
6
+ constructor(sampleRate, numChannels, capabilities) {
7
+ this.#capabilities = capabilities;
8
+ this.#sampleRate = sampleRate;
9
+ this.#numChannels = numChannels;
10
+ }
11
+ /** Returns this TTS's capabilities */
12
+ get capabilities() {
13
+ return this.#capabilities;
14
+ }
15
+ /** Returns the sample rate of audio frames returned by this TTS */
16
+ get sampleRate() {
17
+ return this.#sampleRate;
18
+ }
19
+ /** Returns the channel count of audio frames returned by this TTS */
20
+ get numChannels() {
21
+ return this.#numChannels;
22
+ }
30
23
  }
31
- /**
32
- * An instance of a text-to-speech stream, as an asynchronous iterable iterator.
33
- *
34
- * @example Looping through frames
35
- * ```ts
36
- * for await (const event of stream) {
37
- * await source.captureFrame(event.frame);
38
- * }
39
- * ```
40
- *
41
- * @remarks
42
- * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that
43
- * exports its own child SynthesizeStream class, which inherits this class's methods.
44
- */
45
- export class SynthesizeStream {
46
- static FLUSH_SENTINEL = Symbol('FLUSH_SENTINEL');
47
- static END_OF_STREAM = Symbol('END_OF_STREAM');
48
- input = new AsyncIterableQueue();
49
- queue = new AsyncIterableQueue();
50
- closed = false;
51
- /** Push a string of text to the TTS */
52
- pushText(text) {
53
- if (this.input.closed) {
54
- throw new Error('Input is closed');
55
- }
56
- if (this.closed) {
57
- throw new Error('Stream is closed');
58
- }
59
- this.input.put(text);
24
+ class SynthesizeStream {
25
+ static FLUSH_SENTINEL = Symbol("FLUSH_SENTINEL");
26
+ static END_OF_STREAM = Symbol("END_OF_STREAM");
27
+ input = new AsyncIterableQueue();
28
+ queue = new AsyncIterableQueue();
29
+ closed = false;
30
+ /** Push a string of text to the TTS */
31
+ pushText(text) {
32
+ if (this.input.closed) {
33
+ throw new Error("Input is closed");
60
34
  }
61
- /** Flush the TTS, causing it to process all pending text */
62
- flush() {
63
- if (this.input.closed) {
64
- throw new Error('Input is closed');
65
- }
66
- if (this.closed) {
67
- throw new Error('Stream is closed');
68
- }
69
- this.input.put(SynthesizeStream.FLUSH_SENTINEL);
35
+ if (this.closed) {
36
+ throw new Error("Stream is closed");
70
37
  }
71
- /** Mark the input as ended and forbid additional pushes */
72
- endInput() {
73
- if (this.input.closed) {
74
- throw new Error('Input is closed');
75
- }
76
- if (this.closed) {
77
- throw new Error('Stream is closed');
78
- }
79
- this.input.close();
38
+ this.input.put(text);
39
+ }
40
+ /** Flush the TTS, causing it to process all pending text */
41
+ flush() {
42
+ if (this.input.closed) {
43
+ throw new Error("Input is closed");
80
44
  }
81
- next() {
82
- return this.queue.next();
45
+ if (this.closed) {
46
+ throw new Error("Stream is closed");
83
47
  }
84
- /** Close both the input and output of the TTS stream */
85
- close() {
86
- this.input.close();
87
- this.queue.close();
88
- this.closed = true;
48
+ this.input.put(SynthesizeStream.FLUSH_SENTINEL);
49
+ }
50
+ /** Mark the input as ended and forbid additional pushes */
51
+ endInput() {
52
+ if (this.input.closed) {
53
+ throw new Error("Input is closed");
89
54
  }
90
- [Symbol.asyncIterator]() {
91
- return this;
55
+ if (this.closed) {
56
+ throw new Error("Stream is closed");
92
57
  }
58
+ this.input.close();
59
+ }
60
+ next() {
61
+ return this.queue.next();
62
+ }
63
+ /** Close both the input and output of the TTS stream */
64
+ close() {
65
+ this.input.close();
66
+ this.queue.close();
67
+ this.closed = true;
68
+ }
69
+ [Symbol.asyncIterator]() {
70
+ return this;
71
+ }
93
72
  }
94
- /**
95
- * An instance of a text-to-speech response, as an asynchronous iterable iterator.
96
- *
97
- * @example Looping through frames
98
- * ```ts
99
- * for await (const event of stream) {
100
- * await source.captureFrame(event.frame);
101
- * }
102
- * ```
103
- *
104
- * @remarks
105
- * This class is abstract, and as such cannot be used directly. Instead, use a provider plugin that
106
- * exports its own child ChunkedStream class, which inherits this class's methods.
107
- */
108
- export class ChunkedStream {
109
- queue = new AsyncIterableQueue();
110
- closed = false;
111
- /** Collect every frame into one in a single call */
112
- async collect() {
113
- const frames = [];
114
- for await (const event of this) {
115
- frames.push(event.frame);
116
- }
117
- return mergeFrames(frames);
118
- }
119
- next() {
120
- return this.queue.next();
121
- }
122
- /** Close both the input and output of the TTS stream */
123
- close() {
124
- this.queue.close();
125
- this.closed = true;
126
- }
127
- [Symbol.asyncIterator]() {
128
- return this;
73
+ class ChunkedStream {
74
+ queue = new AsyncIterableQueue();
75
+ closed = false;
76
+ /** Collect every frame into one in a single call */
77
+ async collect() {
78
+ const frames = [];
79
+ for await (const event of this) {
80
+ frames.push(event.frame);
129
81
  }
82
+ return mergeFrames(frames);
83
+ }
84
+ next() {
85
+ return this.queue.next();
86
+ }
87
+ /** Close both the input and output of the TTS stream */
88
+ close() {
89
+ this.queue.close();
90
+ this.closed = true;
91
+ }
92
+ [Symbol.asyncIterator]() {
93
+ return this;
94
+ }
130
95
  }
96
+ export {
97
+ ChunkedStream,
98
+ SynthesizeStream,
99
+ TTS
100
+ };
131
101
  //# sourceMappingURL=tts.js.map