telnyx 6.8.0 → 6.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +39 -0
  3. package/package.json +1 -1
  4. package/resources/index.d.mts +2 -1
  5. package/resources/index.d.mts.map +1 -1
  6. package/resources/index.d.ts +2 -1
  7. package/resources/index.d.ts.map +1 -1
  8. package/resources/index.js +7 -2
  9. package/resources/index.js.map +1 -1
  10. package/resources/index.mjs +2 -1
  11. package/resources/index.mjs.map +1 -1
  12. package/resources/speech-to-text/index.d.mts +4 -0
  13. package/resources/speech-to-text/index.d.mts.map +1 -0
  14. package/resources/speech-to-text/index.d.ts +4 -0
  15. package/resources/speech-to-text/index.d.ts.map +1 -0
  16. package/resources/speech-to-text/index.js +11 -0
  17. package/resources/speech-to-text/index.js.map +1 -0
  18. package/resources/speech-to-text/index.mjs +5 -0
  19. package/resources/speech-to-text/index.mjs.map +1 -0
  20. package/resources/speech-to-text/internal-base.d.mts +40 -0
  21. package/resources/speech-to-text/internal-base.d.mts.map +1 -0
  22. package/resources/speech-to-text/internal-base.d.ts +40 -0
  23. package/resources/speech-to-text/internal-base.d.ts.map +1 -0
  24. package/resources/speech-to-text/internal-base.js +52 -0
  25. package/resources/speech-to-text/internal-base.js.map +1 -0
  26. package/resources/speech-to-text/internal-base.mjs +46 -0
  27. package/resources/speech-to-text/internal-base.mjs.map +1 -0
  28. package/resources/speech-to-text/speech-to-text.d.mts +86 -0
  29. package/resources/speech-to-text/speech-to-text.d.mts.map +1 -0
  30. package/resources/speech-to-text/speech-to-text.d.ts +86 -0
  31. package/resources/speech-to-text/speech-to-text.d.ts.map +1 -0
  32. package/resources/speech-to-text/speech-to-text.js +12 -0
  33. package/resources/speech-to-text/speech-to-text.js.map +1 -0
  34. package/resources/speech-to-text/speech-to-text.mjs +8 -0
  35. package/resources/speech-to-text/speech-to-text.mjs.map +1 -0
  36. package/resources/speech-to-text/ws.d.mts +32 -0
  37. package/resources/speech-to-text/ws.d.mts.map +1 -0
  38. package/resources/speech-to-text/ws.d.ts +32 -0
  39. package/resources/speech-to-text/ws.d.ts.map +1 -0
  40. package/resources/speech-to-text/ws.js +111 -0
  41. package/resources/speech-to-text/ws.js.map +1 -0
  42. package/resources/speech-to-text/ws.mjs +106 -0
  43. package/resources/speech-to-text/ws.mjs.map +1 -0
  44. package/resources/speech-to-text.d.mts +2 -0
  45. package/resources/speech-to-text.d.mts.map +1 -0
  46. package/resources/speech-to-text.d.ts +2 -0
  47. package/resources/speech-to-text.d.ts.map +1 -0
  48. package/resources/speech-to-text.js +6 -0
  49. package/resources/speech-to-text.js.map +1 -0
  50. package/resources/speech-to-text.mjs +3 -0
  51. package/resources/speech-to-text.mjs.map +1 -0
  52. package/resources/text-to-speech/index.d.mts +1 -0
  53. package/resources/text-to-speech/index.d.mts.map +1 -1
  54. package/resources/text-to-speech/index.d.ts +1 -0
  55. package/resources/text-to-speech/index.d.ts.map +1 -1
  56. package/resources/text-to-speech/index.js +3 -1
  57. package/resources/text-to-speech/index.js.map +1 -1
  58. package/resources/text-to-speech/index.mjs +1 -0
  59. package/resources/text-to-speech/index.mjs.map +1 -1
  60. package/src/resources/index.ts +11 -0
  61. package/src/resources/speech-to-text/index.ts +13 -0
  62. package/src/resources/speech-to-text/internal-base.ts +93 -0
  63. package/src/resources/speech-to-text/speech-to-text.ts +102 -0
  64. package/src/resources/speech-to-text/ws.ts +127 -0
  65. package/src/resources/speech-to-text.ts +3 -0
  66. package/src/resources/text-to-speech/index.ts +1 -0
  67. package/src/version.ts +1 -1
  68. package/version.d.mts +1 -1
  69. package/version.d.ts +1 -1
  70. package/version.js +1 -1
  71. package/version.mjs +1 -1
