-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.ts
More file actions
163 lines (141 loc) · 3.58 KB
/
index.ts
File metadata and controls
163 lines (141 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { AudioEncoding } from "..";
export type LLMGatewayMessage = {
role: string;
content: string;
};
export type LLMGatewayConfig = {
model: string;
messages: LLMGatewayMessage[];
max_tokens: number;
};
export type StreamingTranscriberParams = {
websocketBaseUrl?: string;
apiKey?: string;
token?: string;
sampleRate: number;
encoding?: AudioEncoding;
endOfTurnConfidenceThreshold?: number;
/**
* @deprecated Use `minTurnSilence` instead. This parameter will be removed in a future release.
*/
minEndOfTurnSilenceWhenConfident?: number;
minTurnSilence?: number;
maxTurnSilence?: number;
vadThreshold?: number;
formatTurns?: boolean;
filterProfanity?: boolean;
keyterms?: string[];
keytermsPrompt?: string[];
prompt?: string;
speechModel: StreamingSpeechModel;
languageDetection?: boolean;
domain?: StreamingDomain;
inactivityTimeout?: number;
speakerLabels?: boolean;
maxSpeakers?: number;
llmGateway?: LLMGatewayConfig;
};
export type StreamingEvents =
| "open"
| "close"
| "turn"
| "speechStarted"
| "llmGatewayResponse"
| "error";
export type StreamingListeners = {
open?: (event: BeginEvent) => void;
close?: (code: number, reason: string) => void;
turn?: (event: TurnEvent) => void;
speechStarted?: (event: SpeechStartedEvent) => void;
llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
error?: (error: Error) => void;
};
export type StreamingSpeechModel =
| "universal-streaming-english"
| "universal-streaming-multilingual"
| "u3-rt-pro"
| "whisper-rt"
| "u3-pro";
export type StreamingDomain = "medical-v1";
export type StreamingTokenParams = {
expires_in_seconds: number;
max_session_duration_seconds?: number;
};
export type StreamingTemporaryTokenResponse = {
token: string;
};
export type StreamingAudioData = ArrayBufferLike;
export type BeginEvent = {
type: "Begin";
id: string;
expires_at: number;
};
export type SpeechStartedEvent = {
type: "SpeechStarted";
timestamp: number;
};
export type TurnEvent = {
type: "Turn";
turn_order: number;
turn_is_formatted: boolean;
end_of_turn: boolean;
transcript: string;
end_of_turn_confidence: number;
words: StreamingWord[];
language_code?: string;
language_confidence?: number;
speaker_label?: string;
};
export type StreamingWord = {
start: number;
end: number;
confidence: number;
text: string;
word_is_final: boolean;
};
export type TerminationEvent = {
type: "Termination";
audio_duration_seconds: number;
session_duration_seconds: number;
};
export type StreamingTerminateSession = {
type: "Terminate";
};
export type StreamingUpdateConfiguration = {
type: "UpdateConfiguration";
end_of_turn_confidence_threshold?: number;
/**
* @deprecated Use `min_turn_silence` instead. This parameter will be removed in a future release.
*/
min_end_of_turn_silence_when_confident?: number;
min_turn_silence?: number;
max_turn_silence?: number;
vad_threshold?: number;
format_turns?: boolean;
keyterms_prompt?: string[];
prompt?: string;
filter_profanity?: boolean;
};
export type StreamingForceEndpoint = {
type: "ForceEndpoint";
};
export type ErrorEvent = {
error: string;
};
export type LLMGatewayResponseEvent = {
type: "LLMGatewayResponse";
turn_order: number;
transcript: string;
data: unknown;
};
export type StreamingEventMessage =
| BeginEvent
| TurnEvent
| SpeechStartedEvent
| TerminationEvent
| LLMGatewayResponseEvent
| ErrorEvent;
export type StreamingOperationMessage =
| StreamingUpdateConfiguration
| StreamingForceEndpoint
| StreamingTerminateSession;