phonic 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import WebSocket from 'ws';
2
2
 
3
3
  type PhonicConfig = {
4
4
  baseUrl?: string;
5
+ __downstreamWebSocketUrl?: string;
5
6
  };
6
7
  type FetchOptions = {
7
8
  method: "GET";
@@ -67,7 +68,7 @@ declare class PhonicSTSWebSocket {
67
68
  audioChunk(message: {
68
69
  audio: string;
69
70
  }): void;
70
- close(): void;
71
+ close(code?: number): void;
71
72
  }
72
73
 
73
74
  declare class SpeechToSpeech {
@@ -102,6 +103,7 @@ declare class Voices {
102
103
  declare class Phonic {
103
104
  readonly apiKey: string;
104
105
  readonly baseUrl: string;
106
+ readonly __downstreamWebSocketUrl: string | null;
105
107
  private readonly headers;
106
108
  readonly voices: Voices;
107
109
  readonly sts: SpeechToSpeech;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import WebSocket from 'ws';
2
2
 
3
3
  type PhonicConfig = {
4
4
  baseUrl?: string;
5
+ __downstreamWebSocketUrl?: string;
5
6
  };
6
7
  type FetchOptions = {
7
8
  method: "GET";
@@ -67,7 +68,7 @@ declare class PhonicSTSWebSocket {
67
68
  audioChunk(message: {
68
69
  audio: string;
69
70
  }): void;
70
- close(): void;
71
+ close(code?: number): void;
71
72
  }
72
73
 
73
74
  declare class SpeechToSpeech {
@@ -102,6 +103,7 @@ declare class Voices {
102
103
  declare class Phonic {
103
104
  readonly apiKey: string;
104
105
  readonly baseUrl: string;
106
+ readonly __downstreamWebSocketUrl: string | null;
105
107
  private readonly headers;
106
108
  readonly voices: Voices;
107
109
  readonly sts: SpeechToSpeech;
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ __export(index_exports, {
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // package.json
38
- var version = "0.8.1";
38
+ var version = "0.9.0";
39
39
 
40
40
  // src/sts/index.ts
41
41
  var import_ws = __toESM(require("ws"));
@@ -94,8 +94,8 @@ var PhonicSTSWebSocket = class {
94
94
  })
95
95
  );
96
96
  }
97
- close() {
98
- this.ws.close();
97
+ close(code) {
98
+ this.ws.close(code ?? 1e3);
99
99
  }
100
100
  };
101
101
 
@@ -161,7 +161,12 @@ var SpeechToSpeech = class {
161
161
  }
162
162
  async websocket(config) {
163
163
  const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
164
- const phonicApiWsUrl = `${wsBaseUrl}/v1/sts/ws`;
164
+ const queryString = new URLSearchParams({
165
+ ...this.phonic.__downstreamWebSocketUrl !== null && {
166
+ downstream_websocket_url: this.phonic.__downstreamWebSocketUrl
167
+ }
168
+ }).toString();
169
+ const phonicApiWsUrl = `${wsBaseUrl}/v1/sts/ws?${queryString}`;
165
170
  let retryNumber = 0;
166
171
  const maxRetries = 14;
167
172
  const retryDelay = 15e3;
@@ -226,6 +231,7 @@ var Phonic = class {
226
231
  );
227
232
  }
228
233
  this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
234
+ this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
229
235
  this.headers = new Headers({
230
236
  Authorization: `Bearer ${this.apiKey}`,
231
237
  "User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
@@ -233,6 +239,7 @@ var Phonic = class {
233
239
  });
234
240
  }
235
241
  baseUrl;
242
+ __downstreamWebSocketUrl;
236
243
  headers;
237
244
  voices = new Voices(this);
238
245
  sts = new SpeechToSpeech(this);
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.8.1";
2
+ var version = "0.9.0";
3
3
 
4
4
  // src/sts/index.ts
5
5
  import WebSocket from "ws";
@@ -58,8 +58,8 @@ var PhonicSTSWebSocket = class {
58
58
  })
59
59
  );
60
60
  }
61
- close() {
62
- this.ws.close();
61
+ close(code) {
62
+ this.ws.close(code ?? 1e3);
63
63
  }
64
64
  };
65
65
 
@@ -125,7 +125,12 @@ var SpeechToSpeech = class {
125
125
  }
126
126
  async websocket(config) {
127
127
  const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
128
- const phonicApiWsUrl = `${wsBaseUrl}/v1/sts/ws`;
128
+ const queryString = new URLSearchParams({
129
+ ...this.phonic.__downstreamWebSocketUrl !== null && {
130
+ downstream_websocket_url: this.phonic.__downstreamWebSocketUrl
131
+ }
132
+ }).toString();
133
+ const phonicApiWsUrl = `${wsBaseUrl}/v1/sts/ws?${queryString}`;
129
134
  let retryNumber = 0;
130
135
  const maxRetries = 14;
131
136
  const retryDelay = 15e3;
@@ -190,6 +195,7 @@ var Phonic = class {
190
195
  );
191
196
  }
192
197
  this.baseUrl = (config?.baseUrl ?? defaultBaseUrl).replace(/\/$/, "");
198
+ this.__downstreamWebSocketUrl = config?.__downstreamWebSocketUrl || null;
193
199
  this.headers = new Headers({
194
200
  Authorization: `Bearer ${this.apiKey}`,
195
201
  "User-Agent": process.env.PHONIC_USER_AGENT || defaultUserAgent,
@@ -197,6 +203,7 @@ var Phonic = class {
197
203
  });
198
204
  }
199
205
  baseUrl;
206
+ __downstreamWebSocketUrl;
200
207
  headers;
201
208
  voices = new Voices(this);
202
209
  sts = new SpeechToSpeech(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phonic",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Phonic Node.js SDK",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -39,7 +39,7 @@
39
39
  "@biomejs/biome": "1.9.4",
40
40
  "@changesets/changelog-github": "0.5.1",
41
41
  "@changesets/cli": "2.28.1",
42
- "@types/bun": "1.2.4",
42
+ "@types/bun": "1.2.5",
43
43
  "tsup": "8.4.0",
44
44
  "typescript": "5.8.2",
45
45
  "zod": "3.24.2"