sarvamai 0.1.9a2__py3-none-any.whl → 0.1.11a0__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.
Files changed (43) hide show
  1. sarvamai/__init__.py +54 -0
  2. sarvamai/client.py +3 -0
  3. sarvamai/core/client_wrapper.py +2 -2
  4. sarvamai/errors/service_unavailable_error.py +1 -2
  5. sarvamai/requests/__init__.py +22 -0
  6. sarvamai/requests/base_job_parameters.py +7 -0
  7. sarvamai/requests/bulk_job_callback.py +15 -0
  8. sarvamai/requests/bulk_job_init_response_v_1.py +27 -0
  9. sarvamai/requests/file_signed_url_details.py +10 -0
  10. sarvamai/requests/files_download_response.py +15 -0
  11. sarvamai/requests/files_request.py +10 -0
  12. sarvamai/requests/files_upload_response.py +15 -0
  13. sarvamai/requests/job_status_v_1.py +70 -0
  14. sarvamai/requests/speech_to_text_job_parameters.py +32 -0
  15. sarvamai/requests/task_detail_v_1.py +15 -0
  16. sarvamai/requests/task_file_details.py +8 -0
  17. sarvamai/speech_to_text/raw_client.py +8 -9
  18. sarvamai/speech_to_text_job/__init__.py +4 -0
  19. sarvamai/speech_to_text_job/client.py +454 -0
  20. sarvamai/speech_to_text_job/raw_client.py +1189 -0
  21. sarvamai/text_to_speech/client.py +11 -0
  22. sarvamai/text_to_speech/raw_client.py +11 -0
  23. sarvamai/types/__init__.py +30 -0
  24. sarvamai/types/audio_codec.py +5 -0
  25. sarvamai/types/base_job_parameters.py +17 -0
  26. sarvamai/types/bulk_job_callback.py +27 -0
  27. sarvamai/types/bulk_job_init_response_v_1.py +39 -0
  28. sarvamai/types/file_signed_url_details.py +20 -0
  29. sarvamai/types/files_download_response.py +25 -0
  30. sarvamai/types/files_request.py +20 -0
  31. sarvamai/types/files_upload_response.py +25 -0
  32. sarvamai/types/job_state.py +5 -0
  33. sarvamai/types/job_status_v_1.py +80 -0
  34. sarvamai/types/speech_to_text_job_parameters.py +44 -0
  35. sarvamai/types/speech_to_text_model.py +3 -1
  36. sarvamai/types/speech_to_text_translate_model.py +3 -1
  37. sarvamai/types/storage_container_type.py +5 -0
  38. sarvamai/types/task_detail_v_1.py +25 -0
  39. sarvamai/types/task_file_details.py +20 -0
  40. sarvamai/types/task_state.py +5 -0
  41. {sarvamai-0.1.9a2.dist-info → sarvamai-0.1.11a0.dist-info}/METADATA +1 -1
  42. {sarvamai-0.1.9a2.dist-info → sarvamai-0.1.11a0.dist-info}/RECORD +43 -14
  43. {sarvamai-0.1.9a2.dist-info → sarvamai-0.1.11a0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,1189 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from json.decoder import JSONDecodeError
5
+
6
+ from ..core.api_error import ApiError
7
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8
+ from ..core.http_response import AsyncHttpResponse, HttpResponse
9
+ from ..core.jsonable_encoder import jsonable_encoder
10
+ from ..core.pydantic_utilities import parse_obj_as
11
+ from ..core.request_options import RequestOptions
12
+ from ..core.serialization import convert_and_respect_annotation_metadata
13
+ from ..errors.bad_request_error import BadRequestError
14
+ from ..errors.forbidden_error import ForbiddenError
15
+ from ..errors.internal_server_error import InternalServerError
16
+ from ..errors.service_unavailable_error import ServiceUnavailableError
17
+ from ..errors.too_many_requests_error import TooManyRequestsError
18
+ from ..errors.unprocessable_entity_error import UnprocessableEntityError
19
+ from ..requests.bulk_job_callback import BulkJobCallbackParams
20
+ from ..requests.speech_to_text_job_parameters import SpeechToTextJobParametersParams
21
+ from ..types.bulk_job_init_response_v_1 import BulkJobInitResponseV1
22
+ from ..types.files_download_response import FilesDownloadResponse
23
+ from ..types.files_upload_response import FilesUploadResponse
24
+ from ..types.job_status_v_1 import JobStatusV1
25
+
26
+ # this is used as the default value for optional parameters
27
+ OMIT = typing.cast(typing.Any, ...)
28
+
29
+
30
+ class RawSpeechToTextJobClient:
31
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
32
+ self._client_wrapper = client_wrapper
33
+
34
+ def initialise(
35
+ self,
36
+ *,
37
+ job_parameters: SpeechToTextJobParametersParams,
38
+ callback: typing.Optional[BulkJobCallbackParams] = OMIT,
39
+ request_options: typing.Optional[RequestOptions] = None,
40
+ ) -> HttpResponse[BulkJobInitResponseV1]:
41
+ """
42
+ Get a job uuid, and storage folder details for speech to text bulk job v1
43
+
44
+ Parameters
45
+ ----------
46
+ job_parameters : SpeechToTextJobParametersParams
47
+ Job Parameters for the bulk job
48
+
49
+ callback : typing.Optional[BulkJobCallbackParams]
50
+ Parameters for callback URL
51
+
52
+ request_options : typing.Optional[RequestOptions]
53
+ Request-specific configuration.
54
+
55
+ Returns
56
+ -------
57
+ HttpResponse[BulkJobInitResponseV1]
58
+ Successful Response
59
+ """
60
+ _response = self._client_wrapper.httpx_client.request(
61
+ "speech-to-text/job/v1",
62
+ base_url=self._client_wrapper.get_environment().base,
63
+ method="POST",
64
+ json={
65
+ "job_parameters": convert_and_respect_annotation_metadata(
66
+ object_=job_parameters, annotation=SpeechToTextJobParametersParams, direction="write"
67
+ ),
68
+ "callback": convert_and_respect_annotation_metadata(
69
+ object_=callback, annotation=BulkJobCallbackParams, direction="write"
70
+ ),
71
+ },
72
+ headers={
73
+ "content-type": "application/json",
74
+ },
75
+ request_options=request_options,
76
+ omit=OMIT,
77
+ )
78
+ try:
79
+ if 200 <= _response.status_code < 300:
80
+ _data = typing.cast(
81
+ BulkJobInitResponseV1,
82
+ parse_obj_as(
83
+ type_=BulkJobInitResponseV1, # type: ignore
84
+ object_=_response.json(),
85
+ ),
86
+ )
87
+ return HttpResponse(response=_response, data=_data)
88
+ if _response.status_code == 400:
89
+ raise BadRequestError(
90
+ headers=dict(_response.headers),
91
+ body=typing.cast(
92
+ typing.Optional[typing.Any],
93
+ parse_obj_as(
94
+ type_=typing.Optional[typing.Any], # type: ignore
95
+ object_=_response.json(),
96
+ ),
97
+ ),
98
+ )
99
+ if _response.status_code == 403:
100
+ raise ForbiddenError(
101
+ headers=dict(_response.headers),
102
+ body=typing.cast(
103
+ typing.Optional[typing.Any],
104
+ parse_obj_as(
105
+ type_=typing.Optional[typing.Any], # type: ignore
106
+ object_=_response.json(),
107
+ ),
108
+ ),
109
+ )
110
+ if _response.status_code == 422:
111
+ raise UnprocessableEntityError(
112
+ headers=dict(_response.headers),
113
+ body=typing.cast(
114
+ typing.Optional[typing.Any],
115
+ parse_obj_as(
116
+ type_=typing.Optional[typing.Any], # type: ignore
117
+ object_=_response.json(),
118
+ ),
119
+ ),
120
+ )
121
+ if _response.status_code == 429:
122
+ raise TooManyRequestsError(
123
+ headers=dict(_response.headers),
124
+ body=typing.cast(
125
+ typing.Optional[typing.Any],
126
+ parse_obj_as(
127
+ type_=typing.Optional[typing.Any], # type: ignore
128
+ object_=_response.json(),
129
+ ),
130
+ ),
131
+ )
132
+ if _response.status_code == 500:
133
+ raise InternalServerError(
134
+ headers=dict(_response.headers),
135
+ body=typing.cast(
136
+ typing.Optional[typing.Any],
137
+ parse_obj_as(
138
+ type_=typing.Optional[typing.Any], # type: ignore
139
+ object_=_response.json(),
140
+ ),
141
+ ),
142
+ )
143
+ if _response.status_code == 503:
144
+ raise ServiceUnavailableError(
145
+ headers=dict(_response.headers),
146
+ body=typing.cast(
147
+ typing.Optional[typing.Any],
148
+ parse_obj_as(
149
+ type_=typing.Optional[typing.Any], # type: ignore
150
+ object_=_response.json(),
151
+ ),
152
+ ),
153
+ )
154
+ _response_json = _response.json()
155
+ except JSONDecodeError:
156
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
157
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
158
+
159
+ def get_status(
160
+ self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
161
+ ) -> HttpResponse[JobStatusV1]:
162
+ """
163
+ Get the status of a speech to text bulk job V1
164
+
165
+ Parameters
166
+ ----------
167
+ job_id : str
168
+ The unique identifier of the job
169
+
170
+ request_options : typing.Optional[RequestOptions]
171
+ Request-specific configuration.
172
+
173
+ Returns
174
+ -------
175
+ HttpResponse[JobStatusV1]
176
+ Successful Response
177
+ """
178
+ _response = self._client_wrapper.httpx_client.request(
179
+ f"speech-to-text/job/v1/{jsonable_encoder(job_id)}/status",
180
+ base_url=self._client_wrapper.get_environment().base,
181
+ method="GET",
182
+ request_options=request_options,
183
+ )
184
+ try:
185
+ if 200 <= _response.status_code < 300:
186
+ _data = typing.cast(
187
+ JobStatusV1,
188
+ parse_obj_as(
189
+ type_=JobStatusV1, # type: ignore
190
+ object_=_response.json(),
191
+ ),
192
+ )
193
+ return HttpResponse(response=_response, data=_data)
194
+ if _response.status_code == 400:
195
+ raise BadRequestError(
196
+ headers=dict(_response.headers),
197
+ body=typing.cast(
198
+ typing.Optional[typing.Any],
199
+ parse_obj_as(
200
+ type_=typing.Optional[typing.Any], # type: ignore
201
+ object_=_response.json(),
202
+ ),
203
+ ),
204
+ )
205
+ if _response.status_code == 403:
206
+ raise ForbiddenError(
207
+ headers=dict(_response.headers),
208
+ body=typing.cast(
209
+ typing.Optional[typing.Any],
210
+ parse_obj_as(
211
+ type_=typing.Optional[typing.Any], # type: ignore
212
+ object_=_response.json(),
213
+ ),
214
+ ),
215
+ )
216
+ if _response.status_code == 422:
217
+ raise UnprocessableEntityError(
218
+ headers=dict(_response.headers),
219
+ body=typing.cast(
220
+ typing.Optional[typing.Any],
221
+ parse_obj_as(
222
+ type_=typing.Optional[typing.Any], # type: ignore
223
+ object_=_response.json(),
224
+ ),
225
+ ),
226
+ )
227
+ if _response.status_code == 429:
228
+ raise TooManyRequestsError(
229
+ headers=dict(_response.headers),
230
+ body=typing.cast(
231
+ typing.Optional[typing.Any],
232
+ parse_obj_as(
233
+ type_=typing.Optional[typing.Any], # type: ignore
234
+ object_=_response.json(),
235
+ ),
236
+ ),
237
+ )
238
+ if _response.status_code == 500:
239
+ raise InternalServerError(
240
+ headers=dict(_response.headers),
241
+ body=typing.cast(
242
+ typing.Optional[typing.Any],
243
+ parse_obj_as(
244
+ type_=typing.Optional[typing.Any], # type: ignore
245
+ object_=_response.json(),
246
+ ),
247
+ ),
248
+ )
249
+ if _response.status_code == 503:
250
+ raise ServiceUnavailableError(
251
+ headers=dict(_response.headers),
252
+ body=typing.cast(
253
+ typing.Optional[typing.Any],
254
+ parse_obj_as(
255
+ type_=typing.Optional[typing.Any], # type: ignore
256
+ object_=_response.json(),
257
+ ),
258
+ ),
259
+ )
260
+ _response_json = _response.json()
261
+ except JSONDecodeError:
262
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
263
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
264
+
265
+ def start(
266
+ self,
267
+ job_id: str,
268
+ *,
269
+ ptu_id: typing.Optional[int] = None,
270
+ request_options: typing.Optional[RequestOptions] = None,
271
+ ) -> HttpResponse[JobStatusV1]:
272
+ """
273
+ Start a speech to text bulk job V1
274
+
275
+ Parameters
276
+ ----------
277
+ job_id : str
278
+ The unique identifier of the job
279
+
280
+ ptu_id : typing.Optional[int]
281
+
282
+ request_options : typing.Optional[RequestOptions]
283
+ Request-specific configuration.
284
+
285
+ Returns
286
+ -------
287
+ HttpResponse[JobStatusV1]
288
+ Successful Response
289
+ """
290
+ _response = self._client_wrapper.httpx_client.request(
291
+ f"speech-to-text/job/v1/{jsonable_encoder(job_id)}/start",
292
+ base_url=self._client_wrapper.get_environment().base,
293
+ method="POST",
294
+ params={
295
+ "ptu_id": ptu_id,
296
+ },
297
+ request_options=request_options,
298
+ )
299
+ try:
300
+ if 200 <= _response.status_code < 300:
301
+ _data = typing.cast(
302
+ JobStatusV1,
303
+ parse_obj_as(
304
+ type_=JobStatusV1, # type: ignore
305
+ object_=_response.json(),
306
+ ),
307
+ )
308
+ return HttpResponse(response=_response, data=_data)
309
+ if _response.status_code == 400:
310
+ raise BadRequestError(
311
+ headers=dict(_response.headers),
312
+ body=typing.cast(
313
+ typing.Optional[typing.Any],
314
+ parse_obj_as(
315
+ type_=typing.Optional[typing.Any], # type: ignore
316
+ object_=_response.json(),
317
+ ),
318
+ ),
319
+ )
320
+ if _response.status_code == 403:
321
+ raise ForbiddenError(
322
+ headers=dict(_response.headers),
323
+ body=typing.cast(
324
+ typing.Optional[typing.Any],
325
+ parse_obj_as(
326
+ type_=typing.Optional[typing.Any], # type: ignore
327
+ object_=_response.json(),
328
+ ),
329
+ ),
330
+ )
331
+ if _response.status_code == 422:
332
+ raise UnprocessableEntityError(
333
+ headers=dict(_response.headers),
334
+ body=typing.cast(
335
+ typing.Optional[typing.Any],
336
+ parse_obj_as(
337
+ type_=typing.Optional[typing.Any], # type: ignore
338
+ object_=_response.json(),
339
+ ),
340
+ ),
341
+ )
342
+ if _response.status_code == 429:
343
+ raise TooManyRequestsError(
344
+ headers=dict(_response.headers),
345
+ body=typing.cast(
346
+ typing.Optional[typing.Any],
347
+ parse_obj_as(
348
+ type_=typing.Optional[typing.Any], # type: ignore
349
+ object_=_response.json(),
350
+ ),
351
+ ),
352
+ )
353
+ if _response.status_code == 500:
354
+ raise InternalServerError(
355
+ headers=dict(_response.headers),
356
+ body=typing.cast(
357
+ typing.Optional[typing.Any],
358
+ parse_obj_as(
359
+ type_=typing.Optional[typing.Any], # type: ignore
360
+ object_=_response.json(),
361
+ ),
362
+ ),
363
+ )
364
+ if _response.status_code == 503:
365
+ raise ServiceUnavailableError(
366
+ headers=dict(_response.headers),
367
+ body=typing.cast(
368
+ typing.Optional[typing.Any],
369
+ parse_obj_as(
370
+ type_=typing.Optional[typing.Any], # type: ignore
371
+ object_=_response.json(),
372
+ ),
373
+ ),
374
+ )
375
+ _response_json = _response.json()
376
+ except JSONDecodeError:
377
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
378
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
379
+
380
+ def get_upload_links(
381
+ self, *, job_id: str, files: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
382
+ ) -> HttpResponse[FilesUploadResponse]:
383
+ """
384
+ Start a speech to text bulk job V1
385
+
386
+ Parameters
387
+ ----------
388
+ job_id : str
389
+
390
+ files : typing.Sequence[str]
391
+
392
+ request_options : typing.Optional[RequestOptions]
393
+ Request-specific configuration.
394
+
395
+ Returns
396
+ -------
397
+ HttpResponse[FilesUploadResponse]
398
+ Successful Response
399
+ """
400
+ _response = self._client_wrapper.httpx_client.request(
401
+ "speech-to-text/job/v1/upload-files",
402
+ base_url=self._client_wrapper.get_environment().base,
403
+ method="POST",
404
+ json={
405
+ "job_id": job_id,
406
+ "files": files,
407
+ },
408
+ headers={
409
+ "content-type": "application/json",
410
+ },
411
+ request_options=request_options,
412
+ omit=OMIT,
413
+ )
414
+ try:
415
+ if 200 <= _response.status_code < 300:
416
+ _data = typing.cast(
417
+ FilesUploadResponse,
418
+ parse_obj_as(
419
+ type_=FilesUploadResponse, # type: ignore
420
+ object_=_response.json(),
421
+ ),
422
+ )
423
+ return HttpResponse(response=_response, data=_data)
424
+ if _response.status_code == 400:
425
+ raise BadRequestError(
426
+ headers=dict(_response.headers),
427
+ body=typing.cast(
428
+ typing.Optional[typing.Any],
429
+ parse_obj_as(
430
+ type_=typing.Optional[typing.Any], # type: ignore
431
+ object_=_response.json(),
432
+ ),
433
+ ),
434
+ )
435
+ if _response.status_code == 403:
436
+ raise ForbiddenError(
437
+ headers=dict(_response.headers),
438
+ body=typing.cast(
439
+ typing.Optional[typing.Any],
440
+ parse_obj_as(
441
+ type_=typing.Optional[typing.Any], # type: ignore
442
+ object_=_response.json(),
443
+ ),
444
+ ),
445
+ )
446
+ if _response.status_code == 422:
447
+ raise UnprocessableEntityError(
448
+ headers=dict(_response.headers),
449
+ body=typing.cast(
450
+ typing.Optional[typing.Any],
451
+ parse_obj_as(
452
+ type_=typing.Optional[typing.Any], # type: ignore
453
+ object_=_response.json(),
454
+ ),
455
+ ),
456
+ )
457
+ if _response.status_code == 429:
458
+ raise TooManyRequestsError(
459
+ headers=dict(_response.headers),
460
+ body=typing.cast(
461
+ typing.Optional[typing.Any],
462
+ parse_obj_as(
463
+ type_=typing.Optional[typing.Any], # type: ignore
464
+ object_=_response.json(),
465
+ ),
466
+ ),
467
+ )
468
+ if _response.status_code == 500:
469
+ raise InternalServerError(
470
+ headers=dict(_response.headers),
471
+ body=typing.cast(
472
+ typing.Optional[typing.Any],
473
+ parse_obj_as(
474
+ type_=typing.Optional[typing.Any], # type: ignore
475
+ object_=_response.json(),
476
+ ),
477
+ ),
478
+ )
479
+ if _response.status_code == 503:
480
+ raise ServiceUnavailableError(
481
+ headers=dict(_response.headers),
482
+ body=typing.cast(
483
+ typing.Optional[typing.Any],
484
+ parse_obj_as(
485
+ type_=typing.Optional[typing.Any], # type: ignore
486
+ object_=_response.json(),
487
+ ),
488
+ ),
489
+ )
490
+ _response_json = _response.json()
491
+ except JSONDecodeError:
492
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
493
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
494
+
495
+ def get_download_links(
496
+ self, *, job_id: str, files: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
497
+ ) -> HttpResponse[FilesDownloadResponse]:
498
+ """
499
+ Start a speech to text bulk job V1
500
+
501
+ Parameters
502
+ ----------
503
+ job_id : str
504
+
505
+ files : typing.Sequence[str]
506
+
507
+ request_options : typing.Optional[RequestOptions]
508
+ Request-specific configuration.
509
+
510
+ Returns
511
+ -------
512
+ HttpResponse[FilesDownloadResponse]
513
+ Successful Response
514
+ """
515
+ _response = self._client_wrapper.httpx_client.request(
516
+ "speech-to-text/job/v1/download-files",
517
+ base_url=self._client_wrapper.get_environment().base,
518
+ method="POST",
519
+ json={
520
+ "job_id": job_id,
521
+ "files": files,
522
+ },
523
+ headers={
524
+ "content-type": "application/json",
525
+ },
526
+ request_options=request_options,
527
+ omit=OMIT,
528
+ )
529
+ try:
530
+ if 200 <= _response.status_code < 300:
531
+ _data = typing.cast(
532
+ FilesDownloadResponse,
533
+ parse_obj_as(
534
+ type_=FilesDownloadResponse, # type: ignore
535
+ object_=_response.json(),
536
+ ),
537
+ )
538
+ return HttpResponse(response=_response, data=_data)
539
+ if _response.status_code == 400:
540
+ raise BadRequestError(
541
+ headers=dict(_response.headers),
542
+ body=typing.cast(
543
+ typing.Optional[typing.Any],
544
+ parse_obj_as(
545
+ type_=typing.Optional[typing.Any], # type: ignore
546
+ object_=_response.json(),
547
+ ),
548
+ ),
549
+ )
550
+ if _response.status_code == 403:
551
+ raise ForbiddenError(
552
+ headers=dict(_response.headers),
553
+ body=typing.cast(
554
+ typing.Optional[typing.Any],
555
+ parse_obj_as(
556
+ type_=typing.Optional[typing.Any], # type: ignore
557
+ object_=_response.json(),
558
+ ),
559
+ ),
560
+ )
561
+ if _response.status_code == 422:
562
+ raise UnprocessableEntityError(
563
+ headers=dict(_response.headers),
564
+ body=typing.cast(
565
+ typing.Optional[typing.Any],
566
+ parse_obj_as(
567
+ type_=typing.Optional[typing.Any], # type: ignore
568
+ object_=_response.json(),
569
+ ),
570
+ ),
571
+ )
572
+ if _response.status_code == 429:
573
+ raise TooManyRequestsError(
574
+ headers=dict(_response.headers),
575
+ body=typing.cast(
576
+ typing.Optional[typing.Any],
577
+ parse_obj_as(
578
+ type_=typing.Optional[typing.Any], # type: ignore
579
+ object_=_response.json(),
580
+ ),
581
+ ),
582
+ )
583
+ if _response.status_code == 500:
584
+ raise InternalServerError(
585
+ headers=dict(_response.headers),
586
+ body=typing.cast(
587
+ typing.Optional[typing.Any],
588
+ parse_obj_as(
589
+ type_=typing.Optional[typing.Any], # type: ignore
590
+ object_=_response.json(),
591
+ ),
592
+ ),
593
+ )
594
+ if _response.status_code == 503:
595
+ raise ServiceUnavailableError(
596
+ headers=dict(_response.headers),
597
+ body=typing.cast(
598
+ typing.Optional[typing.Any],
599
+ parse_obj_as(
600
+ type_=typing.Optional[typing.Any], # type: ignore
601
+ object_=_response.json(),
602
+ ),
603
+ ),
604
+ )
605
+ _response_json = _response.json()
606
+ except JSONDecodeError:
607
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
608
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
609
+
610
+
611
+ class AsyncRawSpeechToTextJobClient:
612
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
613
+ self._client_wrapper = client_wrapper
614
+
615
+ async def initialise(
616
+ self,
617
+ *,
618
+ job_parameters: SpeechToTextJobParametersParams,
619
+ callback: typing.Optional[BulkJobCallbackParams] = OMIT,
620
+ request_options: typing.Optional[RequestOptions] = None,
621
+ ) -> AsyncHttpResponse[BulkJobInitResponseV1]:
622
+ """
623
+ Get a job uuid, and storage folder details for speech to text bulk job v1
624
+
625
+ Parameters
626
+ ----------
627
+ job_parameters : SpeechToTextJobParametersParams
628
+ Job Parameters for the bulk job
629
+
630
+ callback : typing.Optional[BulkJobCallbackParams]
631
+ Parameters for callback URL
632
+
633
+ request_options : typing.Optional[RequestOptions]
634
+ Request-specific configuration.
635
+
636
+ Returns
637
+ -------
638
+ AsyncHttpResponse[BulkJobInitResponseV1]
639
+ Successful Response
640
+ """
641
+ _response = await self._client_wrapper.httpx_client.request(
642
+ "speech-to-text/job/v1",
643
+ base_url=self._client_wrapper.get_environment().base,
644
+ method="POST",
645
+ json={
646
+ "job_parameters": convert_and_respect_annotation_metadata(
647
+ object_=job_parameters, annotation=SpeechToTextJobParametersParams, direction="write"
648
+ ),
649
+ "callback": convert_and_respect_annotation_metadata(
650
+ object_=callback, annotation=BulkJobCallbackParams, direction="write"
651
+ ),
652
+ },
653
+ headers={
654
+ "content-type": "application/json",
655
+ },
656
+ request_options=request_options,
657
+ omit=OMIT,
658
+ )
659
+ try:
660
+ if 200 <= _response.status_code < 300:
661
+ _data = typing.cast(
662
+ BulkJobInitResponseV1,
663
+ parse_obj_as(
664
+ type_=BulkJobInitResponseV1, # type: ignore
665
+ object_=_response.json(),
666
+ ),
667
+ )
668
+ return AsyncHttpResponse(response=_response, data=_data)
669
+ if _response.status_code == 400:
670
+ raise BadRequestError(
671
+ headers=dict(_response.headers),
672
+ body=typing.cast(
673
+ typing.Optional[typing.Any],
674
+ parse_obj_as(
675
+ type_=typing.Optional[typing.Any], # type: ignore
676
+ object_=_response.json(),
677
+ ),
678
+ ),
679
+ )
680
+ if _response.status_code == 403:
681
+ raise ForbiddenError(
682
+ headers=dict(_response.headers),
683
+ body=typing.cast(
684
+ typing.Optional[typing.Any],
685
+ parse_obj_as(
686
+ type_=typing.Optional[typing.Any], # type: ignore
687
+ object_=_response.json(),
688
+ ),
689
+ ),
690
+ )
691
+ if _response.status_code == 422:
692
+ raise UnprocessableEntityError(
693
+ headers=dict(_response.headers),
694
+ body=typing.cast(
695
+ typing.Optional[typing.Any],
696
+ parse_obj_as(
697
+ type_=typing.Optional[typing.Any], # type: ignore
698
+ object_=_response.json(),
699
+ ),
700
+ ),
701
+ )
702
+ if _response.status_code == 429:
703
+ raise TooManyRequestsError(
704
+ headers=dict(_response.headers),
705
+ body=typing.cast(
706
+ typing.Optional[typing.Any],
707
+ parse_obj_as(
708
+ type_=typing.Optional[typing.Any], # type: ignore
709
+ object_=_response.json(),
710
+ ),
711
+ ),
712
+ )
713
+ if _response.status_code == 500:
714
+ raise InternalServerError(
715
+ headers=dict(_response.headers),
716
+ body=typing.cast(
717
+ typing.Optional[typing.Any],
718
+ parse_obj_as(
719
+ type_=typing.Optional[typing.Any], # type: ignore
720
+ object_=_response.json(),
721
+ ),
722
+ ),
723
+ )
724
+ if _response.status_code == 503:
725
+ raise ServiceUnavailableError(
726
+ headers=dict(_response.headers),
727
+ body=typing.cast(
728
+ typing.Optional[typing.Any],
729
+ parse_obj_as(
730
+ type_=typing.Optional[typing.Any], # type: ignore
731
+ object_=_response.json(),
732
+ ),
733
+ ),
734
+ )
735
+ _response_json = _response.json()
736
+ except JSONDecodeError:
737
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
738
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
739
+
740
+ async def get_status(
741
+ self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
742
+ ) -> AsyncHttpResponse[JobStatusV1]:
743
+ """
744
+ Get the status of a speech to text bulk job V1
745
+
746
+ Parameters
747
+ ----------
748
+ job_id : str
749
+ The unique identifier of the job
750
+
751
+ request_options : typing.Optional[RequestOptions]
752
+ Request-specific configuration.
753
+
754
+ Returns
755
+ -------
756
+ AsyncHttpResponse[JobStatusV1]
757
+ Successful Response
758
+ """
759
+ _response = await self._client_wrapper.httpx_client.request(
760
+ f"speech-to-text/job/v1/{jsonable_encoder(job_id)}/status",
761
+ base_url=self._client_wrapper.get_environment().base,
762
+ method="GET",
763
+ request_options=request_options,
764
+ )
765
+ try:
766
+ if 200 <= _response.status_code < 300:
767
+ _data = typing.cast(
768
+ JobStatusV1,
769
+ parse_obj_as(
770
+ type_=JobStatusV1, # type: ignore
771
+ object_=_response.json(),
772
+ ),
773
+ )
774
+ return AsyncHttpResponse(response=_response, data=_data)
775
+ if _response.status_code == 400:
776
+ raise BadRequestError(
777
+ headers=dict(_response.headers),
778
+ body=typing.cast(
779
+ typing.Optional[typing.Any],
780
+ parse_obj_as(
781
+ type_=typing.Optional[typing.Any], # type: ignore
782
+ object_=_response.json(),
783
+ ),
784
+ ),
785
+ )
786
+ if _response.status_code == 403:
787
+ raise ForbiddenError(
788
+ headers=dict(_response.headers),
789
+ body=typing.cast(
790
+ typing.Optional[typing.Any],
791
+ parse_obj_as(
792
+ type_=typing.Optional[typing.Any], # type: ignore
793
+ object_=_response.json(),
794
+ ),
795
+ ),
796
+ )
797
+ if _response.status_code == 422:
798
+ raise UnprocessableEntityError(
799
+ headers=dict(_response.headers),
800
+ body=typing.cast(
801
+ typing.Optional[typing.Any],
802
+ parse_obj_as(
803
+ type_=typing.Optional[typing.Any], # type: ignore
804
+ object_=_response.json(),
805
+ ),
806
+ ),
807
+ )
808
+ if _response.status_code == 429:
809
+ raise TooManyRequestsError(
810
+ headers=dict(_response.headers),
811
+ body=typing.cast(
812
+ typing.Optional[typing.Any],
813
+ parse_obj_as(
814
+ type_=typing.Optional[typing.Any], # type: ignore
815
+ object_=_response.json(),
816
+ ),
817
+ ),
818
+ )
819
+ if _response.status_code == 500:
820
+ raise InternalServerError(
821
+ headers=dict(_response.headers),
822
+ body=typing.cast(
823
+ typing.Optional[typing.Any],
824
+ parse_obj_as(
825
+ type_=typing.Optional[typing.Any], # type: ignore
826
+ object_=_response.json(),
827
+ ),
828
+ ),
829
+ )
830
+ if _response.status_code == 503:
831
+ raise ServiceUnavailableError(
832
+ headers=dict(_response.headers),
833
+ body=typing.cast(
834
+ typing.Optional[typing.Any],
835
+ parse_obj_as(
836
+ type_=typing.Optional[typing.Any], # type: ignore
837
+ object_=_response.json(),
838
+ ),
839
+ ),
840
+ )
841
+ _response_json = _response.json()
842
+ except JSONDecodeError:
843
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
844
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
845
+
846
+ async def start(
847
+ self,
848
+ job_id: str,
849
+ *,
850
+ ptu_id: typing.Optional[int] = None,
851
+ request_options: typing.Optional[RequestOptions] = None,
852
+ ) -> AsyncHttpResponse[JobStatusV1]:
853
+ """
854
+ Start a speech to text bulk job V1
855
+
856
+ Parameters
857
+ ----------
858
+ job_id : str
859
+ The unique identifier of the job
860
+
861
+ ptu_id : typing.Optional[int]
862
+
863
+ request_options : typing.Optional[RequestOptions]
864
+ Request-specific configuration.
865
+
866
+ Returns
867
+ -------
868
+ AsyncHttpResponse[JobStatusV1]
869
+ Successful Response
870
+ """
871
+ _response = await self._client_wrapper.httpx_client.request(
872
+ f"speech-to-text/job/v1/{jsonable_encoder(job_id)}/start",
873
+ base_url=self._client_wrapper.get_environment().base,
874
+ method="POST",
875
+ params={
876
+ "ptu_id": ptu_id,
877
+ },
878
+ request_options=request_options,
879
+ )
880
+ try:
881
+ if 200 <= _response.status_code < 300:
882
+ _data = typing.cast(
883
+ JobStatusV1,
884
+ parse_obj_as(
885
+ type_=JobStatusV1, # type: ignore
886
+ object_=_response.json(),
887
+ ),
888
+ )
889
+ return AsyncHttpResponse(response=_response, data=_data)
890
+ if _response.status_code == 400:
891
+ raise BadRequestError(
892
+ headers=dict(_response.headers),
893
+ body=typing.cast(
894
+ typing.Optional[typing.Any],
895
+ parse_obj_as(
896
+ type_=typing.Optional[typing.Any], # type: ignore
897
+ object_=_response.json(),
898
+ ),
899
+ ),
900
+ )
901
+ if _response.status_code == 403:
902
+ raise ForbiddenError(
903
+ headers=dict(_response.headers),
904
+ body=typing.cast(
905
+ typing.Optional[typing.Any],
906
+ parse_obj_as(
907
+ type_=typing.Optional[typing.Any], # type: ignore
908
+ object_=_response.json(),
909
+ ),
910
+ ),
911
+ )
912
+ if _response.status_code == 422:
913
+ raise UnprocessableEntityError(
914
+ headers=dict(_response.headers),
915
+ body=typing.cast(
916
+ typing.Optional[typing.Any],
917
+ parse_obj_as(
918
+ type_=typing.Optional[typing.Any], # type: ignore
919
+ object_=_response.json(),
920
+ ),
921
+ ),
922
+ )
923
+ if _response.status_code == 429:
924
+ raise TooManyRequestsError(
925
+ headers=dict(_response.headers),
926
+ body=typing.cast(
927
+ typing.Optional[typing.Any],
928
+ parse_obj_as(
929
+ type_=typing.Optional[typing.Any], # type: ignore
930
+ object_=_response.json(),
931
+ ),
932
+ ),
933
+ )
934
+ if _response.status_code == 500:
935
+ raise InternalServerError(
936
+ headers=dict(_response.headers),
937
+ body=typing.cast(
938
+ typing.Optional[typing.Any],
939
+ parse_obj_as(
940
+ type_=typing.Optional[typing.Any], # type: ignore
941
+ object_=_response.json(),
942
+ ),
943
+ ),
944
+ )
945
+ if _response.status_code == 503:
946
+ raise ServiceUnavailableError(
947
+ headers=dict(_response.headers),
948
+ body=typing.cast(
949
+ typing.Optional[typing.Any],
950
+ parse_obj_as(
951
+ type_=typing.Optional[typing.Any], # type: ignore
952
+ object_=_response.json(),
953
+ ),
954
+ ),
955
+ )
956
+ _response_json = _response.json()
957
+ except JSONDecodeError:
958
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
959
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
960
+
961
+ async def get_upload_links(
962
+ self, *, job_id: str, files: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
963
+ ) -> AsyncHttpResponse[FilesUploadResponse]:
964
+ """
965
+ Start a speech to text bulk job V1
966
+
967
+ Parameters
968
+ ----------
969
+ job_id : str
970
+
971
+ files : typing.Sequence[str]
972
+
973
+ request_options : typing.Optional[RequestOptions]
974
+ Request-specific configuration.
975
+
976
+ Returns
977
+ -------
978
+ AsyncHttpResponse[FilesUploadResponse]
979
+ Successful Response
980
+ """
981
+ _response = await self._client_wrapper.httpx_client.request(
982
+ "speech-to-text/job/v1/upload-files",
983
+ base_url=self._client_wrapper.get_environment().base,
984
+ method="POST",
985
+ json={
986
+ "job_id": job_id,
987
+ "files": files,
988
+ },
989
+ headers={
990
+ "content-type": "application/json",
991
+ },
992
+ request_options=request_options,
993
+ omit=OMIT,
994
+ )
995
+ try:
996
+ if 200 <= _response.status_code < 300:
997
+ _data = typing.cast(
998
+ FilesUploadResponse,
999
+ parse_obj_as(
1000
+ type_=FilesUploadResponse, # type: ignore
1001
+ object_=_response.json(),
1002
+ ),
1003
+ )
1004
+ return AsyncHttpResponse(response=_response, data=_data)
1005
+ if _response.status_code == 400:
1006
+ raise BadRequestError(
1007
+ headers=dict(_response.headers),
1008
+ body=typing.cast(
1009
+ typing.Optional[typing.Any],
1010
+ parse_obj_as(
1011
+ type_=typing.Optional[typing.Any], # type: ignore
1012
+ object_=_response.json(),
1013
+ ),
1014
+ ),
1015
+ )
1016
+ if _response.status_code == 403:
1017
+ raise ForbiddenError(
1018
+ headers=dict(_response.headers),
1019
+ body=typing.cast(
1020
+ typing.Optional[typing.Any],
1021
+ parse_obj_as(
1022
+ type_=typing.Optional[typing.Any], # type: ignore
1023
+ object_=_response.json(),
1024
+ ),
1025
+ ),
1026
+ )
1027
+ if _response.status_code == 422:
1028
+ raise UnprocessableEntityError(
1029
+ headers=dict(_response.headers),
1030
+ body=typing.cast(
1031
+ typing.Optional[typing.Any],
1032
+ parse_obj_as(
1033
+ type_=typing.Optional[typing.Any], # type: ignore
1034
+ object_=_response.json(),
1035
+ ),
1036
+ ),
1037
+ )
1038
+ if _response.status_code == 429:
1039
+ raise TooManyRequestsError(
1040
+ headers=dict(_response.headers),
1041
+ body=typing.cast(
1042
+ typing.Optional[typing.Any],
1043
+ parse_obj_as(
1044
+ type_=typing.Optional[typing.Any], # type: ignore
1045
+ object_=_response.json(),
1046
+ ),
1047
+ ),
1048
+ )
1049
+ if _response.status_code == 500:
1050
+ raise InternalServerError(
1051
+ headers=dict(_response.headers),
1052
+ body=typing.cast(
1053
+ typing.Optional[typing.Any],
1054
+ parse_obj_as(
1055
+ type_=typing.Optional[typing.Any], # type: ignore
1056
+ object_=_response.json(),
1057
+ ),
1058
+ ),
1059
+ )
1060
+ if _response.status_code == 503:
1061
+ raise ServiceUnavailableError(
1062
+ headers=dict(_response.headers),
1063
+ body=typing.cast(
1064
+ typing.Optional[typing.Any],
1065
+ parse_obj_as(
1066
+ type_=typing.Optional[typing.Any], # type: ignore
1067
+ object_=_response.json(),
1068
+ ),
1069
+ ),
1070
+ )
1071
+ _response_json = _response.json()
1072
+ except JSONDecodeError:
1073
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1074
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1075
+
1076
+ async def get_download_links(
1077
+ self, *, job_id: str, files: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
1078
+ ) -> AsyncHttpResponse[FilesDownloadResponse]:
1079
+ """
1080
+ Start a speech to text bulk job V1
1081
+
1082
+ Parameters
1083
+ ----------
1084
+ job_id : str
1085
+
1086
+ files : typing.Sequence[str]
1087
+
1088
+ request_options : typing.Optional[RequestOptions]
1089
+ Request-specific configuration.
1090
+
1091
+ Returns
1092
+ -------
1093
+ AsyncHttpResponse[FilesDownloadResponse]
1094
+ Successful Response
1095
+ """
1096
+ _response = await self._client_wrapper.httpx_client.request(
1097
+ "speech-to-text/job/v1/download-files",
1098
+ base_url=self._client_wrapper.get_environment().base,
1099
+ method="POST",
1100
+ json={
1101
+ "job_id": job_id,
1102
+ "files": files,
1103
+ },
1104
+ headers={
1105
+ "content-type": "application/json",
1106
+ },
1107
+ request_options=request_options,
1108
+ omit=OMIT,
1109
+ )
1110
+ try:
1111
+ if 200 <= _response.status_code < 300:
1112
+ _data = typing.cast(
1113
+ FilesDownloadResponse,
1114
+ parse_obj_as(
1115
+ type_=FilesDownloadResponse, # type: ignore
1116
+ object_=_response.json(),
1117
+ ),
1118
+ )
1119
+ return AsyncHttpResponse(response=_response, data=_data)
1120
+ if _response.status_code == 400:
1121
+ raise BadRequestError(
1122
+ headers=dict(_response.headers),
1123
+ body=typing.cast(
1124
+ typing.Optional[typing.Any],
1125
+ parse_obj_as(
1126
+ type_=typing.Optional[typing.Any], # type: ignore
1127
+ object_=_response.json(),
1128
+ ),
1129
+ ),
1130
+ )
1131
+ if _response.status_code == 403:
1132
+ raise ForbiddenError(
1133
+ headers=dict(_response.headers),
1134
+ body=typing.cast(
1135
+ typing.Optional[typing.Any],
1136
+ parse_obj_as(
1137
+ type_=typing.Optional[typing.Any], # type: ignore
1138
+ object_=_response.json(),
1139
+ ),
1140
+ ),
1141
+ )
1142
+ if _response.status_code == 422:
1143
+ raise UnprocessableEntityError(
1144
+ headers=dict(_response.headers),
1145
+ body=typing.cast(
1146
+ typing.Optional[typing.Any],
1147
+ parse_obj_as(
1148
+ type_=typing.Optional[typing.Any], # type: ignore
1149
+ object_=_response.json(),
1150
+ ),
1151
+ ),
1152
+ )
1153
+ if _response.status_code == 429:
1154
+ raise TooManyRequestsError(
1155
+ headers=dict(_response.headers),
1156
+ body=typing.cast(
1157
+ typing.Optional[typing.Any],
1158
+ parse_obj_as(
1159
+ type_=typing.Optional[typing.Any], # type: ignore
1160
+ object_=_response.json(),
1161
+ ),
1162
+ ),
1163
+ )
1164
+ if _response.status_code == 500:
1165
+ raise InternalServerError(
1166
+ headers=dict(_response.headers),
1167
+ body=typing.cast(
1168
+ typing.Optional[typing.Any],
1169
+ parse_obj_as(
1170
+ type_=typing.Optional[typing.Any], # type: ignore
1171
+ object_=_response.json(),
1172
+ ),
1173
+ ),
1174
+ )
1175
+ if _response.status_code == 503:
1176
+ raise ServiceUnavailableError(
1177
+ headers=dict(_response.headers),
1178
+ body=typing.cast(
1179
+ typing.Optional[typing.Any],
1180
+ parse_obj_as(
1181
+ type_=typing.Optional[typing.Any], # type: ignore
1182
+ object_=_response.json(),
1183
+ ),
1184
+ ),
1185
+ )
1186
+ _response_json = _response.json()
1187
+ except JSONDecodeError:
1188
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1189
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)