phonic 0.8.0 → 0.8.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.
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -3
- package/dist/index.mjs +10 -3
- package/package.json +2 -2
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";
|
|
@@ -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";
|
|
@@ -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.
|
|
38
|
+
var version = "0.8.2";
|
|
39
39
|
|
|
40
40
|
// src/sts/index.ts
|
|
41
41
|
var import_ws = __toESM(require("ws"));
|
|
@@ -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
|
|
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;
|
|
@@ -225,7 +230,8 @@ var Phonic = class {
|
|
|
225
230
|
'API key is missing. Pass it to the constructor: `new Phonic("ph_...")`'
|
|
226
231
|
);
|
|
227
232
|
}
|
|
228
|
-
this.baseUrl = config?.baseUrl ?? defaultBaseUrl;
|
|
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.
|
|
2
|
+
var version = "0.8.2";
|
|
3
3
|
|
|
4
4
|
// src/sts/index.ts
|
|
5
5
|
import WebSocket from "ws";
|
|
@@ -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
|
|
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;
|
|
@@ -189,7 +194,8 @@ var Phonic = class {
|
|
|
189
194
|
'API key is missing. Pass it to the constructor: `new Phonic("ph_...")`'
|
|
190
195
|
);
|
|
191
196
|
}
|
|
192
|
-
this.baseUrl = config?.baseUrl ?? defaultBaseUrl;
|
|
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.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Phonic Node.js SDK",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@changesets/cli": "2.28.1",
|
|
42
42
|
"@types/bun": "1.2.4",
|
|
43
43
|
"tsup": "8.4.0",
|
|
44
|
-
"typescript": "5.
|
|
44
|
+
"typescript": "5.8.2",
|
|
45
45
|
"zod": "3.24.2"
|
|
46
46
|
},
|
|
47
47
|
"files": ["dist/**"],
|