sarvamai 0.1.5a6__py3-none-any.whl → 0.1.5a7__py3-none-any.whl
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.
- sarvamai/__init__.py +45 -1
- sarvamai/chat/__init__.py +2 -0
- sarvamai/chat/client.py +9 -10
- sarvamai/chat/raw_client.py +48 -37
- sarvamai/client.py +13 -31
- sarvamai/core/__init__.py +5 -0
- sarvamai/core/api_error.py +13 -5
- sarvamai/core/client_wrapper.py +17 -20
- sarvamai/core/events.py +30 -0
- sarvamai/core/force_multipart.py +16 -0
- sarvamai/core/http_client.py +70 -24
- sarvamai/core/http_response.py +19 -11
- sarvamai/core/pydantic_utilities.py +69 -108
- sarvamai/environment.py +10 -3
- sarvamai/errors/__init__.py +2 -0
- sarvamai/errors/bad_request_error.py +4 -3
- sarvamai/errors/forbidden_error.py +4 -3
- sarvamai/errors/internal_server_error.py +4 -3
- sarvamai/errors/service_unavailable_error.py +4 -2
- sarvamai/errors/too_many_requests_error.py +4 -3
- sarvamai/errors/unprocessable_entity_error.py +4 -3
- sarvamai/requests/__init__.py +18 -0
- sarvamai/requests/audio_data.py +21 -0
- sarvamai/requests/audio_message.py +8 -0
- sarvamai/requests/chat_completion_request_message.py +3 -1
- sarvamai/requests/create_chat_completion_response.py +2 -2
- sarvamai/requests/diarized_transcript.py +2 -1
- sarvamai/requests/error_data.py +15 -0
- sarvamai/requests/error_details.py +0 -1
- sarvamai/requests/events_data.py +17 -0
- sarvamai/requests/language_identification_response.py +0 -1
- sarvamai/requests/speech_to_text_response.py +1 -2
- sarvamai/requests/speech_to_text_streaming_response.py +10 -0
- sarvamai/requests/speech_to_text_streaming_response_data.py +9 -0
- sarvamai/requests/speech_to_text_translate_response.py +0 -1
- sarvamai/requests/text_to_speech_response.py +2 -2
- sarvamai/requests/timestamps_model.py +2 -1
- sarvamai/requests/transcription_data.py +35 -0
- sarvamai/requests/transcription_metrics.py +15 -0
- sarvamai/requests/translation_response.py +0 -1
- sarvamai/requests/transliteration_response.py +0 -1
- sarvamai/speech_to_text/__init__.py +2 -0
- sarvamai/speech_to_text/client.py +13 -14
- sarvamai/speech_to_text/raw_client.py +99 -68
- sarvamai/speech_to_text_streaming/__init__.py +7 -0
- sarvamai/speech_to_text_streaming/client.py +189 -0
- sarvamai/speech_to_text_streaming/raw_client.py +166 -0
- sarvamai/speech_to_text_streaming/socket_client.py +129 -0
- sarvamai/speech_to_text_streaming/types/__init__.py +8 -0
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_language_code.py +8 -0
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_model.py +5 -0
- sarvamai/text/__init__.py +2 -0
- sarvamai/text/client.py +24 -25
- sarvamai/text/raw_client.py +126 -91
- sarvamai/text_to_speech/__init__.py +2 -0
- sarvamai/text_to_speech/client.py +10 -11
- sarvamai/text_to_speech/raw_client.py +49 -38
- sarvamai/types/__init__.py +24 -0
- sarvamai/types/audio_data.py +33 -0
- sarvamai/types/audio_data_encoding.py +5 -0
- sarvamai/types/audio_message.py +20 -0
- sarvamai/types/chat_completion_request_assistant_message.py +3 -3
- sarvamai/types/chat_completion_request_message.py +3 -2
- sarvamai/types/chat_completion_request_system_message.py +3 -3
- sarvamai/types/chat_completion_request_user_message.py +3 -3
- sarvamai/types/chat_completion_response_message.py +3 -3
- sarvamai/types/choice.py +4 -4
- sarvamai/types/completion_usage.py +3 -3
- sarvamai/types/create_chat_completion_response.py +3 -3
- sarvamai/types/diarized_entry.py +3 -3
- sarvamai/types/diarized_transcript.py +3 -3
- sarvamai/types/error_data.py +27 -0
- sarvamai/types/error_details.py +3 -3
- sarvamai/types/error_message.py +4 -4
- sarvamai/types/events_data.py +28 -0
- sarvamai/types/format.py +5 -0
- sarvamai/types/language_identification_response.py +2 -2
- sarvamai/types/speech_to_text_response.py +3 -3
- sarvamai/types/speech_to_text_streaming_response.py +22 -0
- sarvamai/types/speech_to_text_streaming_response_data.py +9 -0
- sarvamai/types/speech_to_text_streaming_response_type.py +5 -0
- sarvamai/types/speech_to_text_translate_response.py +3 -3
- sarvamai/types/text_to_speech_response.py +2 -2
- sarvamai/types/timestamps_model.py +2 -2
- sarvamai/types/transcription_data.py +45 -0
- sarvamai/types/transcription_metrics.py +27 -0
- sarvamai/types/translation_response.py +2 -2
- sarvamai/types/transliteration_response.py +2 -2
- sarvamai-0.1.5a7.dist-info/METADATA +28 -0
- sarvamai-0.1.5a7.dist-info/RECORD +134 -0
- sarvamai-0.1.5a6.dist-info/METADATA +0 -174
- sarvamai-0.1.5a6.dist-info/RECORD +0 -106
- {sarvamai-0.1.5a6.dist-info → sarvamai-0.1.5a7.dist-info}/WHEEL +0 -0
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
|
-
from
|
|
4
|
+
from json.decoder import JSONDecodeError
|
|
5
|
+
|
|
5
6
|
from .. import core
|
|
6
|
-
from ..
|
|
7
|
-
from ..
|
|
8
|
-
from ..core.
|
|
9
|
-
from ..core.http_response import HttpResponse
|
|
10
|
-
from ..types.speech_to_text_response import SpeechToTextResponse
|
|
7
|
+
from ..core.api_error import ApiError
|
|
8
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
9
|
+
from ..core.http_response import AsyncHttpResponse, HttpResponse
|
|
11
10
|
from ..core.pydantic_utilities import parse_obj_as
|
|
11
|
+
from ..core.request_options import RequestOptions
|
|
12
12
|
from ..errors.bad_request_error import BadRequestError
|
|
13
13
|
from ..errors.forbidden_error import ForbiddenError
|
|
14
|
-
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
15
|
-
from ..errors.too_many_requests_error import TooManyRequestsError
|
|
16
14
|
from ..errors.internal_server_error import InternalServerError
|
|
17
15
|
from ..errors.service_unavailable_error import ServiceUnavailableError
|
|
16
|
+
from ..errors.too_many_requests_error import TooManyRequestsError
|
|
17
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
18
18
|
from ..types.error_message import ErrorMessage
|
|
19
|
-
from
|
|
20
|
-
from ..
|
|
19
|
+
from ..types.speech_to_text_language import SpeechToTextLanguage
|
|
20
|
+
from ..types.speech_to_text_model import SpeechToTextModel
|
|
21
|
+
from ..types.speech_to_text_response import SpeechToTextResponse
|
|
21
22
|
from ..types.speech_to_text_translate_model import SpeechToTextTranslateModel
|
|
22
23
|
from ..types.speech_to_text_translate_response import SpeechToTextTranslateResponse
|
|
23
|
-
from ..core.client_wrapper import AsyncClientWrapper
|
|
24
|
-
from ..core.http_response import AsyncHttpResponse
|
|
25
24
|
|
|
26
25
|
# this is used as the default value for optional parameters
|
|
27
26
|
OMIT = typing.cast(typing.Any, ...)
|
|
@@ -80,6 +79,7 @@ class RawSpeechToTextClient:
|
|
|
80
79
|
"""
|
|
81
80
|
_response = self._client_wrapper.httpx_client.request(
|
|
82
81
|
"speech-to-text",
|
|
82
|
+
base_url=self._client_wrapper.get_environment().base,
|
|
83
83
|
method="POST",
|
|
84
84
|
data={
|
|
85
85
|
"model": model,
|
|
@@ -90,6 +90,7 @@ class RawSpeechToTextClient:
|
|
|
90
90
|
},
|
|
91
91
|
request_options=request_options,
|
|
92
92
|
omit=OMIT,
|
|
93
|
+
force_multipart=True,
|
|
93
94
|
)
|
|
94
95
|
try:
|
|
95
96
|
if 200 <= _response.status_code < 300:
|
|
@@ -103,68 +104,74 @@ class RawSpeechToTextClient:
|
|
|
103
104
|
return HttpResponse(response=_response, data=_data)
|
|
104
105
|
if _response.status_code == 400:
|
|
105
106
|
raise BadRequestError(
|
|
106
|
-
|
|
107
|
+
headers=dict(_response.headers),
|
|
108
|
+
body=typing.cast(
|
|
107
109
|
typing.Optional[typing.Any],
|
|
108
110
|
parse_obj_as(
|
|
109
111
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
110
112
|
object_=_response.json(),
|
|
111
113
|
),
|
|
112
|
-
)
|
|
114
|
+
),
|
|
113
115
|
)
|
|
114
116
|
if _response.status_code == 403:
|
|
115
117
|
raise ForbiddenError(
|
|
116
|
-
|
|
118
|
+
headers=dict(_response.headers),
|
|
119
|
+
body=typing.cast(
|
|
117
120
|
typing.Optional[typing.Any],
|
|
118
121
|
parse_obj_as(
|
|
119
122
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
120
123
|
object_=_response.json(),
|
|
121
124
|
),
|
|
122
|
-
)
|
|
125
|
+
),
|
|
123
126
|
)
|
|
124
127
|
if _response.status_code == 422:
|
|
125
128
|
raise UnprocessableEntityError(
|
|
126
|
-
|
|
129
|
+
headers=dict(_response.headers),
|
|
130
|
+
body=typing.cast(
|
|
127
131
|
typing.Optional[typing.Any],
|
|
128
132
|
parse_obj_as(
|
|
129
133
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
130
134
|
object_=_response.json(),
|
|
131
135
|
),
|
|
132
|
-
)
|
|
136
|
+
),
|
|
133
137
|
)
|
|
134
138
|
if _response.status_code == 429:
|
|
135
139
|
raise TooManyRequestsError(
|
|
136
|
-
|
|
140
|
+
headers=dict(_response.headers),
|
|
141
|
+
body=typing.cast(
|
|
137
142
|
typing.Optional[typing.Any],
|
|
138
143
|
parse_obj_as(
|
|
139
144
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
140
145
|
object_=_response.json(),
|
|
141
146
|
),
|
|
142
|
-
)
|
|
147
|
+
),
|
|
143
148
|
)
|
|
144
149
|
if _response.status_code == 500:
|
|
145
150
|
raise InternalServerError(
|
|
146
|
-
|
|
151
|
+
headers=dict(_response.headers),
|
|
152
|
+
body=typing.cast(
|
|
147
153
|
typing.Optional[typing.Any],
|
|
148
154
|
parse_obj_as(
|
|
149
155
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
150
156
|
object_=_response.json(),
|
|
151
157
|
),
|
|
152
|
-
)
|
|
158
|
+
),
|
|
153
159
|
)
|
|
154
160
|
if _response.status_code == 503:
|
|
155
161
|
raise ServiceUnavailableError(
|
|
156
|
-
|
|
162
|
+
headers=dict(_response.headers),
|
|
163
|
+
body=typing.cast(
|
|
157
164
|
ErrorMessage,
|
|
158
165
|
parse_obj_as(
|
|
159
166
|
type_=ErrorMessage, # type: ignore
|
|
160
167
|
object_=_response.json(),
|
|
161
168
|
),
|
|
162
|
-
)
|
|
169
|
+
),
|
|
163
170
|
)
|
|
164
171
|
_response_json = _response.json()
|
|
165
172
|
except JSONDecodeError:
|
|
166
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
167
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
173
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
174
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
168
175
|
|
|
169
176
|
def translate(
|
|
170
177
|
self,
|
|
@@ -210,6 +217,7 @@ class RawSpeechToTextClient:
|
|
|
210
217
|
"""
|
|
211
218
|
_response = self._client_wrapper.httpx_client.request(
|
|
212
219
|
"speech-to-text-translate",
|
|
220
|
+
base_url=self._client_wrapper.get_environment().base,
|
|
213
221
|
method="POST",
|
|
214
222
|
data={
|
|
215
223
|
"prompt": prompt,
|
|
@@ -220,6 +228,7 @@ class RawSpeechToTextClient:
|
|
|
220
228
|
},
|
|
221
229
|
request_options=request_options,
|
|
222
230
|
omit=OMIT,
|
|
231
|
+
force_multipart=True,
|
|
223
232
|
)
|
|
224
233
|
try:
|
|
225
234
|
if 200 <= _response.status_code < 300:
|
|
@@ -233,68 +242,74 @@ class RawSpeechToTextClient:
|
|
|
233
242
|
return HttpResponse(response=_response, data=_data)
|
|
234
243
|
if _response.status_code == 400:
|
|
235
244
|
raise BadRequestError(
|
|
236
|
-
|
|
245
|
+
headers=dict(_response.headers),
|
|
246
|
+
body=typing.cast(
|
|
237
247
|
typing.Optional[typing.Any],
|
|
238
248
|
parse_obj_as(
|
|
239
249
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
240
250
|
object_=_response.json(),
|
|
241
251
|
),
|
|
242
|
-
)
|
|
252
|
+
),
|
|
243
253
|
)
|
|
244
254
|
if _response.status_code == 403:
|
|
245
255
|
raise ForbiddenError(
|
|
246
|
-
|
|
256
|
+
headers=dict(_response.headers),
|
|
257
|
+
body=typing.cast(
|
|
247
258
|
typing.Optional[typing.Any],
|
|
248
259
|
parse_obj_as(
|
|
249
260
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
250
261
|
object_=_response.json(),
|
|
251
262
|
),
|
|
252
|
-
)
|
|
263
|
+
),
|
|
253
264
|
)
|
|
254
265
|
if _response.status_code == 422:
|
|
255
266
|
raise UnprocessableEntityError(
|
|
256
|
-
|
|
267
|
+
headers=dict(_response.headers),
|
|
268
|
+
body=typing.cast(
|
|
257
269
|
typing.Optional[typing.Any],
|
|
258
270
|
parse_obj_as(
|
|
259
271
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
260
272
|
object_=_response.json(),
|
|
261
273
|
),
|
|
262
|
-
)
|
|
274
|
+
),
|
|
263
275
|
)
|
|
264
276
|
if _response.status_code == 429:
|
|
265
277
|
raise TooManyRequestsError(
|
|
266
|
-
|
|
278
|
+
headers=dict(_response.headers),
|
|
279
|
+
body=typing.cast(
|
|
267
280
|
typing.Optional[typing.Any],
|
|
268
281
|
parse_obj_as(
|
|
269
282
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
270
283
|
object_=_response.json(),
|
|
271
284
|
),
|
|
272
|
-
)
|
|
285
|
+
),
|
|
273
286
|
)
|
|
274
287
|
if _response.status_code == 500:
|
|
275
288
|
raise InternalServerError(
|
|
276
|
-
|
|
289
|
+
headers=dict(_response.headers),
|
|
290
|
+
body=typing.cast(
|
|
277
291
|
typing.Optional[typing.Any],
|
|
278
292
|
parse_obj_as(
|
|
279
293
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
280
294
|
object_=_response.json(),
|
|
281
295
|
),
|
|
282
|
-
)
|
|
296
|
+
),
|
|
283
297
|
)
|
|
284
298
|
if _response.status_code == 503:
|
|
285
299
|
raise ServiceUnavailableError(
|
|
286
|
-
|
|
300
|
+
headers=dict(_response.headers),
|
|
301
|
+
body=typing.cast(
|
|
287
302
|
ErrorMessage,
|
|
288
303
|
parse_obj_as(
|
|
289
304
|
type_=ErrorMessage, # type: ignore
|
|
290
305
|
object_=_response.json(),
|
|
291
306
|
),
|
|
292
|
-
)
|
|
307
|
+
),
|
|
293
308
|
)
|
|
294
309
|
_response_json = _response.json()
|
|
295
310
|
except JSONDecodeError:
|
|
296
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
297
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
311
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
312
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
298
313
|
|
|
299
314
|
|
|
300
315
|
class AsyncRawSpeechToTextClient:
|
|
@@ -350,6 +365,7 @@ class AsyncRawSpeechToTextClient:
|
|
|
350
365
|
"""
|
|
351
366
|
_response = await self._client_wrapper.httpx_client.request(
|
|
352
367
|
"speech-to-text",
|
|
368
|
+
base_url=self._client_wrapper.get_environment().base,
|
|
353
369
|
method="POST",
|
|
354
370
|
data={
|
|
355
371
|
"model": model,
|
|
@@ -360,6 +376,7 @@ class AsyncRawSpeechToTextClient:
|
|
|
360
376
|
},
|
|
361
377
|
request_options=request_options,
|
|
362
378
|
omit=OMIT,
|
|
379
|
+
force_multipart=True,
|
|
363
380
|
)
|
|
364
381
|
try:
|
|
365
382
|
if 200 <= _response.status_code < 300:
|
|
@@ -373,68 +390,74 @@ class AsyncRawSpeechToTextClient:
|
|
|
373
390
|
return AsyncHttpResponse(response=_response, data=_data)
|
|
374
391
|
if _response.status_code == 400:
|
|
375
392
|
raise BadRequestError(
|
|
376
|
-
|
|
393
|
+
headers=dict(_response.headers),
|
|
394
|
+
body=typing.cast(
|
|
377
395
|
typing.Optional[typing.Any],
|
|
378
396
|
parse_obj_as(
|
|
379
397
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
380
398
|
object_=_response.json(),
|
|
381
399
|
),
|
|
382
|
-
)
|
|
400
|
+
),
|
|
383
401
|
)
|
|
384
402
|
if _response.status_code == 403:
|
|
385
403
|
raise ForbiddenError(
|
|
386
|
-
|
|
404
|
+
headers=dict(_response.headers),
|
|
405
|
+
body=typing.cast(
|
|
387
406
|
typing.Optional[typing.Any],
|
|
388
407
|
parse_obj_as(
|
|
389
408
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
390
409
|
object_=_response.json(),
|
|
391
410
|
),
|
|
392
|
-
)
|
|
411
|
+
),
|
|
393
412
|
)
|
|
394
413
|
if _response.status_code == 422:
|
|
395
414
|
raise UnprocessableEntityError(
|
|
396
|
-
|
|
415
|
+
headers=dict(_response.headers),
|
|
416
|
+
body=typing.cast(
|
|
397
417
|
typing.Optional[typing.Any],
|
|
398
418
|
parse_obj_as(
|
|
399
419
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
400
420
|
object_=_response.json(),
|
|
401
421
|
),
|
|
402
|
-
)
|
|
422
|
+
),
|
|
403
423
|
)
|
|
404
424
|
if _response.status_code == 429:
|
|
405
425
|
raise TooManyRequestsError(
|
|
406
|
-
|
|
426
|
+
headers=dict(_response.headers),
|
|
427
|
+
body=typing.cast(
|
|
407
428
|
typing.Optional[typing.Any],
|
|
408
429
|
parse_obj_as(
|
|
409
430
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
410
431
|
object_=_response.json(),
|
|
411
432
|
),
|
|
412
|
-
)
|
|
433
|
+
),
|
|
413
434
|
)
|
|
414
435
|
if _response.status_code == 500:
|
|
415
436
|
raise InternalServerError(
|
|
416
|
-
|
|
437
|
+
headers=dict(_response.headers),
|
|
438
|
+
body=typing.cast(
|
|
417
439
|
typing.Optional[typing.Any],
|
|
418
440
|
parse_obj_as(
|
|
419
441
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
420
442
|
object_=_response.json(),
|
|
421
443
|
),
|
|
422
|
-
)
|
|
444
|
+
),
|
|
423
445
|
)
|
|
424
446
|
if _response.status_code == 503:
|
|
425
447
|
raise ServiceUnavailableError(
|
|
426
|
-
|
|
448
|
+
headers=dict(_response.headers),
|
|
449
|
+
body=typing.cast(
|
|
427
450
|
ErrorMessage,
|
|
428
451
|
parse_obj_as(
|
|
429
452
|
type_=ErrorMessage, # type: ignore
|
|
430
453
|
object_=_response.json(),
|
|
431
454
|
),
|
|
432
|
-
)
|
|
455
|
+
),
|
|
433
456
|
)
|
|
434
457
|
_response_json = _response.json()
|
|
435
458
|
except JSONDecodeError:
|
|
436
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
437
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
459
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
460
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
438
461
|
|
|
439
462
|
async def translate(
|
|
440
463
|
self,
|
|
@@ -480,6 +503,7 @@ class AsyncRawSpeechToTextClient:
|
|
|
480
503
|
"""
|
|
481
504
|
_response = await self._client_wrapper.httpx_client.request(
|
|
482
505
|
"speech-to-text-translate",
|
|
506
|
+
base_url=self._client_wrapper.get_environment().base,
|
|
483
507
|
method="POST",
|
|
484
508
|
data={
|
|
485
509
|
"prompt": prompt,
|
|
@@ -490,6 +514,7 @@ class AsyncRawSpeechToTextClient:
|
|
|
490
514
|
},
|
|
491
515
|
request_options=request_options,
|
|
492
516
|
omit=OMIT,
|
|
517
|
+
force_multipart=True,
|
|
493
518
|
)
|
|
494
519
|
try:
|
|
495
520
|
if 200 <= _response.status_code < 300:
|
|
@@ -503,65 +528,71 @@ class AsyncRawSpeechToTextClient:
|
|
|
503
528
|
return AsyncHttpResponse(response=_response, data=_data)
|
|
504
529
|
if _response.status_code == 400:
|
|
505
530
|
raise BadRequestError(
|
|
506
|
-
|
|
531
|
+
headers=dict(_response.headers),
|
|
532
|
+
body=typing.cast(
|
|
507
533
|
typing.Optional[typing.Any],
|
|
508
534
|
parse_obj_as(
|
|
509
535
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
510
536
|
object_=_response.json(),
|
|
511
537
|
),
|
|
512
|
-
)
|
|
538
|
+
),
|
|
513
539
|
)
|
|
514
540
|
if _response.status_code == 403:
|
|
515
541
|
raise ForbiddenError(
|
|
516
|
-
|
|
542
|
+
headers=dict(_response.headers),
|
|
543
|
+
body=typing.cast(
|
|
517
544
|
typing.Optional[typing.Any],
|
|
518
545
|
parse_obj_as(
|
|
519
546
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
520
547
|
object_=_response.json(),
|
|
521
548
|
),
|
|
522
|
-
)
|
|
549
|
+
),
|
|
523
550
|
)
|
|
524
551
|
if _response.status_code == 422:
|
|
525
552
|
raise UnprocessableEntityError(
|
|
526
|
-
|
|
553
|
+
headers=dict(_response.headers),
|
|
554
|
+
body=typing.cast(
|
|
527
555
|
typing.Optional[typing.Any],
|
|
528
556
|
parse_obj_as(
|
|
529
557
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
530
558
|
object_=_response.json(),
|
|
531
559
|
),
|
|
532
|
-
)
|
|
560
|
+
),
|
|
533
561
|
)
|
|
534
562
|
if _response.status_code == 429:
|
|
535
563
|
raise TooManyRequestsError(
|
|
536
|
-
|
|
564
|
+
headers=dict(_response.headers),
|
|
565
|
+
body=typing.cast(
|
|
537
566
|
typing.Optional[typing.Any],
|
|
538
567
|
parse_obj_as(
|
|
539
568
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
540
569
|
object_=_response.json(),
|
|
541
570
|
),
|
|
542
|
-
)
|
|
571
|
+
),
|
|
543
572
|
)
|
|
544
573
|
if _response.status_code == 500:
|
|
545
574
|
raise InternalServerError(
|
|
546
|
-
|
|
575
|
+
headers=dict(_response.headers),
|
|
576
|
+
body=typing.cast(
|
|
547
577
|
typing.Optional[typing.Any],
|
|
548
578
|
parse_obj_as(
|
|
549
579
|
type_=typing.Optional[typing.Any], # type: ignore
|
|
550
580
|
object_=_response.json(),
|
|
551
581
|
),
|
|
552
|
-
)
|
|
582
|
+
),
|
|
553
583
|
)
|
|
554
584
|
if _response.status_code == 503:
|
|
555
585
|
raise ServiceUnavailableError(
|
|
556
|
-
|
|
586
|
+
headers=dict(_response.headers),
|
|
587
|
+
body=typing.cast(
|
|
557
588
|
ErrorMessage,
|
|
558
589
|
parse_obj_as(
|
|
559
590
|
type_=ErrorMessage, # type: ignore
|
|
560
591
|
object_=_response.json(),
|
|
561
592
|
),
|
|
562
|
-
)
|
|
593
|
+
),
|
|
563
594
|
)
|
|
564
595
|
_response_json = _response.json()
|
|
565
596
|
except JSONDecodeError:
|
|
566
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
567
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
597
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
598
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from contextlib import asynccontextmanager, contextmanager
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
import websockets
|
|
8
|
+
import websockets.sync.client as websockets_sync_client
|
|
9
|
+
from ..core.api_error import ApiError
|
|
10
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
11
|
+
from ..core.request_options import RequestOptions
|
|
12
|
+
from .raw_client import AsyncRawSpeechToTextStreamingClient, RawSpeechToTextStreamingClient
|
|
13
|
+
from .socket_client import AsyncSpeechToTextStreamingSocketClient, SpeechToTextStreamingSocketClient
|
|
14
|
+
from .types.speech_to_text_streaming_language_code import SpeechToTextStreamingLanguageCode
|
|
15
|
+
from .types.speech_to_text_streaming_model import SpeechToTextStreamingModel
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SpeechToTextStreamingClient:
|
|
19
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
20
|
+
self._raw_client = RawSpeechToTextStreamingClient(client_wrapper=client_wrapper)
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def with_raw_response(self) -> RawSpeechToTextStreamingClient:
|
|
24
|
+
"""
|
|
25
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
RawSpeechToTextStreamingClient
|
|
30
|
+
"""
|
|
31
|
+
return self._raw_client
|
|
32
|
+
|
|
33
|
+
@contextmanager
|
|
34
|
+
def connect(
|
|
35
|
+
self,
|
|
36
|
+
*,
|
|
37
|
+
language_code: SpeechToTextStreamingLanguageCode,
|
|
38
|
+
model: SpeechToTextStreamingModel,
|
|
39
|
+
high_vad_sensitivity: typing.Optional[str] = None,
|
|
40
|
+
vad_signals: typing.Optional[str] = None,
|
|
41
|
+
api_subscription_key: typing.Optional[str] = None,
|
|
42
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
43
|
+
) -> typing.Iterator[SpeechToTextStreamingSocketClient]:
|
|
44
|
+
"""
|
|
45
|
+
WebSocket channel for real-time speech to text streaming
|
|
46
|
+
|
|
47
|
+
Parameters
|
|
48
|
+
----------
|
|
49
|
+
language_code : SpeechToTextStreamingLanguageCode
|
|
50
|
+
Language code for speech recognition
|
|
51
|
+
|
|
52
|
+
model : SpeechToTextStreamingModel
|
|
53
|
+
Speech to text model to use
|
|
54
|
+
|
|
55
|
+
high_vad_sensitivity : typing.Optional[str]
|
|
56
|
+
Enable high VAD (Voice Activity Detection) sensitivity
|
|
57
|
+
|
|
58
|
+
vad_signals : typing.Optional[str]
|
|
59
|
+
Enable VAD signals in response
|
|
60
|
+
|
|
61
|
+
api_subscription_key : typing.Optional[str]
|
|
62
|
+
API subscription key for authentication
|
|
63
|
+
|
|
64
|
+
request_options : typing.Optional[RequestOptions]
|
|
65
|
+
Request-specific configuration.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
SpeechToTextStreamingSocketClient
|
|
70
|
+
"""
|
|
71
|
+
ws_url = self._raw_client._client_wrapper.get_environment().production + "/speech-to-text/ws"
|
|
72
|
+
query_params = httpx.QueryParams()
|
|
73
|
+
if language_code is not None:
|
|
74
|
+
query_params = query_params.add("language-code", language_code)
|
|
75
|
+
if model is not None:
|
|
76
|
+
query_params = query_params.add("model", model)
|
|
77
|
+
if high_vad_sensitivity is not None:
|
|
78
|
+
query_params = query_params.add("high_vad_sensitivity", high_vad_sensitivity)
|
|
79
|
+
if vad_signals is not None:
|
|
80
|
+
query_params = query_params.add("vad_signals", vad_signals)
|
|
81
|
+
ws_url = ws_url + f"?{query_params}"
|
|
82
|
+
headers = self._raw_client._client_wrapper.get_headers()
|
|
83
|
+
if api_subscription_key is not None:
|
|
84
|
+
headers["Api-Subscription-Key"] = str(api_subscription_key)
|
|
85
|
+
if request_options and "additional_headers" in request_options:
|
|
86
|
+
headers.update(request_options["additional_headers"])
|
|
87
|
+
try:
|
|
88
|
+
with websockets_sync_client.connect(ws_url, additional_headers=headers) as protocol:
|
|
89
|
+
yield SpeechToTextStreamingSocketClient(websocket=protocol)
|
|
90
|
+
except websockets.exceptions.InvalidStatusCode as exc:
|
|
91
|
+
status_code: int = exc.status_code
|
|
92
|
+
if status_code == 401:
|
|
93
|
+
raise ApiError(
|
|
94
|
+
status_code=status_code,
|
|
95
|
+
headers=dict(headers),
|
|
96
|
+
body="Websocket initialized with invalid credentials.",
|
|
97
|
+
)
|
|
98
|
+
raise ApiError(
|
|
99
|
+
status_code=status_code,
|
|
100
|
+
headers=dict(headers),
|
|
101
|
+
body="Unexpected error when initializing websocket connection.",
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class AsyncSpeechToTextStreamingClient:
|
|
106
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
107
|
+
self._raw_client = AsyncRawSpeechToTextStreamingClient(client_wrapper=client_wrapper)
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def with_raw_response(self) -> AsyncRawSpeechToTextStreamingClient:
|
|
111
|
+
"""
|
|
112
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
113
|
+
|
|
114
|
+
Returns
|
|
115
|
+
-------
|
|
116
|
+
AsyncRawSpeechToTextStreamingClient
|
|
117
|
+
"""
|
|
118
|
+
return self._raw_client
|
|
119
|
+
|
|
120
|
+
@asynccontextmanager
|
|
121
|
+
async def connect(
|
|
122
|
+
self,
|
|
123
|
+
*,
|
|
124
|
+
language_code: SpeechToTextStreamingLanguageCode,
|
|
125
|
+
model: SpeechToTextStreamingModel,
|
|
126
|
+
high_vad_sensitivity: typing.Optional[str] = None,
|
|
127
|
+
vad_signals: typing.Optional[str] = None,
|
|
128
|
+
api_subscription_key: typing.Optional[str] = None,
|
|
129
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
130
|
+
) -> typing.AsyncIterator[AsyncSpeechToTextStreamingSocketClient]:
|
|
131
|
+
"""
|
|
132
|
+
WebSocket channel for real-time speech to text streaming
|
|
133
|
+
|
|
134
|
+
Parameters
|
|
135
|
+
----------
|
|
136
|
+
language_code : SpeechToTextStreamingLanguageCode
|
|
137
|
+
Language code for speech recognition
|
|
138
|
+
|
|
139
|
+
model : SpeechToTextStreamingModel
|
|
140
|
+
Speech to text model to use
|
|
141
|
+
|
|
142
|
+
high_vad_sensitivity : typing.Optional[str]
|
|
143
|
+
Enable high VAD (Voice Activity Detection) sensitivity
|
|
144
|
+
|
|
145
|
+
vad_signals : typing.Optional[str]
|
|
146
|
+
Enable VAD signals in response
|
|
147
|
+
|
|
148
|
+
api_subscription_key : typing.Optional[str]
|
|
149
|
+
API subscription key for authentication
|
|
150
|
+
|
|
151
|
+
request_options : typing.Optional[RequestOptions]
|
|
152
|
+
Request-specific configuration.
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
AsyncSpeechToTextStreamingSocketClient
|
|
157
|
+
"""
|
|
158
|
+
ws_url = self._raw_client._client_wrapper.get_environment().production + "/speech-to-text/ws"
|
|
159
|
+
query_params = httpx.QueryParams()
|
|
160
|
+
if language_code is not None:
|
|
161
|
+
query_params = query_params.add("language-code", language_code)
|
|
162
|
+
if model is not None:
|
|
163
|
+
query_params = query_params.add("model", model)
|
|
164
|
+
if high_vad_sensitivity is not None:
|
|
165
|
+
query_params = query_params.add("high_vad_sensitivity", high_vad_sensitivity)
|
|
166
|
+
if vad_signals is not None:
|
|
167
|
+
query_params = query_params.add("vad_signals", vad_signals)
|
|
168
|
+
ws_url = ws_url + f"?{query_params}"
|
|
169
|
+
headers = self._raw_client._client_wrapper.get_headers()
|
|
170
|
+
if api_subscription_key is not None:
|
|
171
|
+
headers["Api-Subscription-Key"] = str(api_subscription_key)
|
|
172
|
+
if request_options and "additional_headers" in request_options:
|
|
173
|
+
headers.update(request_options["additional_headers"])
|
|
174
|
+
try:
|
|
175
|
+
async with websockets.connect(ws_url, extra_headers=headers) as protocol:
|
|
176
|
+
yield AsyncSpeechToTextStreamingSocketClient(websocket=protocol)
|
|
177
|
+
except websockets.exceptions.InvalidStatusCode as exc:
|
|
178
|
+
status_code: int = exc.status_code
|
|
179
|
+
if status_code == 401:
|
|
180
|
+
raise ApiError(
|
|
181
|
+
status_code=status_code,
|
|
182
|
+
headers=dict(headers),
|
|
183
|
+
body="Websocket initialized with invalid credentials.",
|
|
184
|
+
)
|
|
185
|
+
raise ApiError(
|
|
186
|
+
status_code=status_code,
|
|
187
|
+
headers=dict(headers),
|
|
188
|
+
body="Unexpected error when initializing websocket connection.",
|
|
189
|
+
)
|