@@ -0,0 +1,3 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ export * from "./speech-to-text/index.mjs";
3
+ //# sourceMappingURL=speech-to-text.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speech-to-text.mjs","sourceRoot":"","sources":["../src/resources/speech-to-text.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
@@ -1,2 +1,3 @@
1
1
  export { TextToSpeech, type TextToSpeechGenerateResponse, type TextToSpeechListVoicesResponse, type StreamClientEvent, type StreamServerEvent, type TextToSpeechGenerateParams, type TextToSpeechListVoicesParams, } from "./text-to-speech.mjs";
2
+ export { TextToSpeechWS } from "./ws.mjs";
2
3
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":"OAEO,EACL,YAAY,EACZ,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,GAClC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":"OAEO,EACL,YAAY,EACZ,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,GAClC;OACM,EAAE,cAAc,EAAE"}
@@ -1,2 +1,3 @@
1
1
  export { TextToSpeech, type TextToSpeechGenerateResponse, type TextToSpeechListVoicesResponse, type StreamClientEvent, type StreamServerEvent, type TextToSpeechGenerateParams, type TextToSpeechListVoicesParams, } from "./text-to-speech.js";
2
+ export { TextToSpeechWS } from "./ws.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":"OAEO,EACL,YAAY,EACZ,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,GAClC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":"OAEO,EACL,YAAY,EACZ,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,GAClC;OACM,EAAE,cAAc,EAAE"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TextToSpeech = void 0;
4
+ exports.TextToSpeechWS = exports.TextToSpeech = void 0;
5
5
  var text_to_speech_1 = require("./text-to-speech.js");
6
6
  Object.defineProperty(exports, "TextToSpeech", { enumerable: true, get: function () { return text_to_speech_1.TextToSpeech; } });
7
+ var ws_1 = require("./ws.js");
8
+ Object.defineProperty(exports, "TextToSpeechWS", { enumerable: true, get: function () { return ws_1.TextToSpeechWS; } });
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,sDAQ0B;AAPxB,8GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,sDAQ0B;AAPxB,8GAAA,YAAY,OAAA;AAQd,8BAAsC;AAA7B,oGAAA,cAAc,OAAA"}
@@ -1,3 +1,4 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
  export { TextToSpeech, } from "./text-to-speech.mjs";
3
+ export { TextToSpeechWS } from "./ws.mjs";
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EACL,YAAY,GAOb"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/resources/text-to-speech/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EACL,YAAY,GAOb;OACM,EAAE,cAAc,EAAE"}
@@ -1064,6 +1064,16 @@ export {
1064
1064
  type ShortCodeUpdateParams,
1065
1065
  type ShortCodeListParams,
1066
1066
  } from './short-codes';
