@azure/ai-voicelive 1.0.0-alpha.20251117.2

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 (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +358 -0
  3. package/dist/browser/auth/credentialHandler.d.ts +43 -0
  4. package/dist/browser/auth/credentialHandler.js +147 -0
  5. package/dist/browser/auth/credentialHandler.js.map +1 -0
  6. package/dist/browser/errors/connectionErrors.d.ts +68 -0
  7. package/dist/browser/errors/connectionErrors.js +136 -0
  8. package/dist/browser/errors/connectionErrors.js.map +1 -0
  9. package/dist/browser/errors/index.d.ts +2 -0
  10. package/dist/browser/errors/index.js +4 -0
  11. package/dist/browser/errors/index.js.map +1 -0
  12. package/dist/browser/handlers/sessionHandlers.d.ts +250 -0
  13. package/dist/browser/handlers/sessionHandlers.js +4 -0
  14. package/dist/browser/handlers/sessionHandlers.js.map +1 -0
  15. package/dist/browser/handlers/subscriptionManager.d.ts +54 -0
  16. package/dist/browser/handlers/subscriptionManager.js +250 -0
  17. package/dist/browser/handlers/subscriptionManager.js.map +1 -0
  18. package/dist/browser/index.d.ts +7 -0
  19. package/dist/browser/index.js +12 -0
  20. package/dist/browser/index.js.map +1 -0
  21. package/dist/browser/logger.d.ts +2 -0
  22. package/dist/browser/logger.js +5 -0
  23. package/dist/browser/logger.js.map +1 -0
  24. package/dist/browser/models/index.d.ts +2 -0
  25. package/dist/browser/models/index.js +4 -0
  26. package/dist/browser/models/index.js.map +1 -0
  27. package/dist/browser/models/models.d.ts +2154 -0
  28. package/dist/browser/models/models.js +2251 -0
  29. package/dist/browser/models/models.js.map +1 -0
  30. package/dist/browser/package.json +3 -0
  31. package/dist/browser/protocol/messageParser.d.ts +42 -0
  32. package/dist/browser/protocol/messageParser.js +150 -0
  33. package/dist/browser/protocol/messageParser.js.map +1 -0
  34. package/dist/browser/voiceLiveClient.d.ts +65 -0
  35. package/dist/browser/voiceLiveClient.js +81 -0
  36. package/dist/browser/voiceLiveClient.js.map +1 -0
  37. package/dist/browser/voiceLiveSession.d.ts +138 -0
  38. package/dist/browser/voiceLiveSession.js +429 -0
  39. package/dist/browser/voiceLiveSession.js.map +1 -0
  40. package/dist/browser/websocket/connectionManager.d.ts +88 -0
  41. package/dist/browser/websocket/connectionManager.js +183 -0
  42. package/dist/browser/websocket/connectionManager.js.map +1 -0
  43. package/dist/browser/websocket/websocketBrowser.d.ts +26 -0
  44. package/dist/browser/websocket/websocketBrowser.js +175 -0
  45. package/dist/browser/websocket/websocketBrowser.js.map +1 -0
  46. package/dist/browser/websocket/websocketFactory.d.ts +23 -0
  47. package/dist/browser/websocket/websocketFactory.js +80 -0
  48. package/dist/browser/websocket/websocketFactory.js.map +1 -0
  49. package/dist/browser/websocket/websocketLike.d.ts +78 -0
  50. package/dist/browser/websocket/websocketLike.js +13 -0
  51. package/dist/browser/websocket/websocketLike.js.map +1 -0
  52. package/dist/browser/websocket/websocketNode.d.ts +26 -0
  53. package/dist/browser/websocket/websocketNode.js +180 -0
  54. package/dist/browser/websocket/websocketNode.js.map +1 -0
  55. package/dist/commonjs/auth/credentialHandler.d.ts +43 -0
  56. package/dist/commonjs/auth/credentialHandler.js +151 -0
  57. package/dist/commonjs/auth/credentialHandler.js.map +1 -0
  58. package/dist/commonjs/errors/connectionErrors.d.ts +68 -0
  59. package/dist/commonjs/errors/connectionErrors.js +146 -0
  60. package/dist/commonjs/errors/connectionErrors.js.map +1 -0
  61. package/dist/commonjs/errors/index.d.ts +2 -0
  62. package/dist/commonjs/errors/index.js +7 -0
  63. package/dist/commonjs/errors/index.js.map +1 -0
  64. package/dist/commonjs/handlers/sessionHandlers.d.ts +250 -0
  65. package/dist/commonjs/handlers/sessionHandlers.js +5 -0
  66. package/dist/commonjs/handlers/sessionHandlers.js.map +1 -0
  67. package/dist/commonjs/handlers/subscriptionManager.d.ts +54 -0
  68. package/dist/commonjs/handlers/subscriptionManager.js +255 -0
  69. package/dist/commonjs/handlers/subscriptionManager.js.map +1 -0
  70. package/dist/commonjs/index.d.ts +7 -0
  71. package/dist/commonjs/index.js +45 -0
  72. package/dist/commonjs/index.js.map +1 -0
  73. package/dist/commonjs/logger.d.ts +2 -0
  74. package/dist/commonjs/logger.js +8 -0
  75. package/dist/commonjs/logger.js.map +1 -0
  76. package/dist/commonjs/models/index.d.ts +2 -0
  77. package/dist/commonjs/models/index.js +27 -0
  78. package/dist/commonjs/models/index.js.map +1 -0
  79. package/dist/commonjs/models/models.d.ts +2154 -0
  80. package/dist/commonjs/models/models.js +2463 -0
  81. package/dist/commonjs/models/models.js.map +1 -0
  82. package/dist/commonjs/package.json +3 -0
  83. package/dist/commonjs/protocol/messageParser.d.ts +42 -0
  84. package/dist/commonjs/protocol/messageParser.js +154 -0
  85. package/dist/commonjs/protocol/messageParser.js.map +1 -0
  86. package/dist/commonjs/tsdoc-metadata.json +11 -0
  87. package/dist/commonjs/voiceLiveClient.d.ts +65 -0
  88. package/dist/commonjs/voiceLiveClient.js +85 -0
  89. package/dist/commonjs/voiceLiveClient.js.map +1 -0
  90. package/dist/commonjs/voiceLiveSession.d.ts +138 -0
  91. package/dist/commonjs/voiceLiveSession.js +433 -0
  92. package/dist/commonjs/voiceLiveSession.js.map +1 -0
  93. package/dist/commonjs/websocket/connectionManager.d.ts +88 -0
  94. package/dist/commonjs/websocket/connectionManager.js +187 -0
  95. package/dist/commonjs/websocket/connectionManager.js.map +1 -0
  96. package/dist/commonjs/websocket/websocketBrowser.d.ts +26 -0
  97. package/dist/commonjs/websocket/websocketBrowser.js +179 -0
  98. package/dist/commonjs/websocket/websocketBrowser.js.map +1 -0
  99. package/dist/commonjs/websocket/websocketFactory.d.ts +23 -0
  100. package/dist/commonjs/websocket/websocketFactory.js +86 -0
  101. package/dist/commonjs/websocket/websocketFactory.js.map +1 -0
  102. package/dist/commonjs/websocket/websocketLike.d.ts +78 -0
  103. package/dist/commonjs/websocket/websocketLike.js +16 -0
  104. package/dist/commonjs/websocket/websocketLike.js.map +1 -0
  105. package/dist/commonjs/websocket/websocketNode.d.ts +26 -0
  106. package/dist/commonjs/websocket/websocketNode.js +185 -0
  107. package/dist/commonjs/websocket/websocketNode.js.map +1 -0
  108. package/dist/esm/auth/credentialHandler.d.ts +43 -0
  109. package/dist/esm/auth/credentialHandler.js +147 -0
  110. package/dist/esm/auth/credentialHandler.js.map +1 -0
  111. package/dist/esm/errors/connectionErrors.d.ts +68 -0
  112. package/dist/esm/errors/connectionErrors.js +136 -0
  113. package/dist/esm/errors/connectionErrors.js.map +1 -0
  114. package/dist/esm/errors/index.d.ts +2 -0
  115. package/dist/esm/errors/index.js +4 -0
  116. package/dist/esm/errors/index.js.map +1 -0
  117. package/dist/esm/handlers/sessionHandlers.d.ts +250 -0
  118. package/dist/esm/handlers/sessionHandlers.js +4 -0
  119. package/dist/esm/handlers/sessionHandlers.js.map +1 -0
  120. package/dist/esm/handlers/subscriptionManager.d.ts +54 -0
  121. package/dist/esm/handlers/subscriptionManager.js +250 -0
  122. package/dist/esm/handlers/subscriptionManager.js.map +1 -0
  123. package/dist/esm/index.d.ts +7 -0
  124. package/dist/esm/index.js +12 -0
  125. package/dist/esm/index.js.map +1 -0
  126. package/dist/esm/logger.d.ts +2 -0
  127. package/dist/esm/logger.js +5 -0
  128. package/dist/esm/logger.js.map +1 -0
  129. package/dist/esm/models/index.d.ts +2 -0
  130. package/dist/esm/models/index.js +4 -0
  131. package/dist/esm/models/index.js.map +1 -0
  132. package/dist/esm/models/models.d.ts +2154 -0
  133. package/dist/esm/models/models.js +2251 -0
  134. package/dist/esm/models/models.js.map +1 -0
  135. package/dist/esm/package.json +3 -0
  136. package/dist/esm/protocol/messageParser.d.ts +42 -0
  137. package/dist/esm/protocol/messageParser.js +150 -0
  138. package/dist/esm/protocol/messageParser.js.map +1 -0
  139. package/dist/esm/voiceLiveClient.d.ts +65 -0
  140. package/dist/esm/voiceLiveClient.js +81 -0
  141. package/dist/esm/voiceLiveClient.js.map +1 -0
  142. package/dist/esm/voiceLiveSession.d.ts +138 -0
  143. package/dist/esm/voiceLiveSession.js +429 -0
  144. package/dist/esm/voiceLiveSession.js.map +1 -0
  145. package/dist/esm/websocket/connectionManager.d.ts +88 -0
  146. package/dist/esm/websocket/connectionManager.js +183 -0
  147. package/dist/esm/websocket/connectionManager.js.map +1 -0
  148. package/dist/esm/websocket/websocketBrowser.d.ts +26 -0
  149. package/dist/esm/websocket/websocketBrowser.js +175 -0
  150. package/dist/esm/websocket/websocketBrowser.js.map +1 -0
  151. package/dist/esm/websocket/websocketFactory.d.ts +23 -0
  152. package/dist/esm/websocket/websocketFactory.js +80 -0
  153. package/dist/esm/websocket/websocketFactory.js.map +1 -0
  154. package/dist/esm/websocket/websocketLike.d.ts +78 -0
  155. package/dist/esm/websocket/websocketLike.js +13 -0
  156. package/dist/esm/websocket/websocketLike.js.map +1 -0
  157. package/dist/esm/websocket/websocketNode.d.ts +26 -0
  158. package/dist/esm/websocket/websocketNode.js +180 -0
  159. package/dist/esm/websocket/websocketNode.js.map +1 -0
  160. package/dist/react-native/auth/credentialHandler.d.ts +43 -0
  161. package/dist/react-native/auth/credentialHandler.js +147 -0
  162. package/dist/react-native/auth/credentialHandler.js.map +1 -0
  163. package/dist/react-native/errors/connectionErrors.d.ts +68 -0
  164. package/dist/react-native/errors/connectionErrors.js +136 -0
  165. package/dist/react-native/errors/connectionErrors.js.map +1 -0
  166. package/dist/react-native/errors/index.d.ts +2 -0
  167. package/dist/react-native/errors/index.js +4 -0
  168. package/dist/react-native/errors/index.js.map +1 -0
  169. package/dist/react-native/handlers/sessionHandlers.d.ts +250 -0
  170. package/dist/react-native/handlers/sessionHandlers.js +4 -0
  171. package/dist/react-native/handlers/sessionHandlers.js.map +1 -0
  172. package/dist/react-native/handlers/subscriptionManager.d.ts +54 -0
  173. package/dist/react-native/handlers/subscriptionManager.js +250 -0
  174. package/dist/react-native/handlers/subscriptionManager.js.map +1 -0
  175. package/dist/react-native/index.d.ts +7 -0
  176. package/dist/react-native/index.js +12 -0
  177. package/dist/react-native/index.js.map +1 -0
  178. package/dist/react-native/logger.d.ts +2 -0
  179. package/dist/react-native/logger.js +5 -0
  180. package/dist/react-native/logger.js.map +1 -0
  181. package/dist/react-native/models/index.d.ts +2 -0
  182. package/dist/react-native/models/index.js +4 -0
  183. package/dist/react-native/models/index.js.map +1 -0
  184. package/dist/react-native/models/models.d.ts +2154 -0
  185. package/dist/react-native/models/models.js +2251 -0
  186. package/dist/react-native/models/models.js.map +1 -0
  187. package/dist/react-native/package.json +3 -0
  188. package/dist/react-native/protocol/messageParser.d.ts +42 -0
  189. package/dist/react-native/protocol/messageParser.js +150 -0
  190. package/dist/react-native/protocol/messageParser.js.map +1 -0
  191. package/dist/react-native/voiceLiveClient.d.ts +65 -0
  192. package/dist/react-native/voiceLiveClient.js +81 -0
  193. package/dist/react-native/voiceLiveClient.js.map +1 -0
  194. package/dist/react-native/voiceLiveSession.d.ts +138 -0
  195. package/dist/react-native/voiceLiveSession.js +429 -0
  196. package/dist/react-native/voiceLiveSession.js.map +1 -0
  197. package/dist/react-native/websocket/connectionManager.d.ts +88 -0
  198. package/dist/react-native/websocket/connectionManager.js +183 -0
  199. package/dist/react-native/websocket/connectionManager.js.map +1 -0
  200. package/dist/react-native/websocket/websocketBrowser.d.ts +26 -0
  201. package/dist/react-native/websocket/websocketBrowser.js +175 -0
  202. package/dist/react-native/websocket/websocketBrowser.js.map +1 -0
  203. package/dist/react-native/websocket/websocketFactory.d.ts +23 -0
  204. package/dist/react-native/websocket/websocketFactory.js +80 -0
  205. package/dist/react-native/websocket/websocketFactory.js.map +1 -0
  206. package/dist/react-native/websocket/websocketLike.d.ts +78 -0
  207. package/dist/react-native/websocket/websocketLike.js +13 -0
  208. package/dist/react-native/websocket/websocketLike.js.map +1 -0
  209. package/dist/react-native/websocket/websocketNode.d.ts +26 -0
  210. package/dist/react-native/websocket/websocketNode.js +180 -0
  211. package/dist/react-native/websocket/websocketNode.js.map +1 -0
  212. package/package.json +150 -0
@@ -0,0 +1,42 @@
1
+ import type { ServerEventUnion, ClientEventUnion } from "../models/index.js";
2
+ /**
3
+ * Parsed message containing event data and metadata
4
+ */
5
+ export interface ParsedMessage {
6
+ /** Type of event: client or server */
7
+ type: "client" | "server";
8
+ /** Parsed event data */
9
+ event: ClientEventUnion | ServerEventUnion;
10
+ /** Original raw data for debugging */
11
+ raw: string | ArrayBuffer;
12
+ }
13
+ /**
14
+ * Parses and serializes Voice Live protocol messages
15
+ */
16
+ export declare class VoiceLiveMessageParser {
17
+ /**
18
+ * Parses incoming WebSocket message data into typed events
19
+ */
20
+ parseIncomingMessage(data: string | ArrayBuffer): ParsedMessage | null;
21
+ /**
22
+ * Serializes outgoing client events for WebSocket transmission
23
+ */
24
+ serializeOutgoingMessage(event: ClientEventUnion): string;
25
+ /**
26
+ * Checks if the parsed data represents a server event
27
+ */
28
+ private _isServerEvent;
29
+ /**
30
+ * Checks if the parsed data represents a client event
31
+ */
32
+ private _isClientEvent;
33
+ /**
34
+ * Validates if the type string represents a valid server event type
35
+ */
36
+ private _isValidServerEventType;
37
+ /**
38
+ * Validates if the type string represents a valid client event type
39
+ */
40
+ private _isValidClientEventType;
41
+ }
42
+ //# sourceMappingURL=messageParser.d.ts.map
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.VoiceLiveMessageParser = void 0;
6
+ const models_js_1 = require("../models/models.js");
7
+ /**
8
+ * Parses and serializes Voice Live protocol messages
9
+ */
10
+ class VoiceLiveMessageParser {
11
+ /**
12
+ * Parses incoming WebSocket message data into typed events
13
+ */
14
+ parseIncomingMessage(data) {
15
+ try {
16
+ let messageText;
17
+ if (data instanceof ArrayBuffer) {
18
+ messageText = new TextDecoder().decode(data);
19
+ }
20
+ else {
21
+ messageText = data;
22
+ }
23
+ const parsedData = JSON.parse(messageText);
24
+ // Validate and type the message based on the 'type' field
25
+ if (this._isServerEvent(parsedData)) {
26
+ return {
27
+ type: "server",
28
+ event: (0, models_js_1.serverEventUnionDeserializer)(parsedData),
29
+ raw: data,
30
+ };
31
+ }
32
+ // Handle unexpected client events (shouldn't normally receive these from server)
33
+ if (this._isClientEvent(parsedData)) {
34
+ return {
35
+ type: "client",
36
+ event: parsedData,
37
+ raw: data,
38
+ };
39
+ }
40
+ return null; // Unknown message format
41
+ }
42
+ catch (error) {
43
+ // Invalid JSON or parsing error
44
+ return null;
45
+ }
46
+ }
47
+ /**
48
+ * Serializes outgoing client events for WebSocket transmission
49
+ */
50
+ serializeOutgoingMessage(event) {
51
+ return JSON.stringify((0, models_js_1.clientEventUnionSerializer)(event));
52
+ }
53
+ /**
54
+ * Checks if the parsed data represents a server event
55
+ */
56
+ _isServerEvent(data) {
57
+ // Check if data matches ServerEventUnion structure
58
+ return data && typeof data.type === "string" && this._isValidServerEventType(data.type);
59
+ }
60
+ /**
61
+ * Checks if the parsed data represents a client event
62
+ */
63
+ _isClientEvent(data) {
64
+ // Check if data matches ClientEventUnion structure
65
+ return data && typeof data.type === "string" && this._isValidClientEventType(data.type);
66
+ }
67
+ /**
68
+ * Validates if the type string represents a valid server event type
69
+ */
70
+ _isValidServerEventType(type) {
71
+ // Based on the comprehensive analysis in EXISTING_TYPES_ANALYSIS.md
72
+ const validServerTypes = [
73
+ // Error handling
74
+ "error",
75
+ // Session management
76
+ "session.created",
77
+ "session.updated",
78
+ "session.avatar.connecting",
79
+ // Audio buffer events
80
+ "input_audio_buffer.committed",
81
+ "input_audio_buffer.cleared",
82
+ "input_audio_buffer.speech_started",
83
+ "input_audio_buffer.speech_stopped",
84
+ // Conversation item events
85
+ "conversation.item.created",
86
+ "conversation.item.truncated",
87
+ "conversation.item.deleted",
88
+ "conversation.item.retrieved",
89
+ "conversation.item.input_audio_transcription.completed",
90
+ "conversation.item.input_audio_transcription.failed",
91
+ "conversation.item.input_audio_transcription.delta",
92
+ // Response lifecycle events
93
+ "response.created",
94
+ "response.done",
95
+ "response.output_item.added",
96
+ "response.output_item.done",
97
+ // Content streaming events
98
+ "response.content_part.added",
99
+ "response.content_part.done",
100
+ "response.text.delta",
101
+ "response.text.done",
102
+ // Audio streaming events
103
+ "response.audio_transcript.delta",
104
+ "response.audio_transcript.done",
105
+ "response.audio.delta",
106
+ "response.audio.done",
107
+ // Animation events
108
+ "response.animation.blendshape.delta",
109
+ "response.animation.blendshape.done",
110
+ "response.animation.viseme.delta",
111
+ "response.animation.viseme.done",
112
+ // Timestamp events
113
+ "response.audio.timestamp.delta",
114
+ "response.audio.timestamp.done",
115
+ // Function call events
116
+ "response.function_call_arguments.delta",
117
+ "response.function_call_arguments.done",
118
+ ];
119
+ return validServerTypes.includes(type);
120
+ }
121
+ /**
122
+ * Validates if the type string represents a valid client event type
123
+ */
124
+ _isValidClientEventType(type) {
125
+ // Based on the comprehensive analysis in EXISTING_TYPES_ANALYSIS.md
126
+ const validClientTypes = [
127
+ // Session management
128
+ "session.update",
129
+ "session.avatar.connect",
130
+ // Turn-based audio
131
+ "input_audio_turn.start",
132
+ "input_audio_turn.append",
133
+ "input_audio_turn.end",
134
+ "input_audio_turn.cancel",
135
+ // Buffer-based audio
136
+ "input_audio_buffer.append",
137
+ "input_audio_buffer.commit",
138
+ "input_audio_buffer.clear",
139
+ // Audio control
140
+ "input_audio.clear",
141
+ // Conversation management
142
+ "conversation.item.create",
143
+ "conversation.item.truncate",
144
+ "conversation.item.delete",
145
+ "conversation.item.retrieve",
146
+ // Response management
147
+ "response.create",
148
+ "response.cancel",
149
+ ];
150
+ return validClientTypes.includes(type);
151
+ }
152
+ }
153
+ exports.VoiceLiveMessageParser = VoiceLiveMessageParser;
154
+ //# sourceMappingURL=messageParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageParser.js","sourceRoot":"","sources":["../../../src/protocol/messageParser.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,mDAA+F;AAc/F;;GAEG;AACH,M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YAC3B,0BAA0B;YAE1B,gBAAgB;YAChB,mBAAmB;YAEnB,0BAA0B;YAC1B,0BAA0B;YAC1B,4BAA4B;YAC5B,0BAA0B;YAC1B,4BAA4B;YAE5B,sBAAsB;YACtB,iBAAiB;YACjB,iBAAiB;SAClB,CAAC;QAEF,OAAO,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CACF;AAtKD,wDAsKC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ServerEventUnion, ClientEventUnion } from \"../models/index.js\";\nimport { clientEventUnionSerializer, serverEventUnionDeserializer } from \"../models/models.js\";\n\n/**\n * Parsed message containing event data and metadata\n */\nexport interface ParsedMessage {\n /** Type of event: client or server */\n type: \"client\" | \"server\";\n /** Parsed event data */\n event: ClientEventUnion | ServerEventUnion;\n /** Original raw data for debugging */\n raw: string | ArrayBuffer;\n}\n\n/**\n * Parses and serializes Voice Live protocol messages\n */\nexport class VoiceLiveMessageParser {\n /**\n * Parses incoming WebSocket message data into typed events\n */\n parseIncomingMessage(data: string | ArrayBuffer): ParsedMessage | null {\n try {\n let messageText: string;\n\n if (data instanceof ArrayBuffer) {\n messageText = new TextDecoder().decode(data);\n } else {\n messageText = data;\n }\n\n const parsedData = JSON.parse(messageText);\n\n // Validate and type the message based on the 'type' field\n if (this._isServerEvent(parsedData)) {\n return {\n type: \"server\",\n event: serverEventUnionDeserializer(parsedData),\n raw: data,\n };\n }\n\n // Handle unexpected client events (shouldn't normally receive these from server)\n if (this._isClientEvent(parsedData)) {\n return {\n type: \"client\",\n event: parsedData as ClientEventUnion,\n raw: data,\n };\n }\n\n return null; // Unknown message format\n } catch (error) {\n // Invalid JSON or parsing error\n return null;\n }\n }\n\n /**\n * Serializes outgoing client events for WebSocket transmission\n */\n serializeOutgoingMessage(event: ClientEventUnion): string {\n return JSON.stringify(clientEventUnionSerializer(event));\n }\n\n /**\n * Checks if the parsed data represents a server event\n */\n private _isServerEvent(data: any): boolean {\n // Check if data matches ServerEventUnion structure\n return data && typeof data.type === \"string\" && this._isValidServerEventType(data.type);\n }\n\n /**\n * Checks if the parsed data represents a client event\n */\n private _isClientEvent(data: any): boolean {\n // Check if data matches ClientEventUnion structure\n return data && typeof data.type === \"string\" && this._isValidClientEventType(data.type);\n }\n\n /**\n * Validates if the type string represents a valid server event type\n */\n private _isValidServerEventType(type: string): boolean {\n // Based on the comprehensive analysis in EXISTING_TYPES_ANALYSIS.md\n const validServerTypes = [\n // Error handling\n \"error\",\n\n // Session management\n \"session.created\",\n \"session.updated\",\n \"session.avatar.connecting\",\n\n // Audio buffer events\n \"input_audio_buffer.committed\",\n \"input_audio_buffer.cleared\",\n \"input_audio_buffer.speech_started\",\n \"input_audio_buffer.speech_stopped\",\n\n // Conversation item events\n \"conversation.item.created\",\n \"conversation.item.truncated\",\n \"conversation.item.deleted\",\n \"conversation.item.retrieved\",\n \"conversation.item.input_audio_transcription.completed\",\n \"conversation.item.input_audio_transcription.failed\",\n \"conversation.item.input_audio_transcription.delta\",\n\n // Response lifecycle events\n \"response.created\",\n \"response.done\",\n \"response.output_item.added\",\n \"response.output_item.done\",\n\n // Content streaming events\n \"response.content_part.added\",\n \"response.content_part.done\",\n \"response.text.delta\",\n \"response.text.done\",\n\n // Audio streaming events\n \"response.audio_transcript.delta\",\n \"response.audio_transcript.done\",\n \"response.audio.delta\",\n \"response.audio.done\",\n\n // Animation events\n \"response.animation.blendshape.delta\",\n \"response.animation.blendshape.done\",\n \"response.animation.viseme.delta\",\n \"response.animation.viseme.done\",\n\n // Timestamp events\n \"response.audio.timestamp.delta\",\n \"response.audio.timestamp.done\",\n\n // Function call events\n \"response.function_call_arguments.delta\",\n \"response.function_call_arguments.done\",\n ];\n\n return validServerTypes.includes(type);\n }\n\n /**\n * Validates if the type string represents a valid client event type\n */\n private _isValidClientEventType(type: string): boolean {\n // Based on the comprehensive analysis in EXISTING_TYPES_ANALYSIS.md\n const validClientTypes = [\n // Session management\n \"session.update\",\n \"session.avatar.connect\",\n\n // Turn-based audio\n \"input_audio_turn.start\",\n \"input_audio_turn.append\",\n \"input_audio_turn.end\",\n \"input_audio_turn.cancel\",\n\n // Buffer-based audio\n \"input_audio_buffer.append\",\n \"input_audio_buffer.commit\",\n \"input_audio_buffer.clear\",\n\n // Audio control\n \"input_audio.clear\",\n\n // Conversation management\n \"conversation.item.create\",\n \"conversation.item.truncate\",\n \"conversation.item.delete\",\n \"conversation.item.retrieve\",\n\n // Response management\n \"response.create\",\n \"response.cancel\",\n ];\n\n return validClientTypes.includes(type);\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.55.0"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,65 @@
1
+ import type { KeyCredential, TokenCredential } from "@azure/core-auth";
2
+ import type { RequestSession } from "./models/index.js";
3
+ import type { CreateSessionOptions, StartSessionOptions, VoiceLiveSessionOptions } from "./voiceLiveSession.js";
4
+ import { VoiceLiveSession } from "./voiceLiveSession.js";
5
+ export interface VoiceLiveClientOptions {
6
+ /** API version to use for the Voice Live service */
7
+ apiVersion?: string;
8
+ /** Default session options to apply to all created sessions */
9
+ defaultSessionOptions?: VoiceLiveSessionOptions;
10
+ }
11
+ /**
12
+ * The VoiceLive client provides session management for real-time conversational AI capabilities.
13
+ *
14
+ * This client acts as a factory for creating VoiceLiveSession instances, which handle the actual
15
+ * WebSocket connections and real-time interactions with the service.
16
+ */
17
+ export declare class VoiceLiveClient {
18
+ private readonly _endpoint;
19
+ private readonly _credential;
20
+ private readonly _options;
21
+ /**
22
+ * Creates an instance of VoiceLiveClient with endpoint and credential.
23
+ *
24
+ * @param endpoint - The Voice Live service endpoint URL
25
+ * @param credential - Azure TokenCredential or KeyCredential for authentication
26
+ * @param options - Optional configuration for the client
27
+ */
28
+ constructor(endpoint: string, credential: TokenCredential | KeyCredential, options?: VoiceLiveClientOptions);
29
+ /**
30
+ * Creates a new VoiceLiveSession for real-time voice communication.
31
+ *
32
+ * @param model - The model name to use for the session (e.g., "gpt-4o-realtime-preview")
33
+ * @param sessionOptions - Optional configuration specific to this session
34
+ * @returns A new VoiceLiveSession instance ready to connect
35
+ */
36
+ createSession(model: string, sessionOptions?: CreateSessionOptions): VoiceLiveSession;
37
+ /**
38
+ * Creates a new VoiceLiveSession for real-time voice communication with session configuration.
39
+ *
40
+ * @param sessionConfig - Session configuration including model and other settings
41
+ * @returns A new VoiceLiveSession instance ready to connect
42
+ */
43
+ createSession(sessionConfig: RequestSession, sessionOptions?: CreateSessionOptions): VoiceLiveSession;
44
+ /**
45
+ * Creates and immediately connects a new VoiceLiveSession.
46
+ *
47
+ * @param model - The model name to use for the session (e.g., "gpt-4o-realtime-preview")
48
+ * @param sessionOptions - Optional configuration specific to this session
49
+ * @returns A connected VoiceLiveSession instance
50
+ */
51
+ startSession(model: string, sessionOptions?: StartSessionOptions): Promise<VoiceLiveSession>;
52
+ /**
53
+ * Creates and immediately connects a new VoiceLiveSession with session configuration.
54
+ *
55
+ * @param sessionConfig - Session configuration including model and other settings
56
+ * @param sessionOptions - Optional configuration specific to this session
57
+ * @returns A connected VoiceLiveSession instance
58
+ */
59
+ startSession(sessionConfig: RequestSession, sessionOptions?: StartSessionOptions): Promise<VoiceLiveSession>;
60
+ get endpoint(): string;
61
+ get apiVersion(): string;
62
+ private _buildDefaultOptions;
63
+ private _normalizeEndpoint;
64
+ }
65
+ //# sourceMappingURL=voiceLiveClient.d.ts.map
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.VoiceLiveClient = void 0;
6
+ const voiceLiveSession_js_1 = require("./voiceLiveSession.js");
7
+ const logger_js_1 = require("./logger.js");
8
+ /**
9
+ * The VoiceLive client provides session management for real-time conversational AI capabilities.
10
+ *
11
+ * This client acts as a factory for creating VoiceLiveSession instances, which handle the actual
12
+ * WebSocket connections and real-time interactions with the service.
13
+ */
14
+ class VoiceLiveClient {
15
+ _endpoint;
16
+ _credential;
17
+ _options;
18
+ /**
19
+ * Creates an instance of VoiceLiveClient with endpoint and credential.
20
+ *
21
+ * @param endpoint - The Voice Live service endpoint URL
22
+ * @param credential - Azure TokenCredential or KeyCredential for authentication
23
+ * @param options - Optional configuration for the client
24
+ */
25
+ constructor(endpoint, credential, options = {}) {
26
+ this._endpoint = this._normalizeEndpoint(endpoint);
27
+ this._credential = credential;
28
+ this._options = this._buildDefaultOptions(options);
29
+ logger_js_1.logger.info("VoiceLiveClient created", {
30
+ endpoint: this._endpoint,
31
+ apiVersion: this._options.apiVersion,
32
+ });
33
+ }
34
+ createSession(modelOrConfig, sessionOptions) {
35
+ // Extract model name from the parameter
36
+ const model = typeof modelOrConfig === "string" ? modelOrConfig : modelOrConfig.model;
37
+ if (!model) {
38
+ throw new Error("Model name is required. Provide either a model string or RequestSession with model property.");
39
+ }
40
+ // Merge default session options with provided options
41
+ const mergedOptions = {
42
+ ...this._options.defaultSessionOptions,
43
+ ...sessionOptions,
44
+ };
45
+ const session = new voiceLiveSession_js_1.VoiceLiveSession(this._endpoint, this._credential, this._options.apiVersion, model, mergedOptions);
46
+ // If full session config was provided, store it for later use
47
+ if (typeof modelOrConfig !== "string") {
48
+ session._initialSessionConfig = modelOrConfig;
49
+ }
50
+ logger_js_1.logger.info("VoiceLiveSession created", { model });
51
+ return session;
52
+ }
53
+ async startSession(modelOrConfig, sessionOptions) {
54
+ const session = this.createSession(modelOrConfig, sessionOptions);
55
+ await session.connect();
56
+ // If full session config was provided, send it after connection
57
+ if (typeof modelOrConfig !== "string") {
58
+ await session.updateSession(modelOrConfig);
59
+ }
60
+ return session;
61
+ }
62
+ // Properties
63
+ get endpoint() {
64
+ return this._endpoint;
65
+ }
66
+ get apiVersion() {
67
+ return this._options.apiVersion;
68
+ }
69
+ _buildDefaultOptions(options) {
70
+ return {
71
+ apiVersion: options.apiVersion || "2025-10-01",
72
+ defaultSessionOptions: options.defaultSessionOptions || {},
73
+ };
74
+ }
75
+ _normalizeEndpoint(endpoint) {
76
+ // Ensure endpoint has proper protocol
77
+ if (!endpoint.startsWith("http://") && !endpoint.startsWith("https://")) {
78
+ endpoint = `https://${endpoint}`;
79
+ }
80
+ // Remove trailing slash
81
+ return endpoint.replace(/\/$/, "");
82
+ }
83
+ }
84
+ exports.VoiceLiveClient = VoiceLiveClient;
85
+ //# sourceMappingURL=voiceLiveClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voiceLiveClient.js","sourceRoot":"","sources":["../../src/voiceLiveClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AASlC,+DAAyD;AACzD,2CAAqC;AASrC;;;;;GAKG;AACH,MAAa,eAAe;IACT,SAAS,CAAS;IAClB,WAAW,CAAkC;IAC7C,QAAQ,CAAmC;IAE5D;;;;;;OAMG;IACH,YACE,QAAgB,EAChB,UAA2C,EAC3C,UAAkC,EAAE;QAEpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEnD,kBAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE;YACrC,QAAQ,EAAE,IAAI,CAAC,SAAS;YACxB,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU;SACrC,CAAC,CAAC;IACL,CAAC;IAsBD,aAAa,CACX,aAAsC,EACtC,cAAqC;QAErC,wCAAwC;QACxC,MAAM,KAAK,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,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YAC9C,qBAAqB,EAAE,OAAO,CAAC,qBAAqB,IAAI,EAAE;SAC3D,CAAC;IACJ,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACzC,sCAAsC;QACtC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACxE,QAAQ,GAAG,WAAW,QAAQ,EAAE,CAAC;QACnC,CAAC;QAED,wBAAwB;QACxB,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAlJD,0CAkJC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport type { RequestSession } from \"./models/index.js\";\nimport type {\n CreateSessionOptions,\n StartSessionOptions,\n VoiceLiveSessionOptions,\n} from \"./voiceLiveSession.js\";\nimport { VoiceLiveSession } from \"./voiceLiveSession.js\";\nimport { logger } from \"./logger.js\";\n\nexport interface VoiceLiveClientOptions {\n /** API version to use for the Voice Live service */\n apiVersion?: string;\n /** Default session options to apply to all created sessions */\n defaultSessionOptions?: VoiceLiveSessionOptions;\n}\n\n/**\n * The VoiceLive client provides session management for real-time conversational AI capabilities.\n *\n * This client acts as a factory for creating VoiceLiveSession instances, which handle the actual\n * WebSocket connections and real-time interactions with the service.\n */\nexport class VoiceLiveClient {\n private readonly _endpoint: string;\n private readonly _credential: TokenCredential | KeyCredential;\n private readonly _options: Required<VoiceLiveClientOptions>;\n\n /**\n * Creates an instance of VoiceLiveClient with endpoint and credential.\n *\n * @param endpoint - The Voice Live service endpoint URL\n * @param credential - Azure TokenCredential or KeyCredential for authentication\n * @param options - Optional configuration for the client\n */\n constructor(\n endpoint: string,\n credential: TokenCredential | KeyCredential,\n options: VoiceLiveClientOptions = {},\n ) {\n this._endpoint = this._normalizeEndpoint(endpoint);\n this._credential = credential;\n this._options = this._buildDefaultOptions(options);\n\n logger.info(\"VoiceLiveClient created\", {\n endpoint: this._endpoint,\n apiVersion: this._options.apiVersion,\n });\n }\n\n /**\n * Creates a new VoiceLiveSession for real-time voice communication.\n *\n * @param model - The model name to use for the session (e.g., \"gpt-4o-realtime-preview\")\n * @param sessionOptions - Optional configuration specific to this session\n * @returns A new VoiceLiveSession instance ready to connect\n */\n createSession(model: string, sessionOptions?: CreateSessionOptions): VoiceLiveSession;\n\n /**\n * Creates a new VoiceLiveSession for real-time voice communication with session configuration.\n *\n * @param sessionConfig - Session configuration including model and other settings\n * @returns A new VoiceLiveSession instance ready to connect\n */\n createSession(\n sessionConfig: RequestSession,\n sessionOptions?: CreateSessionOptions,\n ): VoiceLiveSession;\n\n createSession(\n modelOrConfig: string | RequestSession,\n sessionOptions?: CreateSessionOptions,\n ): VoiceLiveSession {\n // Extract model name from the parameter\n const model = typeof modelOrConfig === \"string\" ? modelOrConfig : modelOrConfig.model;\n if (!model) {\n throw new Error(\n \"Model name is required. Provide either a model string or RequestSession with model property.\",\n );\n }\n\n // Merge default session options with provided options\n const mergedOptions: VoiceLiveSessionOptions = {\n ...this._options.defaultSessionOptions,\n ...sessionOptions,\n };\n\n const session = new VoiceLiveSession(\n this._endpoint,\n this._credential,\n this._options.apiVersion,\n model,\n mergedOptions,\n );\n\n // If full session config was provided, store it for later use\n if (typeof modelOrConfig !== \"string\") {\n (session as any)._initialSessionConfig = modelOrConfig;\n }\n\n logger.info(\"VoiceLiveSession created\", { model });\n return session;\n }\n\n /**\n * Creates and immediately connects a new VoiceLiveSession.\n *\n * @param model - The model name to use for the session (e.g., \"gpt-4o-realtime-preview\")\n * @param sessionOptions - Optional configuration specific to this session\n * @returns A connected VoiceLiveSession instance\n */\n async startSession(\n model: string,\n sessionOptions?: StartSessionOptions,\n ): Promise<VoiceLiveSession>;\n\n /**\n * Creates and immediately connects a new VoiceLiveSession with session configuration.\n *\n * @param sessionConfig - Session configuration including model and other settings\n * @param sessionOptions - Optional configuration specific to this session\n * @returns A connected VoiceLiveSession instance\n */\n async startSession(\n sessionConfig: RequestSession,\n sessionOptions?: StartSessionOptions,\n ): Promise<VoiceLiveSession>;\n\n async startSession(\n modelOrConfig: string | RequestSession,\n sessionOptions?: StartSessionOptions,\n ): Promise<VoiceLiveSession> {\n const session = this.createSession(modelOrConfig as any, sessionOptions);\n await session.connect();\n\n // If full session config was provided, send it after connection\n if (typeof modelOrConfig !== \"string\") {\n await session.updateSession(modelOrConfig);\n }\n\n return session;\n }\n\n // Properties\n get endpoint(): string {\n return this._endpoint;\n }\n\n get apiVersion(): string {\n return this._options.apiVersion;\n }\n\n private _buildDefaultOptions(options: VoiceLiveClientOptions): Required<VoiceLiveClientOptions> {\n return {\n apiVersion: options.apiVersion || \"2025-10-01\",\n defaultSessionOptions: options.defaultSessionOptions || {},\n };\n }\n\n private _normalizeEndpoint(endpoint: string): string {\n // Ensure endpoint has proper protocol\n if (!endpoint.startsWith(\"http://\") && !endpoint.startsWith(\"https://\")) {\n endpoint = `https://${endpoint}`;\n }\n\n // Remove trailing slash\n return endpoint.replace(/\\/$/, \"\");\n }\n}\n"]}
@@ -0,0 +1,138 @@
1
+ import type { KeyCredential, TokenCredential } from "@azure/core-auth";
2
+ import type { AbortSignalLike } from "@azure/abort-controller";
3
+ import type { RequestSession, ClientEventUnion, ConversationRequestItem } from "./models/index.js";
4
+ import { ConnectionState } from "./websocket/connectionManager.js";
5
+ import type { VoiceLiveSessionHandlers, VoiceLiveSubscription } from "./handlers/sessionHandlers.js";
6
+ export interface VoiceLiveSessionOptions {
7
+ /** Connection timeout in milliseconds */
8
+ connectionTimeoutInMs?: number;
9
+ /** Enable debug logging for development */
10
+ enableDebugLogging?: boolean;
11
+ }
12
+ export interface CreateSessionOptions extends VoiceLiveSessionOptions {
13
+ }
14
+ export interface StartSessionOptions extends VoiceLiveSessionOptions {
15
+ }
16
+ export interface ConnectOptions {
17
+ /** Abort signal to cancel connection attempt */
18
+ abortSignal?: AbortSignalLike;
19
+ /** Override connection timeout for this operation */
20
+ timeoutInMs?: number;
21
+ }
22
+ export interface SendEventOptions {
23
+ /** Abort signal to cancel send operation */
24
+ abortSignal?: AbortSignalLike;
25
+ /** Timeout for send operation */
26
+ timeoutInMs?: number;
27
+ }
28
+ export interface AudioStreamOptions extends SendEventOptions {
29
+ /** Turn ID for turn-based audio (if not provided, uses buffer mode) */
30
+ turnId?: string;
31
+ }
32
+ export interface TurnOptions extends SendEventOptions {
33
+ /** Custom turn ID (if not provided, one will be generated) */
34
+ turnId?: string;
35
+ }
36
+ /**
37
+ * Represents a WebSocket-based session for real-time voice communication with the Azure VoiceLive service.
38
+ *
39
+ * This class manages the connection, handles real-time communication, and provides access to all
40
+ * interactive features including audio streaming, conversation management, and avatar control.
41
+ */
42
+ export declare class VoiceLiveSession {
43
+ private readonly _endpoint;
44
+ private readonly _credentialHandler;
45
+ private readonly _options;
46
+ private readonly _messageParser;
47
+ private readonly _model;
48
+ private _connectionManager?;
49
+ private _sessionId?;
50
+ private _activeTurnId?;
51
+ private _disposed;
52
+ private readonly _subscriptionManager;
53
+ /**
54
+ * Creates an instance of VoiceLiveSession.
55
+ *
56
+ * @param endpoint - The Voice Live service endpoint URL
57
+ * @param credential - Azure TokenCredential or KeyCredential for authentication
58
+ * @param apiVersion - API version to use for the Voice Live service
59
+ * @param model - The model name to use for the session
60
+ * @param options - Optional configuration for the session
61
+ */
62
+ constructor(endpoint: string, credential: TokenCredential | KeyCredential, apiVersion: string, model: string, options?: VoiceLiveSessionOptions);
63
+ /**
64
+ * Establishes connection to the Voice Live service with authentication.
65
+ */
66
+ connect(options?: ConnectOptions): Promise<void>;
67
+ /**
68
+ * Disconnects from the Voice Live service and cleans up resources.
69
+ */
70
+ disconnect(): Promise<void>;
71
+ /**
72
+ * Subscribe to VoiceLive session events using strongly-typed handlers.
73
+ * This follows the Azure SDK pattern used by EventHub, Service Bus, etc.
74
+ *
75
+ * @param handlers - Handler functions for different types of events
76
+ * @returns A subscription object that can be used to stop receiving events
77
+ */
78
+ subscribe(handlers: VoiceLiveSessionHandlers): VoiceLiveSubscription;
79
+ /**
80
+ * Sends a custom client event to the service.
81
+ */
82
+ sendEvent(event: ClientEventUnion, options?: SendEventOptions): Promise<void>;
83
+ /**
84
+ * Updates the session configuration with the service.
85
+ */
86
+ updateSession(session: RequestSession, options?: SendEventOptions): Promise<void>;
87
+ /**
88
+ * Sends audio data to the service using turn-based or buffer-based approach.
89
+ */
90
+ sendAudio(audioData: ArrayBuffer | Uint8Array, options?: AudioStreamOptions): Promise<void>;
91
+ /**
92
+ * Starts a new audio turn for turn-based audio input.
93
+ */
94
+ startAudioTurn(options?: TurnOptions): Promise<string>;
95
+ /**
96
+ * Ends the current audio turn.
97
+ */
98
+ endAudioTurn(turnId?: string, options?: SendEventOptions): Promise<void>;
99
+ /**
100
+ * Adds a conversation item (message) to the conversation.
101
+ */
102
+ addConversationItem(item: ConversationRequestItem, options?: SendEventOptions): Promise<void>;
103
+ /**
104
+ * Indicates whether the session is currently connected to the Voice Live service.
105
+ */
106
+ get isConnected(): boolean;
107
+ /**
108
+ * Gets the current connection state of the session.
109
+ */
110
+ get connectionState(): ConnectionState;
111
+ /**
112
+ * Gets the current session ID.
113
+ */
114
+ get sessionId(): string | undefined;
115
+ /**
116
+ * Gets the current active audio turn ID.
117
+ */
118
+ get activeTurnId(): string | undefined;
119
+ /**
120
+ * Disposes the session and cleans up resources.
121
+ */
122
+ dispose(): Promise<void>;
123
+ private _buildDefaultOptions;
124
+ private _normalizeEndpoint;
125
+ private _setupConnectionEventHandlers;
126
+ private _markSessionAsDead;
127
+ private _handleIncomingMessage;
128
+ private _handleServerEvent;
129
+ private _notifyConnectionEvent;
130
+ private _notifyServerEvent;
131
+ private _sendEvent;
132
+ private _ensureConnected;
133
+ private _ensureNotDisposed;
134
+ private _generateEventId;
135
+ private _generateTurnId;
136
+ private _arrayBufferToBase64;
137
+ }
138
+ //# sourceMappingURL=voiceLiveSession.d.ts.map