@soniox/node 1.1.2 → 2.0.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/README.md +43 -0
- package/dist/index.cjs +987 -239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +951 -176
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +951 -176
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +983 -240
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//#region src/constants.d.ts
|
|
2
2
|
declare const SONIOX_API_BASE_URL = "https://api.soniox.com";
|
|
3
3
|
declare const SONIOX_API_WS_URL = "wss://stt-rt.soniox.com/transcribe-websocket";
|
|
4
|
+
declare const SONIOX_TTS_API_BASE_URL = "https://tts-rt.soniox.com";
|
|
5
|
+
declare const SONIOX_TTS_WS_URL = "wss://tts-rt.soniox.com/tts-websocket";
|
|
4
6
|
declare const SONIOX_TMP_API_KEY_USAGE_TYPE = "transcribe_websocket";
|
|
5
7
|
declare const SONIOX_TMP_API_KEY_DURATION_MIN = 1;
|
|
6
8
|
declare const SONIOX_TMP_API_KEY_DURATION_MAX = 3600;
|
|
@@ -13,19 +15,40 @@ declare const SONIOX_API_WEBHOOK_SECRET_ENV = "SONIOX_API_WEBHOOK_SECRET";
|
|
|
13
15
|
*/
|
|
14
16
|
type RealtimeErrorCode = 'auth_error' | 'bad_request' | 'quota_exceeded' | 'connection_error' | 'network_error' | 'aborted' | 'state_error' | 'realtime_error';
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
18
|
+
* Error codes for HTTP client errors
|
|
19
|
+
*/
|
|
20
|
+
type HttpErrorCode = 'network_error' | 'timeout' | 'aborted' | 'http_error' | 'parse_error';
|
|
21
|
+
/**
|
|
22
|
+
* HTTP methods supported by the client
|
|
23
|
+
*/
|
|
24
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
25
|
+
/**
|
|
26
|
+
* Error details for SonioxHttpError
|
|
27
|
+
*/
|
|
28
|
+
interface HttpErrorDetails {
|
|
29
|
+
code: HttpErrorCode;
|
|
30
|
+
message: string;
|
|
31
|
+
url: string;
|
|
32
|
+
method: HttpMethod;
|
|
33
|
+
statusCode?: number | undefined;
|
|
34
|
+
headers?: Record<string, string> | undefined;
|
|
35
|
+
/** Response body text (capped at 4KB) */
|
|
36
|
+
bodyText?: string | undefined;
|
|
37
|
+
cause?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* All possible SDK error codes (real-time + HTTP-specific codes)
|
|
17
41
|
*/
|
|
18
|
-
type SonioxErrorCode
|
|
42
|
+
type SonioxErrorCode = RealtimeErrorCode | 'soniox_error' | HttpErrorCode;
|
|
19
43
|
//#endregion
|
|
20
44
|
//#region ../core/src/errors.d.ts
|
|
21
|
-
|
|
22
45
|
declare class SonioxError extends Error {
|
|
23
46
|
/**
|
|
24
47
|
* Error code describing the type of error.
|
|
25
48
|
* Typed as `string` at the base level to allow subclasses (e.g. HTTP errors)
|
|
26
49
|
* to use their own error code unions.
|
|
27
50
|
*/
|
|
28
|
-
readonly code: SonioxErrorCode
|
|
51
|
+
readonly code: SonioxErrorCode | (string & {});
|
|
29
52
|
/**
|
|
30
53
|
* HTTP status code when applicable (e.g., 401 for auth errors, 500 for server errors).
|
|
31
54
|
*/
|
|
@@ -34,7 +57,7 @@ declare class SonioxError extends Error {
|
|
|
34
57
|
* The underlying error that caused this error, if any.
|
|
35
58
|
*/
|
|
36
59
|
readonly cause: unknown;
|
|
37
|
-
constructor(message: string, code?: SonioxErrorCode
|
|
60
|
+
constructor(message: string, code?: SonioxErrorCode | (string & {}), statusCode?: number, cause?: unknown);
|
|
38
61
|
/**
|
|
39
62
|
* Creates a human-readable string representation
|
|
40
63
|
*/
|
|
@@ -45,6 +68,68 @@ declare class SonioxError extends Error {
|
|
|
45
68
|
toJSON(): Record<string, unknown>;
|
|
46
69
|
}
|
|
47
70
|
//#endregion
|
|
71
|
+
//#region ../core/src/http-errors.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* HTTP error class for all HTTP-related failures (REST API).
|
|
74
|
+
*
|
|
75
|
+
* Thrown when HTTP requests fail due to network issues, timeouts,
|
|
76
|
+
* server errors, or response parsing failures.
|
|
77
|
+
*/
|
|
78
|
+
declare class SonioxHttpError extends SonioxError {
|
|
79
|
+
/** Categorized HTTP error code */
|
|
80
|
+
readonly code: HttpErrorCode;
|
|
81
|
+
/** Request URL */
|
|
82
|
+
readonly url: string;
|
|
83
|
+
/** HTTP method */
|
|
84
|
+
readonly method: HttpMethod;
|
|
85
|
+
/** Response headers (only for http_error) */
|
|
86
|
+
readonly headers: Record<string, string> | undefined;
|
|
87
|
+
/** Response body text, capped at 4KB (only for http_error/parse_error) */
|
|
88
|
+
readonly bodyText: string | undefined;
|
|
89
|
+
constructor(details: HttpErrorDetails);
|
|
90
|
+
/**
|
|
91
|
+
* Creates a human-readable string representation
|
|
92
|
+
*/
|
|
93
|
+
toString(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Converts to a plain object for logging/serialization
|
|
96
|
+
*/
|
|
97
|
+
toJSON(): Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a network error
|
|
101
|
+
*/
|
|
102
|
+
declare function createNetworkError(url: string, method: HttpMethod, cause: unknown): SonioxHttpError;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a timeout error
|
|
105
|
+
*/
|
|
106
|
+
declare function createTimeoutError(url: string, method: HttpMethod, timeoutMs: number): SonioxHttpError;
|
|
107
|
+
/**
|
|
108
|
+
* Creates an abort error
|
|
109
|
+
*/
|
|
110
|
+
declare function createAbortError(url: string, method: HttpMethod, cause?: unknown): SonioxHttpError;
|
|
111
|
+
/**
|
|
112
|
+
* Creates an HTTP error (non-2xx status)
|
|
113
|
+
*/
|
|
114
|
+
declare function createHttpError(url: string, method: HttpMethod, statusCode: number, headers: Record<string, string>, bodyText: string): SonioxHttpError;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a parse error (invalid JSON, etc.)
|
|
117
|
+
*/
|
|
118
|
+
declare function createParseError(url: string, method: HttpMethod, bodyText: string, cause: unknown): SonioxHttpError;
|
|
119
|
+
/**
|
|
120
|
+
* Type guard to check if an error is an AbortError
|
|
121
|
+
*/
|
|
122
|
+
declare function isAbortError(error: unknown): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Type guard to check if an error is any SonioxError (base class).
|
|
125
|
+
* This catches all SDK errors including HTTP and real-time errors.
|
|
126
|
+
*/
|
|
127
|
+
declare function isSonioxError(error: unknown): error is SonioxError;
|
|
128
|
+
/**
|
|
129
|
+
* Type guard to check if an error is a SonioxHttpError
|
|
130
|
+
*/
|
|
131
|
+
declare function isSonioxHttpError(error: unknown): error is SonioxHttpError;
|
|
132
|
+
//#endregion
|
|
48
133
|
//#region ../core/src/types/transcriptions.d.ts
|
|
49
134
|
/**
|
|
50
135
|
* Shared transcription types used by both @soniox/node and @soniox/client.
|
|
@@ -218,6 +303,13 @@ type SttSessionOptions = {
|
|
|
218
303
|
* @default 5000
|
|
219
304
|
*/
|
|
220
305
|
keepalive_interval_ms?: number | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* Maximum time to wait for the WebSocket connection to open (milliseconds).
|
|
308
|
+
* If the connection is not established within this time, a
|
|
309
|
+
* {@link ConnectionError} with message "Connection timed out" is thrown.
|
|
310
|
+
* @default 20000
|
|
311
|
+
*/
|
|
312
|
+
connect_timeout_ms?: number | undefined;
|
|
221
313
|
};
|
|
222
314
|
/**
|
|
223
315
|
* A single token from the real-time transcription.
|
|
@@ -431,6 +523,14 @@ type RealtimeEvent = {
|
|
|
431
523
|
* Session lifecycle states.
|
|
432
524
|
*/
|
|
433
525
|
type SttSessionState = 'idle' | 'connecting' | 'connected' | 'finishing' | 'finished' | 'canceled' | 'closed' | 'error';
|
|
526
|
+
/**
|
|
527
|
+
* Reason for a state transition.
|
|
528
|
+
*
|
|
529
|
+
* Provided as an optional field on `state_change` events so consumers
|
|
530
|
+
* can distinguish user-initiated actions from automatic reconnections,
|
|
531
|
+
* connection failures, etc.
|
|
532
|
+
*/
|
|
533
|
+
type StateChangeReason = 'user_action' | 'connected' | 'connection_lost' | 'reconnecting' | 'reconnected' | 'error' | 'finished';
|
|
434
534
|
/**
|
|
435
535
|
* Event handlers for the STT session.
|
|
436
536
|
*/
|
|
@@ -473,6 +573,7 @@ type SttSessionEvents = {
|
|
|
473
573
|
state_change: (update: {
|
|
474
574
|
old_state: SttSessionState;
|
|
475
575
|
new_state: SttSessionState;
|
|
576
|
+
reason?: StateChangeReason;
|
|
476
577
|
}) => void;
|
|
477
578
|
};
|
|
478
579
|
/**
|
|
@@ -496,6 +597,368 @@ type SendStreamOptions = {
|
|
|
496
597
|
finish?: boolean | undefined;
|
|
497
598
|
};
|
|
498
599
|
//#endregion
|
|
600
|
+
//#region ../core/src/realtime/errors.d.ts
|
|
601
|
+
/**
|
|
602
|
+
* Base error class for all real-time (WebSocket) SDK errors
|
|
603
|
+
*/
|
|
604
|
+
declare class RealtimeError extends SonioxError {
|
|
605
|
+
/** Real-time error code */
|
|
606
|
+
readonly code: RealtimeErrorCode;
|
|
607
|
+
/**
|
|
608
|
+
* Original response payload for debugging.
|
|
609
|
+
* Contains the raw WebSocket message that caused the error.
|
|
610
|
+
*/
|
|
611
|
+
readonly raw: unknown;
|
|
612
|
+
constructor(message: string, code?: RealtimeErrorCode, statusCode?: number, raw?: unknown);
|
|
613
|
+
/**
|
|
614
|
+
* Creates a human-readable string representation
|
|
615
|
+
*/
|
|
616
|
+
toString(): string;
|
|
617
|
+
/**
|
|
618
|
+
* Converts to a plain object for logging/serialization
|
|
619
|
+
*/
|
|
620
|
+
toJSON(): Record<string, unknown>;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Authentication error (401).
|
|
624
|
+
* Thrown when the API key is invalid or expired.
|
|
625
|
+
*/
|
|
626
|
+
declare class AuthError extends RealtimeError {
|
|
627
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Bad request error (400).
|
|
631
|
+
* Thrown for invalid configuration or parameters.
|
|
632
|
+
*/
|
|
633
|
+
declare class BadRequestError extends RealtimeError {
|
|
634
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Quota error (402, 429).
|
|
638
|
+
* Thrown when rate limits are exceeded or quota is exhausted.
|
|
639
|
+
*/
|
|
640
|
+
declare class QuotaError extends RealtimeError {
|
|
641
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Connection error.
|
|
645
|
+
* Thrown for WebSocket connection failures and transport errors.
|
|
646
|
+
*/
|
|
647
|
+
declare class ConnectionError extends RealtimeError {
|
|
648
|
+
constructor(message: string, raw?: unknown);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Network error.
|
|
652
|
+
* Thrown for server-side network issues (408, 500, 503).
|
|
653
|
+
*/
|
|
654
|
+
declare class NetworkError extends RealtimeError {
|
|
655
|
+
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Abort error.
|
|
659
|
+
* Thrown when an operation is cancelled via AbortSignal.
|
|
660
|
+
*/
|
|
661
|
+
declare class AbortError extends RealtimeError {
|
|
662
|
+
constructor(message?: string);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* State error.
|
|
666
|
+
* Thrown when an operation is attempted in an invalid state.
|
|
667
|
+
*/
|
|
668
|
+
declare class StateError extends RealtimeError {
|
|
669
|
+
constructor(message: string);
|
|
670
|
+
}
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region ../core/src/types/tts.d.ts
|
|
673
|
+
/**
|
|
674
|
+
* Supported audio formats for Text-to-Speech output.
|
|
675
|
+
*/
|
|
676
|
+
type TtsAudioFormat = 'pcm_f32le' | 'pcm_s16le' | 'pcm_mulaw' | 'pcm_alaw' | 'wav' | 'aac' | 'mp3' | 'opus' | 'flac' | (string & {});
|
|
677
|
+
/**
|
|
678
|
+
* Input for creating a TTS stream. All fields are optional and are merged
|
|
679
|
+
* with `tts_defaults` from the resolved connection config. After merging,
|
|
680
|
+
* `model`, `language`, `voice`, and `audio_format` must be present.
|
|
681
|
+
*/
|
|
682
|
+
type TtsStreamInput = {
|
|
683
|
+
/**
|
|
684
|
+
* Text-to-Speech model to use.
|
|
685
|
+
* @example 'tts-rt-v1-preview'
|
|
686
|
+
*/
|
|
687
|
+
model?: string | undefined;
|
|
688
|
+
/**
|
|
689
|
+
* Language code for speech generation.
|
|
690
|
+
* @example 'en'
|
|
691
|
+
*/
|
|
692
|
+
language?: string | undefined;
|
|
693
|
+
/**
|
|
694
|
+
* Voice identifier.
|
|
695
|
+
* @example 'Adrian'
|
|
696
|
+
*/
|
|
697
|
+
voice?: string | undefined;
|
|
698
|
+
/**
|
|
699
|
+
* Output audio format
|
|
700
|
+
* @example 'wav'
|
|
701
|
+
*/
|
|
702
|
+
audio_format?: TtsAudioFormat | undefined;
|
|
703
|
+
/**
|
|
704
|
+
* Output sample rate in Hz. Required for raw PCM formats.
|
|
705
|
+
*/
|
|
706
|
+
sample_rate?: number | undefined;
|
|
707
|
+
/**
|
|
708
|
+
* Codec bitrate in bps (for compressed formats).
|
|
709
|
+
*/
|
|
710
|
+
bitrate?: number | undefined;
|
|
711
|
+
/**
|
|
712
|
+
* Client-generated stream identifier. Must be unique among active streams
|
|
713
|
+
* on the same connection. Auto-generated if omitted.
|
|
714
|
+
*/
|
|
715
|
+
stream_id?: string | undefined;
|
|
716
|
+
};
|
|
717
|
+
/**
|
|
718
|
+
* Fully resolved TTS stream config sent over the WebSocket.
|
|
719
|
+
* All required fields are present after merging input with defaults.
|
|
720
|
+
*/
|
|
721
|
+
type TtsStreamConfig = {
|
|
722
|
+
model: string;
|
|
723
|
+
language: string;
|
|
724
|
+
voice: string;
|
|
725
|
+
audio_format: string;
|
|
726
|
+
sample_rate?: number | undefined;
|
|
727
|
+
bitrate?: number | undefined;
|
|
728
|
+
stream_id: string;
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* Events emitted by a TTS WebSocket connection.
|
|
732
|
+
*/
|
|
733
|
+
type TtsConnectionEvents = {
|
|
734
|
+
/**
|
|
735
|
+
* A connection-level error occurred. Always a {@link RealtimeError}
|
|
736
|
+
* subclass (e.g. {@link ConnectionError}, {@link NetworkError},
|
|
737
|
+
* {@link AuthError}).
|
|
738
|
+
*/
|
|
739
|
+
error: (error: RealtimeError) => void;
|
|
740
|
+
/** The WebSocket connection was closed. */
|
|
741
|
+
close: () => void;
|
|
742
|
+
};
|
|
743
|
+
/**
|
|
744
|
+
* Options for creating a TTS connection.
|
|
745
|
+
*/
|
|
746
|
+
type TtsConnectionOptions = {
|
|
747
|
+
/**
|
|
748
|
+
* Interval for sending keepalive messages (milliseconds).
|
|
749
|
+
* @default 5000
|
|
750
|
+
* @minimum 1000
|
|
751
|
+
*/
|
|
752
|
+
keepalive_interval_ms?: number | undefined;
|
|
753
|
+
/**
|
|
754
|
+
* Maximum time to wait for the WebSocket connection to open (milliseconds).
|
|
755
|
+
* @default 20000
|
|
756
|
+
*/
|
|
757
|
+
connect_timeout_ms?: number | undefined;
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* Events emitted by a TTS stream.
|
|
761
|
+
*/
|
|
762
|
+
type TtsStreamEvents = {
|
|
763
|
+
/** Decoded audio chunk received. */
|
|
764
|
+
audio: (chunk: Uint8Array) => void;
|
|
765
|
+
/** Server marked the final audio payload for this stream. */
|
|
766
|
+
audioEnd: () => void;
|
|
767
|
+
/** Stream has been fully terminated by the server. */
|
|
768
|
+
terminated: () => void;
|
|
769
|
+
/**
|
|
770
|
+
* A stream-level error occurred. Always a {@link RealtimeError}
|
|
771
|
+
* subclass mapped from the server `error_code` / `error_message`.
|
|
772
|
+
*/
|
|
773
|
+
error: (error: RealtimeError) => void;
|
|
774
|
+
};
|
|
775
|
+
/**
|
|
776
|
+
* Lifecycle states for a TTS stream.
|
|
777
|
+
*/
|
|
778
|
+
type TtsStreamState = 'active' | 'finishing' | 'ended' | 'error';
|
|
779
|
+
/**
|
|
780
|
+
* Raw JSON event received from the TTS WebSocket server.
|
|
781
|
+
*/
|
|
782
|
+
type TtsEvent = {
|
|
783
|
+
stream_id?: string | undefined;
|
|
784
|
+
audio?: string | undefined;
|
|
785
|
+
audio_end?: boolean | undefined;
|
|
786
|
+
terminated?: boolean | undefined;
|
|
787
|
+
error_code?: number | undefined;
|
|
788
|
+
error_message?: string | undefined;
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Options for REST TTS generation (`generate` / `generateStream`).
|
|
792
|
+
*/
|
|
793
|
+
type GenerateSpeechOptions = {
|
|
794
|
+
/** Input text to generate as speech. */
|
|
795
|
+
text: string;
|
|
796
|
+
/** Text-to-Speech model to use. @default 'tts-rt-v1-preview' */
|
|
797
|
+
model?: string | undefined;
|
|
798
|
+
/** Language code. @default 'en' */
|
|
799
|
+
language?: string | undefined;
|
|
800
|
+
/** Voice identifier. */
|
|
801
|
+
voice: string;
|
|
802
|
+
/**
|
|
803
|
+
* Output audio format
|
|
804
|
+
* @default 'wav'
|
|
805
|
+
*/
|
|
806
|
+
audio_format?: string | undefined;
|
|
807
|
+
/** Output sample rate in Hz. Required for raw PCM formats. */
|
|
808
|
+
sample_rate?: number | undefined;
|
|
809
|
+
/** Codec bitrate in bps (for compressed formats). */
|
|
810
|
+
bitrate?: number | undefined;
|
|
811
|
+
/** Optional AbortSignal for cancellation. */
|
|
812
|
+
signal?: AbortSignal | undefined;
|
|
813
|
+
};
|
|
814
|
+
/**
|
|
815
|
+
* A Text-to-Speech voice.
|
|
816
|
+
*/
|
|
817
|
+
type TtsVoice = {
|
|
818
|
+
/** Unique identifier of the voice. */
|
|
819
|
+
id: string;
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* A Text-to-Speech model.
|
|
823
|
+
*/
|
|
824
|
+
type TtsModel = {
|
|
825
|
+
/** Unique identifier of the model. */
|
|
826
|
+
id: string;
|
|
827
|
+
/** If this is an alias, the id of the aliased model. */
|
|
828
|
+
aliased_model_id?: string | null;
|
|
829
|
+
/** Name of the model. */
|
|
830
|
+
name: string;
|
|
831
|
+
/** Voices supported by this model. */
|
|
832
|
+
voices: TtsVoice[];
|
|
833
|
+
};
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region ../core/src/connection.d.ts
|
|
836
|
+
/**
|
|
837
|
+
* Soniox deployment region.
|
|
838
|
+
*
|
|
839
|
+
* Defined regions:
|
|
840
|
+
* - `'eu'` — European Union (`*.eu.soniox.com`)
|
|
841
|
+
* - `'jp'` — Japan (`*.jp.soniox.com`)
|
|
842
|
+
* - `undefined` — Default (United States). The US region has no subdomain.
|
|
843
|
+
*
|
|
844
|
+
* A region name (other than `'us'`) is shorthand for setting `base_domain`
|
|
845
|
+
* to `{region}.soniox.com`. The string `'us'` is accepted and normalized to
|
|
846
|
+
* the default (United States) base domain; there is no `us.soniox.com` host.
|
|
847
|
+
*
|
|
848
|
+
* The type stays open (`string & {}`) for forward compatibility with regions
|
|
849
|
+
* added after this SDK version was published, but passing an unknown region
|
|
850
|
+
* simply prepends it as a subdomain and may not resolve.
|
|
851
|
+
*
|
|
852
|
+
* @see https://soniox.com/docs/stt/data-residency
|
|
853
|
+
*/
|
|
854
|
+
type SonioxRegion = 'eu' | 'jp' | (string & {});
|
|
855
|
+
/**
|
|
856
|
+
* Connection configuration for Soniox APIs.
|
|
857
|
+
*
|
|
858
|
+
* Can be provided as a plain object (sync) or returned from an async function
|
|
859
|
+
* to support fetching configuration from a server at runtime.
|
|
860
|
+
*/
|
|
861
|
+
type SonioxConnectionConfig = {
|
|
862
|
+
/** API key for authentication. */
|
|
863
|
+
api_key: string;
|
|
864
|
+
/**
|
|
865
|
+
* Deployment region. Determines which regional endpoints are used.
|
|
866
|
+
* Leave `undefined` for the default (US) region.
|
|
867
|
+
*
|
|
868
|
+
* Shorthand for `base_domain: '{region}.soniox.com'`.
|
|
869
|
+
* `base_domain` takes precedence when both are provided.
|
|
870
|
+
*
|
|
871
|
+
* @see https://soniox.com/docs/stt/data-residency
|
|
872
|
+
*/
|
|
873
|
+
region?: SonioxRegion | undefined;
|
|
874
|
+
/**
|
|
875
|
+
* Base domain for all Soniox service URLs.
|
|
876
|
+
*
|
|
877
|
+
* A single override that derives all four service endpoints:
|
|
878
|
+
* - `api_domain` → `https://api.{base_domain}`
|
|
879
|
+
* - `stt_ws_url` → `wss://stt-rt.{base_domain}/transcribe-websocket`
|
|
880
|
+
* - `tts_api_url` → `https://tts-rt.{base_domain}`
|
|
881
|
+
* - `tts_ws_url` → `wss://tts-rt.{base_domain}/tts-websocket`
|
|
882
|
+
*
|
|
883
|
+
* Takes precedence over `region`. Individual URL fields (`api_domain`,
|
|
884
|
+
* `stt_ws_url`, etc.) still take final precedence over this value.
|
|
885
|
+
*
|
|
886
|
+
* @example 'eu.soniox.com'
|
|
887
|
+
*/
|
|
888
|
+
base_domain?: string | undefined;
|
|
889
|
+
/**
|
|
890
|
+
* REST API domain override (e.g. `'https://api.eu.soniox.com'`).
|
|
891
|
+
* When set, takes precedence over the region-derived domain.
|
|
892
|
+
*/
|
|
893
|
+
api_domain?: string | undefined;
|
|
894
|
+
/**
|
|
895
|
+
* STT WebSocket URL override (e.g. `'wss://stt-rt.eu.soniox.com/transcribe-websocket'`).
|
|
896
|
+
* When set, takes precedence over the region-derived URL.
|
|
897
|
+
*/
|
|
898
|
+
stt_ws_url?: string | undefined;
|
|
899
|
+
/**
|
|
900
|
+
* TTS REST API URL override (e.g. `'https://tts-rt.eu.soniox.com'`).
|
|
901
|
+
* When set, takes precedence over the region-derived URL.
|
|
902
|
+
*/
|
|
903
|
+
tts_api_url?: string | undefined;
|
|
904
|
+
/**
|
|
905
|
+
* TTS WebSocket URL override (e.g. `'wss://tts-rt.eu.soniox.com/tts-websocket'`).
|
|
906
|
+
* When set, takes precedence over the region-derived URL.
|
|
907
|
+
*/
|
|
908
|
+
tts_ws_url?: string | undefined;
|
|
909
|
+
/**
|
|
910
|
+
* Server-provided STT session defaults (model, language hints, context, etc.).
|
|
911
|
+
*
|
|
912
|
+
* Available to the `session_config` function passed to `client.realtime.record()`,
|
|
913
|
+
* allowing server-driven defaults. Not applied automatically — the caller must
|
|
914
|
+
* explicitly spread them.
|
|
915
|
+
*/
|
|
916
|
+
stt_defaults?: Partial<SttSessionConfig> | undefined;
|
|
917
|
+
/**
|
|
918
|
+
* Server-provided TTS stream defaults (model, voice, language, audio_format, etc.).
|
|
919
|
+
*
|
|
920
|
+
* Automatically merged as the base layer when opening TTS streams.
|
|
921
|
+
* Caller-provided fields override these defaults.
|
|
922
|
+
*/
|
|
923
|
+
tts_defaults?: Partial<TtsStreamConfig> | undefined;
|
|
924
|
+
/**
|
|
925
|
+
* @deprecated Use `stt_defaults` instead. Kept as an alias for backward
|
|
926
|
+
* compatibility; the resolver treats it as equivalent to `stt_defaults`
|
|
927
|
+
* when that field is absent. Planned for removal in the next major version.
|
|
928
|
+
*/
|
|
929
|
+
session_defaults?: Partial<SttSessionConfig> | undefined;
|
|
930
|
+
};
|
|
931
|
+
/**
|
|
932
|
+
* Fully resolved connection configuration with all URLs determined.
|
|
933
|
+
*/
|
|
934
|
+
type ResolvedConnectionConfig = {
|
|
935
|
+
api_key: string;
|
|
936
|
+
api_domain: string;
|
|
937
|
+
stt_ws_url: string;
|
|
938
|
+
tts_api_url: string;
|
|
939
|
+
tts_ws_url: string;
|
|
940
|
+
/** Server-provided STT session defaults (empty object when not provided). */
|
|
941
|
+
stt_defaults: Partial<SttSessionConfig>;
|
|
942
|
+
/** Server-provided TTS stream defaults (empty object when not provided). */
|
|
943
|
+
tts_defaults: Partial<TtsStreamConfig>;
|
|
944
|
+
/**
|
|
945
|
+
* @deprecated Use `stt_defaults` instead. Kept in the resolver output as
|
|
946
|
+
* an alias for backward compatibility; planned for removal in the next
|
|
947
|
+
* major version.
|
|
948
|
+
*/
|
|
949
|
+
session_defaults: Partial<SttSessionConfig>;
|
|
950
|
+
};
|
|
951
|
+
/**
|
|
952
|
+
* Resolve a {@link SonioxConnectionConfig} into fully qualified URLs.
|
|
953
|
+
*
|
|
954
|
+
* Resolution priority (highest → lowest) for each URL:
|
|
955
|
+
* 1. Explicit field (`api_domain`, `stt_ws_url`, `tts_api_url`, `tts_ws_url`)
|
|
956
|
+
* 2. Derived from `base_domain`
|
|
957
|
+
* 3. Derived from `region` → `{region}.soniox.com`
|
|
958
|
+
* 4. Default US base domain (`soniox.com`)
|
|
959
|
+
*/
|
|
960
|
+
declare function resolveConnectionConfig(config: SonioxConnectionConfig): ResolvedConnectionConfig;
|
|
961
|
+
//#endregion
|
|
499
962
|
//#region ../core/src/realtime/stt.d.ts
|
|
500
963
|
/**
|
|
501
964
|
* Real-time Speech-to-Text session
|
|
@@ -525,6 +988,7 @@ declare class RealtimeSttSession implements AsyncIterable<RealtimeEvent> {
|
|
|
525
988
|
private readonly wsBaseUrl;
|
|
526
989
|
private readonly config;
|
|
527
990
|
private readonly keepaliveIntervalMs;
|
|
991
|
+
private readonly connectTimeoutMs;
|
|
528
992
|
private readonly signal;
|
|
529
993
|
private ws;
|
|
530
994
|
private _state;
|
|
@@ -610,6 +1074,11 @@ declare class RealtimeSttSession implements AsyncIterable<RealtimeEvent> {
|
|
|
610
1074
|
* Async iterator for consuming events.
|
|
611
1075
|
*/
|
|
612
1076
|
[Symbol.asyncIterator](): AsyncIterator<RealtimeEvent>;
|
|
1077
|
+
/**
|
|
1078
|
+
* @internal Debug-only: forcefully close the underlying WebSocket to
|
|
1079
|
+
* simulate an unexpected network disconnection.
|
|
1080
|
+
*/
|
|
1081
|
+
__debugForceDisconnect(): void;
|
|
613
1082
|
private createWebSocket;
|
|
614
1083
|
private handleMessage;
|
|
615
1084
|
private handleClose;
|
|
@@ -626,6 +1095,181 @@ declare class RealtimeSttSession implements AsyncIterable<RealtimeEvent> {
|
|
|
626
1095
|
private updateKeepalive;
|
|
627
1096
|
}
|
|
628
1097
|
//#endregion
|
|
1098
|
+
//#region ../core/src/realtime/emitter.d.ts
|
|
1099
|
+
/**
|
|
1100
|
+
* A minimal, runtime-agnostic typed event emitter.
|
|
1101
|
+
* Does not depend on Node.js EventEmitter.
|
|
1102
|
+
*/
|
|
1103
|
+
declare class TypedEmitter<Events extends Record<string, (...args: any[]) => void>> {
|
|
1104
|
+
private listeners;
|
|
1105
|
+
private readonly errorEvent;
|
|
1106
|
+
/**
|
|
1107
|
+
* Register an event handler.
|
|
1108
|
+
*/
|
|
1109
|
+
on<E extends keyof Events>(event: E, handler: Events[E]): this;
|
|
1110
|
+
/**
|
|
1111
|
+
* Register a one-time event handler.
|
|
1112
|
+
*/
|
|
1113
|
+
once<E extends keyof Events>(event: E, handler: Events[E]): this;
|
|
1114
|
+
/**
|
|
1115
|
+
* Remove an event handler.
|
|
1116
|
+
*/
|
|
1117
|
+
off<E extends keyof Events>(event: E, handler: Events[E]): this;
|
|
1118
|
+
/**
|
|
1119
|
+
* Emit an event to all registered handlers.
|
|
1120
|
+
* Handler errors do not prevent other handlers from running.
|
|
1121
|
+
* Errors are reported to an `error` event if present, otherwise rethrown async.
|
|
1122
|
+
*/
|
|
1123
|
+
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): void;
|
|
1124
|
+
/**
|
|
1125
|
+
* Remove all event handlers.
|
|
1126
|
+
*/
|
|
1127
|
+
removeAllListeners(event?: keyof Events): void;
|
|
1128
|
+
private reportListenerError;
|
|
1129
|
+
private normalizeError;
|
|
1130
|
+
private scheduleThrow;
|
|
1131
|
+
}
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region ../core/src/realtime/tts.d.ts
|
|
1134
|
+
/**
|
|
1135
|
+
* Handle for one TTS stream on a WebSocket connection.
|
|
1136
|
+
*
|
|
1137
|
+
* Emits typed events and supports async iteration over decoded audio chunks.
|
|
1138
|
+
*
|
|
1139
|
+
* @example Event-based
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* stream.on('audio', (chunk) => process(chunk));
|
|
1142
|
+
* stream.on('terminated', () => console.log('done'));
|
|
1143
|
+
* stream.sendText("Hello world");
|
|
1144
|
+
* stream.finish();
|
|
1145
|
+
* ```
|
|
1146
|
+
*
|
|
1147
|
+
* @example Async iteration
|
|
1148
|
+
* ```typescript
|
|
1149
|
+
* stream.sendText("Hello world");
|
|
1150
|
+
* stream.finish();
|
|
1151
|
+
* for await (const chunk of stream) {
|
|
1152
|
+
* process(chunk);
|
|
1153
|
+
* }
|
|
1154
|
+
* ```
|
|
1155
|
+
*/
|
|
1156
|
+
declare class RealtimeTtsStream extends TypedEmitter<TtsStreamEvents> implements AsyncIterable<Uint8Array> {
|
|
1157
|
+
readonly streamId: string;
|
|
1158
|
+
private _state;
|
|
1159
|
+
private readonly audioQueue;
|
|
1160
|
+
private readonly connection;
|
|
1161
|
+
private readonly ownsConnection;
|
|
1162
|
+
/** @internal */
|
|
1163
|
+
constructor(streamId: string, connection: RealtimeTtsConnection, ownsConnection: boolean);
|
|
1164
|
+
/** Current stream lifecycle state. */
|
|
1165
|
+
get state(): TtsStreamState;
|
|
1166
|
+
/**
|
|
1167
|
+
* Send one text chunk to the TTS stream.
|
|
1168
|
+
*
|
|
1169
|
+
* @param text - Text to synthesize
|
|
1170
|
+
* @param options.end - If true, signals this is the final text chunk
|
|
1171
|
+
*/
|
|
1172
|
+
sendText(text: string, options?: {
|
|
1173
|
+
end?: boolean;
|
|
1174
|
+
}): void;
|
|
1175
|
+
/**
|
|
1176
|
+
* Pipe an async iterable of text chunks into the stream.
|
|
1177
|
+
* Automatically calls {@link finish} when the iterable completes.
|
|
1178
|
+
*
|
|
1179
|
+
* Designed for concurrent use: call `sendStream()` and consume audio
|
|
1180
|
+
* via `for await` or events simultaneously.
|
|
1181
|
+
*
|
|
1182
|
+
* @example LLM token piping
|
|
1183
|
+
* ```typescript
|
|
1184
|
+
* stream.sendStream(llmTokenStream);
|
|
1185
|
+
* for await (const audio of stream) { forward(audio); }
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
sendStream(source: AsyncIterable<string>): Promise<void>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Signal that no more text will be sent for this stream.
|
|
1191
|
+
* The server will finish generating audio and send `terminated`.
|
|
1192
|
+
*/
|
|
1193
|
+
finish(): void;
|
|
1194
|
+
/**
|
|
1195
|
+
* Cancel this stream. The server will stop generating and send `terminated`.
|
|
1196
|
+
*/
|
|
1197
|
+
cancel(): void;
|
|
1198
|
+
/**
|
|
1199
|
+
* Close this stream. For single-stream usage (created via `tts(input)`),
|
|
1200
|
+
* also closes the underlying WebSocket connection.
|
|
1201
|
+
*/
|
|
1202
|
+
close(): void;
|
|
1203
|
+
/** Async iterator that yields decoded audio chunks. */
|
|
1204
|
+
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
1205
|
+
/** @internal Dispatch a server event to this stream. */
|
|
1206
|
+
_handleEvent(event: TtsEvent): void;
|
|
1207
|
+
/** @internal Force-end this stream (connection closing). */
|
|
1208
|
+
_forceEnd(): void;
|
|
1209
|
+
private _endStream;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* WebSocket connection for real-time Text-to-Speech.
|
|
1213
|
+
*
|
|
1214
|
+
* Supports up to 5 concurrent streams multiplexed by `stream_id`.
|
|
1215
|
+
* The connection automatically sends keepalive messages while open.
|
|
1216
|
+
*
|
|
1217
|
+
* @example Multi-stream
|
|
1218
|
+
* ```typescript
|
|
1219
|
+
* const conn = new RealtimeTtsConnection(apiKey, wsUrl, ttsDefaults);
|
|
1220
|
+
* await conn.connect();
|
|
1221
|
+
*
|
|
1222
|
+
* const s1 = conn.stream({ model, voice, language, audio_format });
|
|
1223
|
+
* s1.sendText("Hello");
|
|
1224
|
+
* s1.finish();
|
|
1225
|
+
* for await (const chunk of s1) { ... }
|
|
1226
|
+
*
|
|
1227
|
+
* conn.close();
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
declare class RealtimeTtsConnection extends TypedEmitter<TtsConnectionEvents> {
|
|
1231
|
+
private readonly apiKey;
|
|
1232
|
+
private readonly wsUrl;
|
|
1233
|
+
private readonly ttsDefaults;
|
|
1234
|
+
private readonly keepaliveIntervalMs;
|
|
1235
|
+
private readonly connectTimeoutMs;
|
|
1236
|
+
private ws;
|
|
1237
|
+
private connected;
|
|
1238
|
+
private connecting;
|
|
1239
|
+
private keepaliveTimer;
|
|
1240
|
+
private readonly activeStreams;
|
|
1241
|
+
constructor(apiKey: string, wsUrl: string, ttsDefaults?: Partial<TtsStreamConfig>, options?: TtsConnectionOptions);
|
|
1242
|
+
/** Whether the WebSocket is connected. */
|
|
1243
|
+
get isConnected(): boolean;
|
|
1244
|
+
/**
|
|
1245
|
+
* Open the WebSocket connection and start keepalive.
|
|
1246
|
+
* Called automatically by {@link stream} if not yet connected.
|
|
1247
|
+
*/
|
|
1248
|
+
connect(): Promise<void>;
|
|
1249
|
+
/**
|
|
1250
|
+
* Open a new TTS stream on this connection.
|
|
1251
|
+
* Auto-connects if the WebSocket is not yet open.
|
|
1252
|
+
*
|
|
1253
|
+
* @param input - Stream configuration (merged with tts_defaults)
|
|
1254
|
+
* @returns A ready-to-use stream handle
|
|
1255
|
+
*/
|
|
1256
|
+
stream(input?: TtsStreamInput): Promise<RealtimeTtsStream>;
|
|
1257
|
+
/** @internal Open a stream, optionally marking it as connection-owning. */
|
|
1258
|
+
_openStream(input: TtsStreamInput, ownsConnection: boolean): Promise<RealtimeTtsStream>;
|
|
1259
|
+
/**
|
|
1260
|
+
* Close the WebSocket connection and terminate all active streams.
|
|
1261
|
+
*/
|
|
1262
|
+
close(): void;
|
|
1263
|
+
/** @internal Send a JSON payload on the WebSocket. */
|
|
1264
|
+
_sendJson(payload: Record<string, unknown>): void;
|
|
1265
|
+
/** @internal Remove a stream from the active set. */
|
|
1266
|
+
_deactivateStream(streamId: string): void;
|
|
1267
|
+
private createWebSocket;
|
|
1268
|
+
private handleMessage;
|
|
1269
|
+
private startKeepalive;
|
|
1270
|
+
private stopKeepalive;
|
|
1271
|
+
}
|
|
1272
|
+
//#endregion
|
|
629
1273
|
//#region ../core/src/realtime/segments.d.ts
|
|
630
1274
|
/**
|
|
631
1275
|
* Groups real-time tokens into segments based on specified grouping keys.
|
|
@@ -698,104 +1342,52 @@ declare class RealtimeUtteranceBuffer {
|
|
|
698
1342
|
reset(): void;
|
|
699
1343
|
}
|
|
700
1344
|
//#endregion
|
|
701
|
-
//#region ../core/src/
|
|
1345
|
+
//#region ../core/src/tts-rest.d.ts
|
|
702
1346
|
/**
|
|
703
|
-
*
|
|
1347
|
+
* Browser-safe REST client for TTS generation.
|
|
1348
|
+
*
|
|
1349
|
+
* Provides `generate()` (buffered) and `generateStream()` (streaming)
|
|
1350
|
+
* using only `globalThis.fetch`. HTTP failures are surfaced as
|
|
1351
|
+
* {@link SonioxHttpError}, matching the rest of the Soniox SDK.
|
|
1352
|
+
*
|
|
1353
|
+
* Authentication uses the `Authorization: Bearer <api_key>` header.
|
|
1354
|
+
*
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```typescript
|
|
1357
|
+
* const client = new TtsRestClient(apiKey, 'https://tts-rt.soniox.com');
|
|
1358
|
+
* const audio = await client.generate({ text: 'Hello', voice: 'Adrian' });
|
|
1359
|
+
* ```
|
|
704
1360
|
*/
|
|
705
|
-
declare class
|
|
706
|
-
|
|
707
|
-
readonly
|
|
1361
|
+
declare class TtsRestClient {
|
|
1362
|
+
private readonly apiKey;
|
|
1363
|
+
private readonly ttsApiUrl;
|
|
1364
|
+
constructor(apiKey: string, ttsApiUrl: string);
|
|
708
1365
|
/**
|
|
709
|
-
*
|
|
710
|
-
*
|
|
1366
|
+
* Generate speech audio from text. Returns the full audio as a `Uint8Array`.
|
|
1367
|
+
*
|
|
1368
|
+
* @throws {@link SonioxHttpError} on non-2xx responses, network failures,
|
|
1369
|
+
* or aborted requests.
|
|
711
1370
|
*/
|
|
712
|
-
|
|
713
|
-
constructor(message: string, code?: RealtimeErrorCode, statusCode?: number, raw?: unknown);
|
|
1371
|
+
generate(options: GenerateSpeechOptions): Promise<Uint8Array>;
|
|
714
1372
|
/**
|
|
715
|
-
*
|
|
1373
|
+
* Generate speech audio from text as a streaming async iterable.
|
|
1374
|
+
*
|
|
1375
|
+
* Yields `Uint8Array` chunks as they arrive from the server response body.
|
|
1376
|
+
* Lower time-to-first-audio than {@link generate}.
|
|
1377
|
+
*
|
|
1378
|
+
* **Known limitation:** Mid-stream server errors (reported via HTTP trailers)
|
|
1379
|
+
* cannot be detected through the `fetch` API. The iterator may end early
|
|
1380
|
+
* without an explicit error. Use WebSocket TTS for reliable error detection.
|
|
1381
|
+
*
|
|
1382
|
+
* @throws {@link SonioxHttpError} on non-2xx responses, network failures,
|
|
1383
|
+
* or aborted requests (before the stream starts).
|
|
716
1384
|
*/
|
|
717
|
-
|
|
1385
|
+
generateStream(options: GenerateSpeechOptions): AsyncIterable<Uint8Array>;
|
|
718
1386
|
/**
|
|
719
|
-
*
|
|
1387
|
+
* Internal request helper. Performs the fetch, maps network/abort failures
|
|
1388
|
+
* to {@link SonioxHttpError}, and throws on non-2xx responses.
|
|
720
1389
|
*/
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Authentication error (401).
|
|
725
|
-
* Thrown when the API key is invalid or expired.
|
|
726
|
-
*/
|
|
727
|
-
declare class AuthError extends RealtimeError {
|
|
728
|
-
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Bad request error (400).
|
|
732
|
-
* Thrown for invalid configuration or parameters.
|
|
733
|
-
*/
|
|
734
|
-
declare class BadRequestError extends RealtimeError {
|
|
735
|
-
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Quota error (402, 429).
|
|
739
|
-
* Thrown when rate limits are exceeded or quota is exhausted.
|
|
740
|
-
*/
|
|
741
|
-
declare class QuotaError extends RealtimeError {
|
|
742
|
-
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Connection error.
|
|
746
|
-
* Thrown for WebSocket connection failures and transport errors.
|
|
747
|
-
*/
|
|
748
|
-
declare class ConnectionError extends RealtimeError {
|
|
749
|
-
constructor(message: string, raw?: unknown);
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Network error.
|
|
753
|
-
* Thrown for server-side network issues (408, 500, 503).
|
|
754
|
-
*/
|
|
755
|
-
declare class NetworkError extends RealtimeError {
|
|
756
|
-
constructor(message: string, statusCode?: number, raw?: unknown);
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Abort error.
|
|
760
|
-
* Thrown when an operation is cancelled via AbortSignal.
|
|
761
|
-
*/
|
|
762
|
-
declare class AbortError extends RealtimeError {
|
|
763
|
-
constructor(message?: string);
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* State error.
|
|
767
|
-
* Thrown when an operation is attempted in an invalid state.
|
|
768
|
-
*/
|
|
769
|
-
declare class StateError extends RealtimeError {
|
|
770
|
-
constructor(message: string);
|
|
771
|
-
}
|
|
772
|
-
//#endregion
|
|
773
|
-
//#region src/types/public/errors.d.ts
|
|
774
|
-
/**
|
|
775
|
-
* Error codes for HTTP client errors
|
|
776
|
-
*/
|
|
777
|
-
type HttpErrorCode = 'network_error' | 'timeout' | 'aborted' | 'http_error' | 'parse_error';
|
|
778
|
-
/**
|
|
779
|
-
* All possible SDK error codes (core real-time + HTTP-specific codes)
|
|
780
|
-
*/
|
|
781
|
-
type SonioxErrorCode = RealtimeErrorCode | 'soniox_error' | HttpErrorCode;
|
|
782
|
-
/**
|
|
783
|
-
* HTTP methods supported by the client
|
|
784
|
-
*/
|
|
785
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
786
|
-
/**
|
|
787
|
-
* Error details for SonioxHttpError
|
|
788
|
-
*/
|
|
789
|
-
interface HttpErrorDetails {
|
|
790
|
-
code: HttpErrorCode;
|
|
791
|
-
message: string;
|
|
792
|
-
url: string;
|
|
793
|
-
method: HttpMethod;
|
|
794
|
-
statusCode?: number | undefined;
|
|
795
|
-
headers?: Record<string, string> | undefined;
|
|
796
|
-
/** Response body text (capped at 4KB) */
|
|
797
|
-
bodyText?: string | undefined;
|
|
798
|
-
cause?: unknown;
|
|
1390
|
+
private sendRequest;
|
|
799
1391
|
}
|
|
800
1392
|
//#endregion
|
|
801
1393
|
//#region src/types/public/http.d.ts
|
|
@@ -947,12 +1539,31 @@ type RealtimeClientOptions = {
|
|
|
947
1539
|
*/
|
|
948
1540
|
api_key: string;
|
|
949
1541
|
/**
|
|
950
|
-
* WebSocket base URL for real-time connections.
|
|
1542
|
+
* STT WebSocket base URL for real-time connections.
|
|
951
1543
|
* @default 'wss://stt-rt.soniox.com/transcribe-websocket'
|
|
952
1544
|
*/
|
|
953
1545
|
ws_base_url: string;
|
|
954
1546
|
/**
|
|
955
|
-
*
|
|
1547
|
+
* TTS WebSocket URL for real-time connections.
|
|
1548
|
+
* @default 'wss://tts-rt.soniox.com/tts-websocket'
|
|
1549
|
+
*/
|
|
1550
|
+
tts_ws_url: string;
|
|
1551
|
+
/**
|
|
1552
|
+
* STT session config defaults. Merged as the base layer when opening
|
|
1553
|
+
* STT sessions via `realtime.stt(config)`; caller fields override.
|
|
1554
|
+
*/
|
|
1555
|
+
stt_defaults?: Partial<SttSessionConfig> | undefined;
|
|
1556
|
+
/**
|
|
1557
|
+
* TTS stream config defaults. Merged as the base layer when opening
|
|
1558
|
+
* TTS streams via `realtime.tts(...)`; caller fields override.
|
|
1559
|
+
*/
|
|
1560
|
+
tts_defaults?: Partial<TtsStreamConfig> | undefined;
|
|
1561
|
+
/**
|
|
1562
|
+
* Default TTS connection options.
|
|
1563
|
+
*/
|
|
1564
|
+
tts_connection_options?: TtsConnectionOptions | undefined;
|
|
1565
|
+
/**
|
|
1566
|
+
* Default session options applied to all real-time STT sessions.
|
|
956
1567
|
* Can be overridden per-session.
|
|
957
1568
|
*/
|
|
958
1569
|
default_session_options?: SttSessionOptions | undefined;
|
|
@@ -1825,7 +2436,7 @@ type HonoLikeContext = {
|
|
|
1825
2436
|
};
|
|
1826
2437
|
//#endregion
|
|
1827
2438
|
//#region src/types/public/index.d.ts
|
|
1828
|
-
type TemporaryApiKeyUsageType = 'transcribe_websocket';
|
|
2439
|
+
type TemporaryApiKeyUsageType = 'transcribe_websocket' | 'tts_rt';
|
|
1829
2440
|
type TemporaryApiKeyRequest = {
|
|
1830
2441
|
/**
|
|
1831
2442
|
* Intended usage of the temporary API key.
|
|
@@ -1859,16 +2470,44 @@ type TemporaryApiKeyResponse = {
|
|
|
1859
2470
|
*/
|
|
1860
2471
|
type RealtimeOptions = {
|
|
1861
2472
|
/**
|
|
1862
|
-
* WebSocket base URL for real-time connections.
|
|
2473
|
+
* STT WebSocket base URL for real-time connections.
|
|
1863
2474
|
* Falls back to SONIOX_WS_URL environment variable,
|
|
1864
2475
|
* then to 'wss://stt-rt.soniox.com/transcribe-websocket'.
|
|
1865
2476
|
*/
|
|
1866
2477
|
ws_base_url?: string | undefined;
|
|
1867
2478
|
/**
|
|
1868
|
-
*
|
|
2479
|
+
* TTS WebSocket URL for real-time connections.
|
|
2480
|
+
* Falls back to SONIOX_TTS_WS_URL environment variable,
|
|
2481
|
+
* then to 'wss://tts-rt.soniox.com/tts-websocket'.
|
|
2482
|
+
*/
|
|
2483
|
+
tts_ws_url?: string | undefined;
|
|
2484
|
+
/**
|
|
2485
|
+
* Default TTS connection options (keepalive interval, connect timeout).
|
|
2486
|
+
*/
|
|
2487
|
+
tts_connection_options?: TtsConnectionOptions | undefined;
|
|
2488
|
+
/**
|
|
2489
|
+
* Default session options applied to all real-time STT sessions.
|
|
1869
2490
|
* Can be overridden per-session.
|
|
1870
2491
|
*/
|
|
1871
2492
|
default_session_options?: SttSessionOptions | undefined;
|
|
2493
|
+
/**
|
|
2494
|
+
* Default STT session config fields (model, language hints, context, etc.).
|
|
2495
|
+
*
|
|
2496
|
+
* Merged as the base layer when opening STT sessions via
|
|
2497
|
+
* `client.realtime.stt(config)`. Fields on the caller-provided `config`
|
|
2498
|
+
* override these defaults. Equivalent to
|
|
2499
|
+
* {@link SonioxConnectionConfig.stt_defaults} on the web/react clients.
|
|
2500
|
+
*/
|
|
2501
|
+
stt_defaults?: Partial<SttSessionConfig> | undefined;
|
|
2502
|
+
/**
|
|
2503
|
+
* Default TTS stream config fields (model, voice, language, audio_format, etc.).
|
|
2504
|
+
*
|
|
2505
|
+
* Merged as the base layer when opening TTS streams via
|
|
2506
|
+
* `client.realtime.tts(...)`. Fields on the caller-provided
|
|
2507
|
+
* {@link TtsStreamInput} override these defaults. Equivalent to
|
|
2508
|
+
* {@link SonioxConnectionConfig.tts_defaults} on the web/react clients.
|
|
2509
|
+
*/
|
|
2510
|
+
tts_defaults?: Partial<TtsStreamConfig> | undefined;
|
|
1872
2511
|
};
|
|
1873
2512
|
type SonioxNodeClientOptions = {
|
|
1874
2513
|
/**
|
|
@@ -1876,16 +2515,62 @@ type SonioxNodeClientOptions = {
|
|
|
1876
2515
|
* Falls back to SONIOX_API_KEY environment variable if not provided.
|
|
1877
2516
|
*/
|
|
1878
2517
|
api_key?: string;
|
|
2518
|
+
/**
|
|
2519
|
+
* Deployment region. Determines which regional endpoints are used
|
|
2520
|
+
* for both the REST API and real-time WebSocket connections.
|
|
2521
|
+
*
|
|
2522
|
+
* Leave `undefined` for the default (US) region.
|
|
2523
|
+
* Shorthand for `base_domain: '{region}.soniox.com'`.
|
|
2524
|
+
* `base_domain` takes precedence when both are provided.
|
|
2525
|
+
*
|
|
2526
|
+
* @see https://soniox.com/docs/stt/data-residency
|
|
2527
|
+
*/
|
|
2528
|
+
region?: SonioxRegion | undefined;
|
|
2529
|
+
/**
|
|
2530
|
+
* Base domain for all Soniox service URLs.
|
|
2531
|
+
*
|
|
2532
|
+
* A single override that derives all service endpoints from the pattern
|
|
2533
|
+
* `{service}.{base_domain}`. Takes precedence over `region`.
|
|
2534
|
+
* Falls back to SONIOX_BASE_DOMAIN environment variable.
|
|
2535
|
+
* Individual URL fields (`base_url`, `tts_api_url`, `realtime.ws_base_url`,
|
|
2536
|
+
* `realtime.tts_ws_url`) still take final precedence.
|
|
2537
|
+
*
|
|
2538
|
+
* @example 'eu.soniox.com'
|
|
2539
|
+
*/
|
|
2540
|
+
base_domain?: string | undefined;
|
|
1879
2541
|
/**
|
|
1880
2542
|
* Base URL for the REST API.
|
|
1881
2543
|
* Falls back to SONIOX_API_BASE_URL environment variable,
|
|
1882
|
-
* then to 'https://api.soniox.com'.
|
|
2544
|
+
* then to the region-derived URL, then to 'https://api.soniox.com'.
|
|
1883
2545
|
*/
|
|
1884
2546
|
base_url?: string;
|
|
2547
|
+
/**
|
|
2548
|
+
* TTS REST API URL.
|
|
2549
|
+
* Falls back to SONIOX_TTS_API_URL environment variable,
|
|
2550
|
+
* then to the region-derived URL, then to 'https://tts-rt.soniox.com'.
|
|
2551
|
+
*/
|
|
2552
|
+
tts_api_url?: string;
|
|
1885
2553
|
/**
|
|
1886
2554
|
* Custom HTTP client implementation.
|
|
1887
2555
|
*/
|
|
1888
2556
|
http_client?: HttpClient;
|
|
2557
|
+
/**
|
|
2558
|
+
* Default STT session config fields applied to every real-time STT session
|
|
2559
|
+
* opened via `client.realtime.stt(config)`. Caller-provided fields override.
|
|
2560
|
+
*
|
|
2561
|
+
* Equivalent to {@link SonioxConnectionConfig.stt_defaults} on the
|
|
2562
|
+
* web/react clients. Prefer this when you want the same defaults
|
|
2563
|
+
* across your whole Node process.
|
|
2564
|
+
*/
|
|
2565
|
+
stt_defaults?: Partial<SttSessionConfig> | undefined;
|
|
2566
|
+
/**
|
|
2567
|
+
* Default TTS stream config fields applied to every real-time TTS stream
|
|
2568
|
+
* opened via `client.realtime.tts(...)`. Caller-provided fields override.
|
|
2569
|
+
*
|
|
2570
|
+
* Equivalent to {@link SonioxConnectionConfig.tts_defaults} on the
|
|
2571
|
+
* web/react clients.
|
|
2572
|
+
*/
|
|
2573
|
+
tts_defaults?: Partial<TtsStreamConfig> | undefined;
|
|
1889
2574
|
/**
|
|
1890
2575
|
* Real-time API configuration options.
|
|
1891
2576
|
*/
|
|
@@ -1902,6 +2587,19 @@ declare class SonioxAuthAPI {
|
|
|
1902
2587
|
* @param request - Request parameters for the temporary key
|
|
1903
2588
|
* @param signal - Optional AbortSignal for cancellation
|
|
1904
2589
|
* @returns The temporary API key response
|
|
2590
|
+
*
|
|
2591
|
+
* @example
|
|
2592
|
+
* ```typescript
|
|
2593
|
+
* const sttKey = await client.auth.createTemporaryKey({
|
|
2594
|
+
* usage_type: 'transcribe_websocket',
|
|
2595
|
+
* expires_in_seconds: 300,
|
|
2596
|
+
* });
|
|
2597
|
+
*
|
|
2598
|
+
* const ttsKey = await client.auth.createTemporaryKey({
|
|
2599
|
+
* usage_type: 'tts_rt',
|
|
2600
|
+
* expires_in_seconds: 300,
|
|
2601
|
+
* });
|
|
2602
|
+
* ```
|
|
1905
2603
|
*/
|
|
1906
2604
|
createTemporaryKey(request: TemporaryApiKeyRequest, signal?: AbortSignal): Promise<TemporaryApiKeyResponse>;
|
|
1907
2605
|
}
|
|
@@ -2721,6 +3419,59 @@ declare class SonioxSttApi {
|
|
|
2721
3419
|
destroy_all(options?: DeleteAllTranscriptionsOptions): Promise<void>;
|
|
2722
3420
|
}
|
|
2723
3421
|
//#endregion
|
|
3422
|
+
//#region src/async/tts.d.ts
|
|
3423
|
+
/**
|
|
3424
|
+
* REST API for Text-to-Speech generation and TTS model listing.
|
|
3425
|
+
*
|
|
3426
|
+
* Accessed via `client.tts` on {@link SonioxNodeClient}.
|
|
3427
|
+
*
|
|
3428
|
+
* Inherits browser-safe `generate()` and `generateStream()` from
|
|
3429
|
+
* `TtsRestClient` in `@soniox/core`, and adds Node-specific methods
|
|
3430
|
+
* `generateToFile()` and `listModels()`.
|
|
3431
|
+
*/
|
|
3432
|
+
declare class SonioxTtsApi extends TtsRestClient {
|
|
3433
|
+
private readonly http;
|
|
3434
|
+
constructor(apiKey: string, ttsApiUrl: string, http: HttpClient);
|
|
3435
|
+
/**
|
|
3436
|
+
* Generate speech audio and write to a file or writable stream.
|
|
3437
|
+
*
|
|
3438
|
+
* @param output - File path (string) or a `WritableStream<Uint8Array>`
|
|
3439
|
+
* @param options - Generation options
|
|
3440
|
+
* @returns Number of bytes written
|
|
3441
|
+
*
|
|
3442
|
+
* @example Write to file
|
|
3443
|
+
* ```typescript
|
|
3444
|
+
* const bytes = await client.tts.generateToFile('output.wav', {
|
|
3445
|
+
* text: 'Hello world',
|
|
3446
|
+
* voice: 'Adrian',
|
|
3447
|
+
* language: 'en',
|
|
3448
|
+
* });
|
|
3449
|
+
* ```
|
|
3450
|
+
*
|
|
3451
|
+
* @example Write to a writable stream
|
|
3452
|
+
* ```typescript
|
|
3453
|
+
* const bytes = await client.tts.generateToFile(writableStream, {
|
|
3454
|
+
* text: 'Hello world',
|
|
3455
|
+
* voice: 'Adrian',
|
|
3456
|
+
* language: 'en',
|
|
3457
|
+
* });
|
|
3458
|
+
* ```
|
|
3459
|
+
*/
|
|
3460
|
+
generateToFile(output: string | WritableStream<Uint8Array>, options: GenerateSpeechOptions): Promise<number>;
|
|
3461
|
+
/**
|
|
3462
|
+
* List available TTS models and their voices.
|
|
3463
|
+
*
|
|
3464
|
+
* @example
|
|
3465
|
+
* ```typescript
|
|
3466
|
+
* const models = await client.tts.listModels();
|
|
3467
|
+
* for (const model of models) {
|
|
3468
|
+
* console.log(model.id, model.voices.map(v => v.id));
|
|
3469
|
+
* }
|
|
3470
|
+
* ```
|
|
3471
|
+
*/
|
|
3472
|
+
listModels(signal?: AbortSignal): Promise<TtsModel[]>;
|
|
3473
|
+
}
|
|
3474
|
+
//#endregion
|
|
2724
3475
|
//#region src/async/webhooks.d.ts
|
|
2725
3476
|
/**
|
|
2726
3477
|
* Webhook utilities API accessible via client.webhooks
|
|
@@ -2799,48 +3550,134 @@ declare class SonioxWebhooksAPI {
|
|
|
2799
3550
|
//#endregion
|
|
2800
3551
|
//#region src/realtime/index.d.ts
|
|
2801
3552
|
/**
|
|
2802
|
-
*
|
|
3553
|
+
* Callable TTS factory with `.multiStream()` for multi-stream connections.
|
|
3554
|
+
*/
|
|
3555
|
+
interface TtsFactory {
|
|
3556
|
+
/**
|
|
3557
|
+
* Create a single-stream TTS connection.
|
|
3558
|
+
* Opens a WebSocket, starts one stream, and returns a ready-to-use stream
|
|
3559
|
+
* that owns its connection (closing the stream closes the connection).
|
|
3560
|
+
*
|
|
3561
|
+
* @example
|
|
3562
|
+
* ```typescript
|
|
3563
|
+
* const stream = await client.realtime.tts({
|
|
3564
|
+
* model: 'tts-rt-v1-preview',
|
|
3565
|
+
* voice: 'Adrian',
|
|
3566
|
+
* language: 'en',
|
|
3567
|
+
* audio_format: 'wav',
|
|
3568
|
+
* });
|
|
3569
|
+
* stream.sendText("Hello world");
|
|
3570
|
+
* stream.finish();
|
|
3571
|
+
* for await (const chunk of stream) { process(chunk); }
|
|
3572
|
+
* ```
|
|
3573
|
+
*/
|
|
3574
|
+
(input?: TtsStreamInput): Promise<RealtimeTtsStream>;
|
|
3575
|
+
/**
|
|
3576
|
+
* Create a multi-stream TTS connection.
|
|
3577
|
+
* Opens a single WebSocket that can host up to 5 concurrent streams.
|
|
3578
|
+
*
|
|
3579
|
+
* @example
|
|
3580
|
+
* ```typescript
|
|
3581
|
+
* const conn = await client.realtime.tts.multiStream();
|
|
3582
|
+
* const s1 = await conn.stream({
|
|
3583
|
+
* model: 'tts-rt-v1-preview',
|
|
3584
|
+
* voice: 'Adrian',
|
|
3585
|
+
* language: 'en',
|
|
3586
|
+
* audio_format: 'wav',
|
|
3587
|
+
* });
|
|
3588
|
+
* // Use any voice returned by client.tts.listModels()
|
|
3589
|
+
* const s2 = await conn.stream({
|
|
3590
|
+
* model: 'tts-rt-v1-preview',
|
|
3591
|
+
* voice: someOtherVoice,
|
|
3592
|
+
* language: 'en',
|
|
3593
|
+
* audio_format: 'wav',
|
|
3594
|
+
* });
|
|
3595
|
+
* ```
|
|
3596
|
+
*/
|
|
3597
|
+
multiStream(): Promise<RealtimeTtsConnection>;
|
|
3598
|
+
}
|
|
3599
|
+
/**
|
|
3600
|
+
* Real-time API factory for creating STT sessions and TTS connections.
|
|
2803
3601
|
*
|
|
2804
|
-
* @example
|
|
3602
|
+
* @example STT
|
|
3603
|
+
* ```typescript
|
|
3604
|
+
* const session = client.realtime.stt({ model: 'stt-rt-v4' });
|
|
3605
|
+
* await session.connect();
|
|
3606
|
+
* ```
|
|
3607
|
+
*
|
|
3608
|
+
* @example TTS (single stream)
|
|
2805
3609
|
* ```typescript
|
|
2806
|
-
* const
|
|
2807
|
-
* model: '
|
|
2808
|
-
*
|
|
3610
|
+
* const stream = await client.realtime.tts({
|
|
3611
|
+
* model: 'tts-rt-v1-preview',
|
|
3612
|
+
* voice: 'Adrian',
|
|
3613
|
+
* language: 'en',
|
|
3614
|
+
* audio_format: 'wav',
|
|
2809
3615
|
* });
|
|
3616
|
+
* stream.sendText("Hello");
|
|
3617
|
+
* stream.finish();
|
|
3618
|
+
* for await (const chunk of stream) { ... }
|
|
3619
|
+
* ```
|
|
2810
3620
|
*
|
|
2811
|
-
*
|
|
3621
|
+
* @example TTS (multi-stream)
|
|
3622
|
+
* ```typescript
|
|
3623
|
+
* const conn = await client.realtime.tts.multiStream();
|
|
3624
|
+
* const stream = await conn.stream({
|
|
3625
|
+
* model: 'tts-rt-v1-preview',
|
|
3626
|
+
* voice: 'Adrian',
|
|
3627
|
+
* language: 'en',
|
|
3628
|
+
* audio_format: 'wav',
|
|
3629
|
+
* });
|
|
2812
3630
|
* ```
|
|
2813
3631
|
*/
|
|
2814
3632
|
declare class SonioxRealtimeApi {
|
|
2815
3633
|
private readonly options;
|
|
3634
|
+
readonly tts: TtsFactory;
|
|
2816
3635
|
constructor(options: RealtimeClientOptions);
|
|
2817
3636
|
/**
|
|
2818
3637
|
* Create a new Speech-to-Text session.
|
|
2819
3638
|
*
|
|
2820
|
-
*
|
|
2821
|
-
*
|
|
2822
|
-
* @returns New STT session instance
|
|
3639
|
+
* `config` is shallow-merged on top of `stt_defaults` from the client
|
|
3640
|
+
* options; caller-provided fields override the defaults.
|
|
2823
3641
|
*/
|
|
2824
3642
|
stt(config: SttSessionConfig, options?: SttSessionOptions): RealtimeSttSession;
|
|
3643
|
+
private createSingleTtsStream;
|
|
3644
|
+
private createTtsConnection;
|
|
2825
3645
|
}
|
|
2826
3646
|
//#endregion
|
|
2827
3647
|
//#region src/client.d.ts
|
|
2828
3648
|
/**
|
|
2829
3649
|
* Soniox Node Client
|
|
2830
|
-
* @returns {SonioxNodeClient}
|
|
2831
3650
|
*
|
|
2832
3651
|
* @example
|
|
2833
3652
|
* ```typescript
|
|
2834
3653
|
* import { SonioxNodeClient } from '@soniox/node';
|
|
2835
3654
|
*
|
|
2836
|
-
*
|
|
2837
|
-
*
|
|
3655
|
+
* // Default (US) region
|
|
3656
|
+
* const client = new SonioxNodeClient({ api_key: 'your-api-key' });
|
|
3657
|
+
*
|
|
3658
|
+
* // EU region
|
|
3659
|
+
* const client = new SonioxNodeClient({ api_key: 'your-api-key', region: 'eu' });
|
|
3660
|
+
*
|
|
3661
|
+
* // REST TTS
|
|
3662
|
+
* const audio = await client.tts.generate({
|
|
3663
|
+
* text: 'Hello',
|
|
3664
|
+
* voice: 'Adrian',
|
|
3665
|
+
* language: 'en',
|
|
3666
|
+
* });
|
|
3667
|
+
*
|
|
3668
|
+
* // WebSocket TTS
|
|
3669
|
+
* const stream = await client.realtime.tts({
|
|
3670
|
+
* model: 'tts-rt-v1-preview',
|
|
3671
|
+
* voice: 'Adrian',
|
|
3672
|
+
* language: 'en',
|
|
3673
|
+
* audio_format: 'wav',
|
|
2838
3674
|
* });
|
|
2839
3675
|
* ```
|
|
2840
3676
|
*/
|
|
2841
3677
|
declare class SonioxNodeClient {
|
|
2842
3678
|
readonly files: SonioxFilesAPI;
|
|
2843
3679
|
readonly stt: SonioxSttApi;
|
|
3680
|
+
readonly tts: SonioxTtsApi;
|
|
2844
3681
|
readonly models: SonioxModelsAPI;
|
|
2845
3682
|
readonly webhooks: SonioxWebhooksAPI;
|
|
2846
3683
|
readonly auth: SonioxAuthAPI;
|
|
@@ -2932,68 +3769,6 @@ declare class FetchHttpClient implements HttpClient {
|
|
|
2932
3769
|
private normalizeError;
|
|
2933
3770
|
}
|
|
2934
3771
|
//#endregion
|
|
2935
|
-
//#region src/http/errors.d.ts
|
|
2936
|
-
/**
|
|
2937
|
-
* HTTP error class for all HTTP-related failures (REST API).
|
|
2938
|
-
*
|
|
2939
|
-
* Thrown when HTTP requests fail due to network issues, timeouts,
|
|
2940
|
-
* server errors, or response parsing failures.
|
|
2941
|
-
*/
|
|
2942
|
-
declare class SonioxHttpError extends SonioxError {
|
|
2943
|
-
/** Categorized HTTP error code */
|
|
2944
|
-
readonly code: HttpErrorCode;
|
|
2945
|
-
/** Request URL */
|
|
2946
|
-
readonly url: string;
|
|
2947
|
-
/** HTTP method */
|
|
2948
|
-
readonly method: HttpMethod;
|
|
2949
|
-
/** Response headers (only for http_error) */
|
|
2950
|
-
readonly headers: Record<string, string> | undefined;
|
|
2951
|
-
/** Response body text, capped at 4KB (only for http_error/parse_error) */
|
|
2952
|
-
readonly bodyText: string | undefined;
|
|
2953
|
-
constructor(details: HttpErrorDetails);
|
|
2954
|
-
/**
|
|
2955
|
-
* Creates a human-readable string representation
|
|
2956
|
-
*/
|
|
2957
|
-
toString(): string;
|
|
2958
|
-
/**
|
|
2959
|
-
* Converts to a plain object for logging/serialization
|
|
2960
|
-
*/
|
|
2961
|
-
toJSON(): Record<string, unknown>;
|
|
2962
|
-
}
|
|
2963
|
-
/**
|
|
2964
|
-
* Creates a network error
|
|
2965
|
-
*/
|
|
2966
|
-
declare function createNetworkError(url: string, method: HttpMethod, cause: unknown): SonioxHttpError;
|
|
2967
|
-
/**
|
|
2968
|
-
* Creates a timeout error
|
|
2969
|
-
*/
|
|
2970
|
-
declare function createTimeoutError(url: string, method: HttpMethod, timeoutMs: number): SonioxHttpError;
|
|
2971
|
-
/**
|
|
2972
|
-
* Creates an abort error
|
|
2973
|
-
*/
|
|
2974
|
-
declare function createAbortError(url: string, method: HttpMethod, cause?: unknown): SonioxHttpError;
|
|
2975
|
-
/**
|
|
2976
|
-
* Creates an HTTP error (non-2xx status)
|
|
2977
|
-
*/
|
|
2978
|
-
declare function createHttpError(url: string, method: HttpMethod, statusCode: number, headers: Record<string, string>, bodyText: string): SonioxHttpError;
|
|
2979
|
-
/**
|
|
2980
|
-
* Creates a parse error (invalid JSON, etc.)
|
|
2981
|
-
*/
|
|
2982
|
-
declare function createParseError(url: string, method: HttpMethod, bodyText: string, cause: unknown): SonioxHttpError;
|
|
2983
|
-
/**
|
|
2984
|
-
* Type guard to check if an error is an AbortError
|
|
2985
|
-
*/
|
|
2986
|
-
declare function isAbortError(error: unknown): boolean;
|
|
2987
|
-
/**
|
|
2988
|
-
* Type guard to check if an error is any SonioxError (base class).
|
|
2989
|
-
* This catches all SDK errors including HTTP and real-time errors.
|
|
2990
|
-
*/
|
|
2991
|
-
declare function isSonioxError(error: unknown): error is SonioxError;
|
|
2992
|
-
/**
|
|
2993
|
-
* Type guard to check if an error is a SonioxHttpError
|
|
2994
|
-
*/
|
|
2995
|
-
declare function isSonioxHttpError(error: unknown): error is SonioxHttpError;
|
|
2996
|
-
//#endregion
|
|
2997
3772
|
//#region src/http/url.d.ts
|
|
2998
3773
|
/**
|
|
2999
3774
|
* Builds a complete URL from base URL, path, and query parameters
|
|
@@ -3008,5 +3783,5 @@ declare function normalizeHeaders(headers: Headers): Record<string, string>;
|
|
|
3008
3783
|
*/
|
|
3009
3784
|
declare function mergeHeaders(...headerObjects: (Record<string, string> | undefined)[]): Record<string, string>;
|
|
3010
3785
|
//#endregion
|
|
3011
|
-
export { AbortError, type AudioData, type AudioFormat, AuthError, BadRequestError, type CleanupTarget, ConnectionError, type ContextGeneralEntry, type ContextTranslationTerm, type CreateTranscriptionOptions, type DeleteAllFilesOptions, type DeleteAllTranscriptionsOptions, type ExpressLikeRequest, type FastifyLikeRequest, FetchHttpClient, type FileIdentifier, FileListResult, type HandleWebhookOptions, type HonoLikeContext, type HttpClient, type HttpClientOptions, type HttpErrorCode, type HttpErrorDetails, type HttpMethod, type HttpObservabilityHooks, type HttpRequest, type HttpRequestBody, type HttpRequestMeta, type HttpResponse, type HttpResponseMeta, type HttpResponseType, type ISonioxTranscript, type ISonioxTranscription, type ListFilesOptions, type ListFilesResponse, type ListTranscriptionsOptions, type ListTranscriptionsResponse, type NestJSLikeRequest, NetworkError, type OneWayTranslationConfig, type QueryParams, QuotaError, type RealtimeClientOptions, RealtimeError, type RealtimeErrorCode, type RealtimeEvent, RealtimeOptions, type RealtimeResult, type RealtimeSegment, RealtimeSegmentBuffer, type RealtimeSegmentBufferOptions, type RealtimeSegmentOptions, RealtimeSttSession, type RealtimeToken, type RealtimeUtterance, RealtimeUtteranceBuffer, type RealtimeUtteranceBufferOptions, SONIOX_API_BASE_URL, SONIOX_API_WEBHOOK_HEADER_ENV, SONIOX_API_WEBHOOK_SECRET_ENV, SONIOX_API_WS_URL, SONIOX_TMP_API_KEY_DURATION_MAX, SONIOX_TMP_API_KEY_DURATION_MIN, SONIOX_TMP_API_KEY_USAGE_TYPE, type SegmentGroupKey, type SegmentTranscriptOptions, type SendStreamOptions, SonioxError, type SonioxErrorCode, SonioxFile, type SonioxFileData, SonioxHttpError, type SonioxLanguage, type SonioxModel, SonioxNodeClient, SonioxNodeClientOptions, SonioxRealtimeApi, SonioxTranscript, SonioxTranscription, type SonioxTranscriptionData, type SonioxTranscriptionMode, type SonioxTranslationTarget, StateError, type SttSessionConfig, type SttSessionEvents, type SttSessionOptions, type SttSessionState, TemporaryApiKeyRequest, TemporaryApiKeyResponse, TemporaryApiKeyUsageType, type TranscribeBaseOptions, type TranscribeFromFile, type TranscribeFromFileId, type TranscribeFromFileIdOptions, type TranscribeFromFileOptions, type TranscribeFromUrl, type TranscribeFromUrlOptions, type TranscribeOptions, type TranscriptResponse, type TranscriptSegment, type TranscriptToken, type TranscriptionContext, type TranscriptionIdentifier, TranscriptionListResult, type TranscriptionStatus, type TranslationConfig, type TwoWayTranslationConfig, type UploadFileInput, type UploadFileOptions, type WaitOptions, type WebhookAuthConfig, type WebhookEvent, type WebhookEventStatus, type WebhookHandlerResult, type WebhookHandlerResultWithFetch, type WebhookHeaders, buildUrl, createAbortError, createHttpError, createNetworkError, createParseError, createTimeoutError, isAbortError, isSonioxError, isSonioxHttpError, mergeHeaders, normalizeHeaders, segmentRealtimeTokens, segmentTranscript };
|
|
3786
|
+
export { AbortError, type AudioData, type AudioFormat, AuthError, BadRequestError, type CleanupTarget, ConnectionError, type ContextGeneralEntry, type ContextTranslationTerm, type CreateTranscriptionOptions, type DeleteAllFilesOptions, type DeleteAllTranscriptionsOptions, type ExpressLikeRequest, type FastifyLikeRequest, FetchHttpClient, type FileIdentifier, FileListResult, type GenerateSpeechOptions, type HandleWebhookOptions, type HonoLikeContext, type HttpClient, type HttpClientOptions, type HttpErrorCode, type HttpErrorDetails, type HttpMethod, type HttpObservabilityHooks, type HttpRequest, type HttpRequestBody, type HttpRequestMeta, type HttpResponse, type HttpResponseMeta, type HttpResponseType, type ISonioxTranscript, type ISonioxTranscription, type ListFilesOptions, type ListFilesResponse, type ListTranscriptionsOptions, type ListTranscriptionsResponse, type NestJSLikeRequest, NetworkError, type OneWayTranslationConfig, type QueryParams, QuotaError, type RealtimeClientOptions, RealtimeError, type RealtimeErrorCode, type RealtimeEvent, RealtimeOptions, type RealtimeResult, type RealtimeSegment, RealtimeSegmentBuffer, type RealtimeSegmentBufferOptions, type RealtimeSegmentOptions, RealtimeSttSession, type RealtimeToken, RealtimeTtsConnection, RealtimeTtsStream, type RealtimeUtterance, RealtimeUtteranceBuffer, type RealtimeUtteranceBufferOptions, type ResolvedConnectionConfig, SONIOX_API_BASE_URL, SONIOX_API_WEBHOOK_HEADER_ENV, SONIOX_API_WEBHOOK_SECRET_ENV, SONIOX_API_WS_URL, SONIOX_TMP_API_KEY_DURATION_MAX, SONIOX_TMP_API_KEY_DURATION_MIN, SONIOX_TMP_API_KEY_USAGE_TYPE, SONIOX_TTS_API_BASE_URL, SONIOX_TTS_WS_URL, type SegmentGroupKey, type SegmentTranscriptOptions, type SendStreamOptions, type SonioxConnectionConfig, SonioxError, type SonioxErrorCode, SonioxFile, type SonioxFileData, SonioxHttpError, type SonioxLanguage, type SonioxModel, SonioxNodeClient, SonioxNodeClientOptions, SonioxRealtimeApi, type SonioxRegion, SonioxTranscript, SonioxTranscription, type SonioxTranscriptionData, type SonioxTranscriptionMode, type SonioxTranslationTarget, SonioxTtsApi, StateError, type SttSessionConfig, type SttSessionEvents, type SttSessionOptions, type SttSessionState, TemporaryApiKeyRequest, TemporaryApiKeyResponse, TemporaryApiKeyUsageType, type TranscribeBaseOptions, type TranscribeFromFile, type TranscribeFromFileId, type TranscribeFromFileIdOptions, type TranscribeFromFileOptions, type TranscribeFromUrl, type TranscribeFromUrlOptions, type TranscribeOptions, type TranscriptResponse, type TranscriptSegment, type TranscriptToken, type TranscriptionContext, type TranscriptionIdentifier, TranscriptionListResult, type TranscriptionStatus, type TranslationConfig, type TtsAudioFormat, type TtsConnectionEvents, type TtsConnectionOptions, type TtsEvent, type TtsModel, type TtsStreamConfig, type TtsStreamEvents, type TtsStreamInput, type TtsStreamState, type TtsVoice, type TwoWayTranslationConfig, type UploadFileInput, type UploadFileOptions, type WaitOptions, type WebhookAuthConfig, type WebhookEvent, type WebhookEventStatus, type WebhookHandlerResult, type WebhookHandlerResultWithFetch, type WebhookHeaders, buildUrl, createAbortError, createHttpError, createNetworkError, createParseError, createTimeoutError, isAbortError, isSonioxError, isSonioxHttpError, mergeHeaders, normalizeHeaders, resolveConnectionConfig, segmentRealtimeTokens, segmentTranscript };
|
|
3012
3787
|
//# sourceMappingURL=index.d.mts.map
|