1067
+ export {
1068
+ SpeechToText,
1069
+ SpeechToTextWS,
1070
+ WebSocketError as SpeechToTextWebSocketError,
1071
+ type SpeechToTextStreamParams,
1072
+ type SttClientEvent,
1073
+ type SttServerEvent,
1074
+ type TranscriptFrame,
1075
+ type SttErrorFrame,
1076
+ } from './speech-to-text';
1067
1077
  export {
1068
1078
  SimCardDataUsageNotifications,
1069
1079
  type SimCardDataUsageNotification,
@@ -1181,6 +1191,7 @@ export {
1181
1191
  } from './texml-applications';
1182
1192
  export {
1183
1193
  TextToSpeech,
1194
+ TextToSpeechWS,
1184
1195
  type TextToSpeechGenerateResponse,
1185
1196
  type TextToSpeechListVoicesResponse,
1186
1197
  type StreamClientEvent,
@@ -0,0 +1,13 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export {
4
+ SpeechToText,
5
+ type SpeechToTextStreamParams,
6
+ type SttClientEvent,
7
+ type SttServerEvent,
8
+ type TranscriptFrame,
9
+ type SttErrorFrame,
10
+ } from './speech-to-text';
11
+
12
+ export { SpeechToTextWS } from './ws';
13
+ export { WebSocketError } from './internal-base';
@@ -0,0 +1,93 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as SpeechToTextAPI from './speech-to-text';
4
+ import { Telnyx } from '../../client';
5
+
6
+ import { EventEmitter } from '../../core/EventEmitter';
7
+ import { TelnyxError } from '../../core/error';
8
+ import { stringifyQuery } from '../../internal/utils';
9
+
10
+ export class WebSocketError extends TelnyxError {
11
+ /**
12
+ * The error data that the API sent back in an error event.
13
+ */
14
+ error?: SpeechToTextAPI.SttServerEvent.ErrorFrame | undefined;
15
+
16
+ constructor(message: string, event: SpeechToTextAPI.SttServerEvent.ErrorFrame | null) {
17
+ super(message);
18
+
19
+ this.error = event ?? undefined;
20
+ }
21
+ }
22
+
23
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
24
+
25
+ type WebsocketEvents = Simplify<
26
+ {
27
+ event: (event: SpeechToTextAPI.SttServerEvent) => void;
28
+ error: (error: WebSocketError) => void;
29
+ } & {
30
+ [EventType in Exclude<NonNullable<SpeechToTextAPI.SttServerEvent['type']>, 'error'>]: (
31
+ event: Extract<SpeechToTextAPI.SttServerEvent, { type?: EventType }>,
32
+ ) => unknown;
33
+ }
34
+ >;
35
+
36
+ export abstract class SpeechToTextEmitter extends EventEmitter<WebsocketEvents> {
37
+ /**
38
+ * Send binary audio data to the API.
39
+ */
40
+ abstract send(data: SpeechToTextAPI.SttClientEvent): void;
41
+
42
+ /**
43
+ * Close the websocket connection.
44
+ */
45
+ abstract close(props?: { code: number; reason: string }): void;
46
+
47
+ protected _onError(event: null, message: string, cause: any): void;
48
+ protected _onError(event: SpeechToTextAPI.SttServerEvent.ErrorFrame, message?: string | undefined): void;
49
+ protected _onError(
50
+ event: SpeechToTextAPI.SttServerEvent.ErrorFrame | null,
51
+ message?: string | undefined,
52
+ cause?: any,
53
+ ): void {
54
+ message = message ?? safeJSONStringify(event) ?? 'unknown error';
55
+
56
+ if (!this._hasListener('error')) {
57
+ const error = new WebSocketError(
58
+ message +
59
+ `\n\nTo resolve these unhandled rejection errors you should bind an \`error\` callback, e.g. \`ws.on('error', (error) => ...)\` `,
60
+ event,
61
+ );
62
+ // @ts-ignore
63
+ error.cause = cause;
64
+ Promise.reject(error);
65
+ return;
66
+ }
67
+
68
+ const error = new WebSocketError(message, event);
69
+ // @ts-ignore
70
+ error.cause = cause;
71
+
72
+ this._emit('error', error);
73
+ }
74
+ }
75
+
76
+ export function buildURL(client: Telnyx, query?: SpeechToTextAPI.SpeechToTextStreamParams | null): URL {
77
+ const path = '/speech-to-text/transcription';
78
+ const baseURL = client.baseURL;
79
+ const url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));
80
+ if (query) {
81
+ url.search = stringifyQuery(query);
82
+ }
83
+ url.protocol = 'wss';
84
+ return url;
85
+ }
86
+
87
+ function safeJSONStringify(value: unknown): string | null {
88
+ try {
89
+ return JSON.stringify(value);
90
+ } catch {
91
+ return null;
92
+ }
93
+ }
@@ -0,0 +1,102 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+
5
+ /**
6
+ * Speech to text streaming operations via WebSocket
7
+ */
8
+ export class SpeechToText extends APIResource {}
9
+
10
+ /**
11
+ * Parameters for establishing a speech-to-text WebSocket connection.
12
+ */
13
+ export interface SpeechToTextStreamParams {
14
+ /**
15
+ * The transcription engine to use for processing the audio stream.
16
+ */
17
+ transcription_engine: 'Azure' | 'Deepgram' | 'Google' | 'Telnyx';
18
+
19
+ /**
20
+ * The format of the input audio stream.
21
+ */
22
+ input_format?: 'mp3' | 'wav' | 'raw';
23
+
24
+ /**
25
+ * The language code for transcription (e.g., 'en-US', 'es-ES').
26
+ */
27
+ language?: string;
28
+
29
+ /**
30
+ * Whether to return interim (partial) transcription results.
31
+ */
32
+ interim_results?: boolean;
33
+
34
+ /**
35
+ * The model to use for transcription (engine-specific).
36
+ */
37
+ model?: string;
38
+ }
39
+
40
+ /**
41
+ * Binary audio data sent from client to server.
42
+ * Send raw audio bytes in mp3 or wav format.
43
+ */
44
+ export type SttClientEvent = ArrayBuffer | Buffer | Uint8Array;
45
+
46
+ /**
47
+ * Union of all server-to-client WebSocket events for STT streaming.
48
+ */
49
+ export type SttServerEvent = SttServerEvent.TranscriptFrame | SttServerEvent.ErrorFrame;
50
+
51
+ export namespace SttServerEvent {
52
+ /**
53
+ * Server-to-client frame containing a transcription result.
54
+ */
55
+ export interface TranscriptFrame {
56
+ /**
57
+ * Frame type identifier.
58
+ */
59
+ type: 'transcript';
60
+
61
+ /**
62
+ * The transcribed text from the audio.
63
+ */
64
+ transcript: string;
65
+
66
+ /**
67
+ * Whether this is a final transcription result.
68
+ * When `false`, this is an interim result that may be refined.
69
+ */
70
+ is_final?: boolean;
71
+
72
+ /**
73
+ * Confidence score of the transcription, ranging from 0 to 1.
74
+ */
75
+ confidence?: number;
76
+ }
77
+
78
+ /**
79
+ * Server-to-client frame indicating an error during transcription.
80
+ */
81
+ export interface ErrorFrame {
82
+ /**
83
+ * Frame type identifier.
84
+ */
85
+ type: 'error';
86
+
87
+ /**
88
+ * Error message describing what went wrong.
89
+ */
90
+ error: string;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Transcript frame with transcription result.
96
+ */
97
+ export type TranscriptFrame = SttServerEvent.TranscriptFrame;
98
+
99
+ /**
100
+ * Error frame indicating transcription failure.
101
+ */
102
+ export type SttErrorFrame = SttServerEvent.ErrorFrame;
@@ -0,0 +1,127 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as WS from 'ws';
4
+ import { SpeechToTextEmitter, buildURL } from './internal-base';
5
+ import * as SpeechToTextAPI from './speech-to-text';
6
+ import { Telnyx } from '../../client';
7
+
8
+ export class SpeechToTextWS extends SpeechToTextEmitter {
9
+ url: URL;
10
+ socket: WS.WebSocket;
11
+ private client: Telnyx;
12
+
13
+ constructor(
14
+ client: Telnyx,
15
+ parameters: SpeechToTextAPI.SpeechToTextStreamParams,
16
+ options?: WS.ClientOptions | null | undefined,
17
+ ) {
18
+ super();
19
+ this.client = client;
20
+ this.url = buildURL(client, parameters);
21
+ this.socket = new WS.WebSocket(this.url, {
22
+ ...options,
23
+ headers: {
24
+ ...this.authHeaders(),
25
+ ...options?.headers,
26
+ },
27
+ });
28
+
29
+ this.socket.on('open', () => {
30
+ // Connection established, ready to send audio
31
+ });
32
+
33
+ this.socket.on('message', (wsEvent) => {
34
+ const event = (() => {
35
+ try {
36
+ return JSON.parse(wsEvent.toString()) as SpeechToTextAPI.SttServerEvent;
37
+ } catch (err) {
38
+ this._onError(null, 'could not parse websocket event', err);
39
+ return null;
40
+ }
41
+ })();
42
+
43
+ if (event) {
44
+ this._emit('event', event);
45
+
46
+ if (event.type === 'error') {
47
+ this._onError(event);
48
+ } else {
49
+ // @ts-ignore TS isn't smart enough to get the relationship right here
50
+ this._emit(event.type, event);
51
+ }
52
+ }
53
+ });
54
+
55
+ this.socket.on('error', (err) => {
56
+ this._onError(null, err.message, err);
57
+ });
58
+
59
+ this.socket.on('close', (code, reason) => {
60
+ // Connection closed
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Send binary audio data to the server for transcription.
66
+ * @param data - Raw audio bytes (mp3 or wav format)
67
+ */
68
+ send(data: SpeechToTextAPI.SttClientEvent) {
69
+ try {
70
+ this.socket.send(data);
71
+ } catch (err) {
72
+ this._onError(null, 'could not send audio data', err);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Close the WebSocket connection.
78
+ */
79
+ close(props?: { code: number; reason: string }) {
80
+ try {
81
+ this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');
82
+ } catch (err) {
83
+ this._onError(null, 'could not close the connection', err);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Check if the WebSocket is open and ready to send data.
89
+ */
90
+ get isOpen(): boolean {
91
+ return this.socket.readyState === WS.WebSocket.OPEN;
92
+ }
93
+
94
+ /**
95
+ * Wait for the connection to be established.
96
+ */
97
+ waitForOpen(): Promise<void> {
98
+ return new Promise((resolve, reject) => {
99
+ if (this.socket.readyState === WS.WebSocket.OPEN) {
100
+ resolve();
101
+ return;
102
+ }
103
+
104
+ const onOpen = () => {
105
+ this.socket.off('open', onOpen);
106
+ this.socket.off('error', onError);
107
+ resolve();
108
+ };
109
+
110
+ const onError = (err: Error) => {
111
+ this.socket.off('open', onOpen);
112
+ this.socket.off('error', onError);
113
+ reject(err);
114
+ };
115
+
116
+ this.socket.on('open', onOpen);
117
+ this.socket.on('error', onError);
118
+ });
119
+ }
120
+
121
+ private authHeaders(): Record<string, string> {
122
+ if (this.client.apiKey) {
123
+ return { Authorization: `Bearer ${this.client.apiKey}` };
124
+ }
125
+ return {};
126
+ }
127
+ }
@@ -0,0 +1,3 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export * from './speech-to-text/index';
@@ -9,3 +9,4 @@ export {
9
9
  type TextToSpeechGenerateParams,
10
10
  type TextToSpeechListVoicesParams,
11
11
  } from './text-to-speech';
12
+ export { TextToSpeechWS } from './ws';
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '6.8.0'; // x-release-please-version
1
+ export const VERSION = '6.8.2'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "6.8.0";
1
+ export declare const VERSION = "6.8.2";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "6.8.0";
1
+ export declare const VERSION = "6.8.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '6.8.0'; // x-release-please-version
4
+ exports.VERSION = '6.8.2'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '6.8.0'; // x-release-please-version
1
+ export const VERSION = '6.8.2'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map