sarvamai 0.1.11a0__py3-none-any.whl → 0.1.11a1__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/core/client_wrapper.py +2 -2
- sarvamai/speech_to_text_job/client.py +89 -14
- sarvamai/speech_to_text_job/job.py +468 -0
- {sarvamai-0.1.11a0.dist-info → sarvamai-0.1.11a1.dist-info}/METADATA +1 -1
- {sarvamai-0.1.11a0.dist-info → sarvamai-0.1.11a1.dist-info}/RECORD +6 -5
- {sarvamai-0.1.11a0.dist-info → sarvamai-0.1.11a1.dist-info}/WHEEL +0 -0
sarvamai/core/client_wrapper.py
CHANGED
|
@@ -23,10 +23,10 @@ class BaseClientWrapper:
|
|
|
23
23
|
|
|
24
24
|
def get_headers(self) -> typing.Dict[str, str]:
|
|
25
25
|
headers: typing.Dict[str, str] = {
|
|
26
|
-
"User-Agent": "sarvamai/0.1.
|
|
26
|
+
"User-Agent": "sarvamai/0.1.11a1",
|
|
27
27
|
"X-Fern-Language": "Python",
|
|
28
28
|
"X-Fern-SDK-Name": "sarvamai",
|
|
29
|
-
"X-Fern-SDK-Version": "0.1.
|
|
29
|
+
"X-Fern-SDK-Version": "0.1.11a1",
|
|
30
30
|
**(self.get_custom_headers() or {}),
|
|
31
31
|
}
|
|
32
32
|
headers["api-subscription-key"] = self.api_subscription_key
|
|
@@ -11,6 +11,7 @@ from ..types.files_download_response import FilesDownloadResponse
|
|
|
11
11
|
from ..types.files_upload_response import FilesUploadResponse
|
|
12
12
|
from ..types.job_status_v_1 import JobStatusV1
|
|
13
13
|
from .raw_client import AsyncRawSpeechToTextJobClient, RawSpeechToTextJobClient
|
|
14
|
+
from .job import AsyncSpeechToTextJob, SpeechToTextJob
|
|
14
15
|
|
|
15
16
|
# this is used as the default value for optional parameters
|
|
16
17
|
OMIT = typing.cast(typing.Any, ...)
|
|
@@ -69,11 +70,15 @@ class SpeechToTextJobClient:
|
|
|
69
70
|
)
|
|
70
71
|
"""
|
|
71
72
|
_response = self._raw_client.initialise(
|
|
72
|
-
job_parameters=job_parameters,
|
|
73
|
+
job_parameters=job_parameters,
|
|
74
|
+
callback=callback,
|
|
75
|
+
request_options=request_options,
|
|
73
76
|
)
|
|
74
77
|
return _response.data
|
|
75
78
|
|
|
76
|
-
def get_status(
|
|
79
|
+
def get_status(
|
|
80
|
+
self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
81
|
+
) -> JobStatusV1:
|
|
77
82
|
"""
|
|
78
83
|
Get the status of a speech to text bulk job V1
|
|
79
84
|
|
|
@@ -140,11 +145,17 @@ class SpeechToTextJobClient:
|
|
|
140
145
|
job_id="job_id",
|
|
141
146
|
)
|
|
142
147
|
"""
|
|
143
|
-
_response = self._raw_client.start(
|
|
148
|
+
_response = self._raw_client.start(
|
|
149
|
+
job_id, ptu_id=ptu_id, request_options=request_options
|
|
150
|
+
)
|
|
144
151
|
return _response.data
|
|
145
152
|
|
|
146
153
|
def get_upload_links(
|
|
147
|
-
self,
|
|
154
|
+
self,
|
|
155
|
+
*,
|
|
156
|
+
job_id: str,
|
|
157
|
+
files: typing.Sequence[str],
|
|
158
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
148
159
|
) -> FilesUploadResponse:
|
|
149
160
|
"""
|
|
150
161
|
Start a speech to text bulk job V1
|
|
@@ -175,11 +186,17 @@ class SpeechToTextJobClient:
|
|
|
175
186
|
files=["files"],
|
|
176
187
|
)
|
|
177
188
|
"""
|
|
178
|
-
_response = self._raw_client.get_upload_links(
|
|
189
|
+
_response = self._raw_client.get_upload_links(
|
|
190
|
+
job_id=job_id, files=files, request_options=request_options
|
|
191
|
+
)
|
|
179
192
|
return _response.data
|
|
180
193
|
|
|
181
194
|
def get_download_links(
|
|
182
|
-
self,
|
|
195
|
+
self,
|
|
196
|
+
*,
|
|
197
|
+
job_id: str,
|
|
198
|
+
files: typing.Sequence[str],
|
|
199
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
183
200
|
) -> FilesDownloadResponse:
|
|
184
201
|
"""
|
|
185
202
|
Start a speech to text bulk job V1
|
|
@@ -210,9 +227,30 @@ class SpeechToTextJobClient:
|
|
|
210
227
|
files=["files"],
|
|
211
228
|
)
|
|
212
229
|
"""
|
|
213
|
-
_response = self._raw_client.get_download_links(
|
|
230
|
+
_response = self._raw_client.get_download_links(
|
|
231
|
+
job_id=job_id, files=files, request_options=request_options
|
|
232
|
+
)
|
|
214
233
|
return _response.data
|
|
215
234
|
|
|
235
|
+
def create_job(
|
|
236
|
+
self,
|
|
237
|
+
job_parameters: SpeechToTextJobParametersParams,
|
|
238
|
+
callback: typing.Optional[BulkJobCallbackParams] = OMIT,
|
|
239
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
240
|
+
) -> SpeechToTextJob:
|
|
241
|
+
response = self.initialise(
|
|
242
|
+
job_parameters=job_parameters,
|
|
243
|
+
callback=callback,
|
|
244
|
+
request_options=request_options,
|
|
245
|
+
)
|
|
246
|
+
return SpeechToTextJob(job_id=response.job_id, client=self)
|
|
247
|
+
|
|
248
|
+
def get_job(self, job_id: str) -> SpeechToTextJob:
|
|
249
|
+
"""
|
|
250
|
+
Return a job handle for an existing Speech-to-Text job.
|
|
251
|
+
"""
|
|
252
|
+
return SpeechToTextJob(job_id=job_id, client=self)
|
|
253
|
+
|
|
216
254
|
|
|
217
255
|
class AsyncSpeechToTextJobClient:
|
|
218
256
|
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
@@ -275,11 +313,15 @@ class AsyncSpeechToTextJobClient:
|
|
|
275
313
|
asyncio.run(main())
|
|
276
314
|
"""
|
|
277
315
|
_response = await self._raw_client.initialise(
|
|
278
|
-
job_parameters=job_parameters,
|
|
316
|
+
job_parameters=job_parameters,
|
|
317
|
+
callback=callback,
|
|
318
|
+
request_options=request_options,
|
|
279
319
|
)
|
|
280
320
|
return _response.data
|
|
281
321
|
|
|
282
|
-
async def get_status(
|
|
322
|
+
async def get_status(
|
|
323
|
+
self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
324
|
+
) -> JobStatusV1:
|
|
283
325
|
"""
|
|
284
326
|
Get the status of a speech to text bulk job V1
|
|
285
327
|
|
|
@@ -315,7 +357,9 @@ class AsyncSpeechToTextJobClient:
|
|
|
315
357
|
|
|
316
358
|
asyncio.run(main())
|
|
317
359
|
"""
|
|
318
|
-
_response = await self._raw_client.get_status(
|
|
360
|
+
_response = await self._raw_client.get_status(
|
|
361
|
+
job_id, request_options=request_options
|
|
362
|
+
)
|
|
319
363
|
return _response.data
|
|
320
364
|
|
|
321
365
|
async def start(
|
|
@@ -362,11 +406,17 @@ class AsyncSpeechToTextJobClient:
|
|
|
362
406
|
|
|
363
407
|
asyncio.run(main())
|
|
364
408
|
"""
|
|
365
|
-
_response = await self._raw_client.start(
|
|
409
|
+
_response = await self._raw_client.start(
|
|
410
|
+
job_id, ptu_id=ptu_id, request_options=request_options
|
|
411
|
+
)
|
|
366
412
|
return _response.data
|
|
367
413
|
|
|
368
414
|
async def get_upload_links(
|
|
369
|
-
self,
|
|
415
|
+
self,
|
|
416
|
+
*,
|
|
417
|
+
job_id: str,
|
|
418
|
+
files: typing.Sequence[str],
|
|
419
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
370
420
|
) -> FilesUploadResponse:
|
|
371
421
|
"""
|
|
372
422
|
Start a speech to text bulk job V1
|
|
@@ -405,11 +455,17 @@ class AsyncSpeechToTextJobClient:
|
|
|
405
455
|
|
|
406
456
|
asyncio.run(main())
|
|
407
457
|
"""
|
|
408
|
-
_response = await self._raw_client.get_upload_links(
|
|
458
|
+
_response = await self._raw_client.get_upload_links(
|
|
459
|
+
job_id=job_id, files=files, request_options=request_options
|
|
460
|
+
)
|
|
409
461
|
return _response.data
|
|
410
462
|
|
|
411
463
|
async def get_download_links(
|
|
412
|
-
self,
|
|
464
|
+
self,
|
|
465
|
+
*,
|
|
466
|
+
job_id: str,
|
|
467
|
+
files: typing.Sequence[str],
|
|
468
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
413
469
|
) -> FilesDownloadResponse:
|
|
414
470
|
"""
|
|
415
471
|
Start a speech to text bulk job V1
|
|
@@ -452,3 +508,22 @@ class AsyncSpeechToTextJobClient:
|
|
|
452
508
|
job_id=job_id, files=files, request_options=request_options
|
|
453
509
|
)
|
|
454
510
|
return _response.data
|
|
511
|
+
|
|
512
|
+
async def create_job(
|
|
513
|
+
self,
|
|
514
|
+
job_parameters: SpeechToTextJobParametersParams,
|
|
515
|
+
callback: typing.Optional[BulkJobCallbackParams] = OMIT,
|
|
516
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
517
|
+
) -> "AsyncSpeechToTextJob":
|
|
518
|
+
response = await self.initialise(
|
|
519
|
+
job_parameters=job_parameters,
|
|
520
|
+
callback=callback,
|
|
521
|
+
request_options=request_options,
|
|
522
|
+
)
|
|
523
|
+
return AsyncSpeechToTextJob(job_id=response.job_id, client=self)
|
|
524
|
+
|
|
525
|
+
async def get_job(self, job_id: str) -> "AsyncSpeechToTextJob":
|
|
526
|
+
"""
|
|
527
|
+
Return a job handle for an existing Speech-to-Text job.
|
|
528
|
+
"""
|
|
529
|
+
return AsyncSpeechToTextJob(job_id=job_id, client=self)
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
import typing
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ..types import JobStatusV1
|
|
8
|
+
|
|
9
|
+
if typing.TYPE_CHECKING:
|
|
10
|
+
from .client import AsyncSpeechToTextJobClient, SpeechToTextJobClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AsyncSpeechToTextJob:
|
|
14
|
+
def __init__(self, job_id: str, client: "AsyncSpeechToTextJobClient"):
|
|
15
|
+
"""
|
|
16
|
+
Initialize the asynchronous speech-to-text job.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
job_id : str
|
|
21
|
+
The unique job identifier returned from a previous job initialization.
|
|
22
|
+
|
|
23
|
+
client : AsyncSpeechToTextJobClient
|
|
24
|
+
The async client instance used to create the job.
|
|
25
|
+
|
|
26
|
+
!!! important
|
|
27
|
+
This must be the **same client instance** that was used to initialize
|
|
28
|
+
the job originally, as it contains the subscription key and configuration
|
|
29
|
+
required to authenticate and manage the job.
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
self._job_id = job_id
|
|
33
|
+
self._client = client
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def job_id(self) -> str:
|
|
37
|
+
"""
|
|
38
|
+
Returns the job ID associated with this job instance.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
str
|
|
43
|
+
"""
|
|
44
|
+
return self._job_id
|
|
45
|
+
|
|
46
|
+
async def upload_files(self, file_paths: typing.Sequence[str]) -> bool:
|
|
47
|
+
"""
|
|
48
|
+
Upload input audio files for the speech-to-text job.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
file_paths : Sequence[str]
|
|
53
|
+
List of full paths to local audio files.
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
bool
|
|
58
|
+
True if all files are uploaded successfully.
|
|
59
|
+
"""
|
|
60
|
+
upload_links = await self._client.get_upload_links(
|
|
61
|
+
job_id=self._job_id,
|
|
62
|
+
files=[os.path.basename(p) for p in file_paths],
|
|
63
|
+
)
|
|
64
|
+
async with httpx.AsyncClient() as session:
|
|
65
|
+
for path in file_paths:
|
|
66
|
+
file_name = os.path.basename(path)
|
|
67
|
+
url = upload_links.upload_urls[file_name].file_url
|
|
68
|
+
with open(path, "rb") as f:
|
|
69
|
+
response = await session.put(
|
|
70
|
+
url,
|
|
71
|
+
content=f.read(),
|
|
72
|
+
headers={
|
|
73
|
+
"x-ms-blob-type": "BlockBlob",
|
|
74
|
+
"Content-Type": "audio/wav",
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
if response.status_code != 201:
|
|
78
|
+
raise RuntimeError(
|
|
79
|
+
f"Upload failed for {file_name}: {response.status_code}"
|
|
80
|
+
)
|
|
81
|
+
return True
|
|
82
|
+
|
|
83
|
+
async def wait_until_complete(
|
|
84
|
+
self, poll_interval: int = 5, timeout: int = 600
|
|
85
|
+
) -> JobStatusV1:
|
|
86
|
+
"""
|
|
87
|
+
Polls job status until it completes or fails.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
poll_interval : int, optional
|
|
92
|
+
Time in seconds between polling attempts (default is 5).
|
|
93
|
+
|
|
94
|
+
timeout : int, optional
|
|
95
|
+
Maximum time to wait for completion in seconds (default is 600).
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
JobStatusV1
|
|
100
|
+
Final job status.
|
|
101
|
+
|
|
102
|
+
Raises
|
|
103
|
+
------
|
|
104
|
+
TimeoutError
|
|
105
|
+
If the job does not complete within the given timeout.
|
|
106
|
+
"""
|
|
107
|
+
start = asyncio.get_event_loop().time()
|
|
108
|
+
while True:
|
|
109
|
+
status = await self.get_status()
|
|
110
|
+
state = status.job_state.lower()
|
|
111
|
+
if state in {"completed", "failed"}:
|
|
112
|
+
return status
|
|
113
|
+
if asyncio.get_event_loop().time() - start > timeout:
|
|
114
|
+
raise TimeoutError(
|
|
115
|
+
f"Job {self._job_id} did not complete within {timeout} seconds."
|
|
116
|
+
)
|
|
117
|
+
await asyncio.sleep(poll_interval)
|
|
118
|
+
|
|
119
|
+
async def get_output_mappings(self) -> typing.List[typing.Dict[str, str]]:
|
|
120
|
+
"""
|
|
121
|
+
Get the mapping of input files to their corresponding output files.
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
List[Dict[str, str]]
|
|
126
|
+
List of mappings with keys 'input_file' and 'output_file'.
|
|
127
|
+
"""
|
|
128
|
+
job_status = await self.get_status()
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
"input_file": detail.inputs[0].file_name,
|
|
132
|
+
"output_file": detail.outputs[0].file_name,
|
|
133
|
+
}
|
|
134
|
+
for detail in (job_status.job_details or [])
|
|
135
|
+
if detail.inputs and detail.outputs
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
async def download_outputs(self, output_dir: str) -> bool:
|
|
139
|
+
"""
|
|
140
|
+
Download output files to the specified directory.
|
|
141
|
+
|
|
142
|
+
Parameters
|
|
143
|
+
----------
|
|
144
|
+
output_dir : str
|
|
145
|
+
Local directory where outputs will be saved.
|
|
146
|
+
|
|
147
|
+
Returns
|
|
148
|
+
-------
|
|
149
|
+
bool
|
|
150
|
+
True if all files downloaded successfully.
|
|
151
|
+
|
|
152
|
+
Raises
|
|
153
|
+
------
|
|
154
|
+
RuntimeError
|
|
155
|
+
If a file fails to download.
|
|
156
|
+
"""
|
|
157
|
+
mappings = await self.get_output_mappings()
|
|
158
|
+
file_names = [m["output_file"] for m in mappings]
|
|
159
|
+
download_links = await self._client.get_download_links(
|
|
160
|
+
job_id=self._job_id, files=file_names
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
164
|
+
async with httpx.AsyncClient() as session:
|
|
165
|
+
for m in mappings:
|
|
166
|
+
url = download_links.download_urls[m["output_file"]].file_url
|
|
167
|
+
response = await session.get(url)
|
|
168
|
+
if response.status_code != 200:
|
|
169
|
+
raise RuntimeError(
|
|
170
|
+
f"Download failed for {m['output_file']}: {response.status_code}"
|
|
171
|
+
)
|
|
172
|
+
output_path = os.path.join(output_dir, f"{m['input_file']}.json")
|
|
173
|
+
with open(output_path, "wb") as f:
|
|
174
|
+
f.write(response.content)
|
|
175
|
+
return True
|
|
176
|
+
|
|
177
|
+
async def get_status(self) -> JobStatusV1:
|
|
178
|
+
"""
|
|
179
|
+
Retrieve the current status of the job.
|
|
180
|
+
|
|
181
|
+
Returns
|
|
182
|
+
-------
|
|
183
|
+
JobStatusV1
|
|
184
|
+
"""
|
|
185
|
+
return await self._client.get_status(self._job_id)
|
|
186
|
+
|
|
187
|
+
async def start(self) -> JobStatusV1:
|
|
188
|
+
"""
|
|
189
|
+
Start the speech-to-text job processing.
|
|
190
|
+
|
|
191
|
+
Returns
|
|
192
|
+
-------
|
|
193
|
+
JobStatusV1
|
|
194
|
+
"""
|
|
195
|
+
return await self._client.start(job_id=self._job_id)
|
|
196
|
+
|
|
197
|
+
async def exists(self) -> bool:
|
|
198
|
+
"""
|
|
199
|
+
Check if the job exists in the system.
|
|
200
|
+
|
|
201
|
+
Returns
|
|
202
|
+
-------
|
|
203
|
+
bool
|
|
204
|
+
"""
|
|
205
|
+
try:
|
|
206
|
+
await self.get_status()
|
|
207
|
+
return True
|
|
208
|
+
except httpx.HTTPStatusError:
|
|
209
|
+
return False
|
|
210
|
+
|
|
211
|
+
async def is_complete(self) -> bool:
|
|
212
|
+
"""
|
|
213
|
+
Check if the job is either completed or failed.
|
|
214
|
+
|
|
215
|
+
Returns
|
|
216
|
+
-------
|
|
217
|
+
bool
|
|
218
|
+
"""
|
|
219
|
+
state = (await self.get_status()).job_state.lower()
|
|
220
|
+
return state in {"completed", "failed"}
|
|
221
|
+
|
|
222
|
+
async def is_successful(self) -> bool:
|
|
223
|
+
"""
|
|
224
|
+
Check if the job completed successfully.
|
|
225
|
+
|
|
226
|
+
Returns
|
|
227
|
+
-------
|
|
228
|
+
bool
|
|
229
|
+
"""
|
|
230
|
+
return (await self.get_status()).job_state.lower() == "completed"
|
|
231
|
+
|
|
232
|
+
async def is_failed(self) -> bool:
|
|
233
|
+
"""
|
|
234
|
+
Check if the job has failed.
|
|
235
|
+
|
|
236
|
+
Returns
|
|
237
|
+
-------
|
|
238
|
+
bool
|
|
239
|
+
"""
|
|
240
|
+
return (await self.get_status()).job_state.lower() == "failed"
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class SpeechToTextJob:
|
|
244
|
+
def __init__(self, job_id: str, client: "SpeechToTextJobClient"):
|
|
245
|
+
"""
|
|
246
|
+
Initialize the synchronous speech-to-text job.
|
|
247
|
+
|
|
248
|
+
Parameters
|
|
249
|
+
----------
|
|
250
|
+
job_id : str
|
|
251
|
+
The unique job identifier returned from a previous job initialization.
|
|
252
|
+
|
|
253
|
+
client : SpeechToTextJobClient
|
|
254
|
+
The client instance used to create the job.
|
|
255
|
+
|
|
256
|
+
!!! important
|
|
257
|
+
This must be the **same client instance** that was used to initialize
|
|
258
|
+
the job originally, as it contains the subscription key and configuration
|
|
259
|
+
required to authenticate and manage the job.
|
|
260
|
+
|
|
261
|
+
"""
|
|
262
|
+
self._job_id = job_id
|
|
263
|
+
self._client = client
|
|
264
|
+
|
|
265
|
+
@property
|
|
266
|
+
def job_id(self) -> str:
|
|
267
|
+
"""
|
|
268
|
+
Returns the job ID associated with this job instance.
|
|
269
|
+
|
|
270
|
+
Returns
|
|
271
|
+
-------
|
|
272
|
+
str
|
|
273
|
+
"""
|
|
274
|
+
return self._job_id
|
|
275
|
+
|
|
276
|
+
def upload_files(self, file_paths: typing.Sequence[str]) -> bool:
|
|
277
|
+
"""
|
|
278
|
+
Upload input audio files for the speech-to-text job.
|
|
279
|
+
|
|
280
|
+
Parameters
|
|
281
|
+
----------
|
|
282
|
+
file_paths : Sequence[str]
|
|
283
|
+
List of full paths to local audio files.
|
|
284
|
+
|
|
285
|
+
Returns
|
|
286
|
+
-------
|
|
287
|
+
bool
|
|
288
|
+
True if all files are uploaded successfully.
|
|
289
|
+
"""
|
|
290
|
+
upload_links = self._client.get_upload_links(
|
|
291
|
+
job_id=self._job_id, files=[os.path.basename(p) for p in file_paths]
|
|
292
|
+
)
|
|
293
|
+
with httpx.Client() as client:
|
|
294
|
+
for path in file_paths:
|
|
295
|
+
file_name = os.path.basename(path)
|
|
296
|
+
url = upload_links.upload_urls[file_name].file_url
|
|
297
|
+
with open(path, "rb") as f:
|
|
298
|
+
response = client.put(
|
|
299
|
+
url,
|
|
300
|
+
content=f,
|
|
301
|
+
headers={
|
|
302
|
+
"x-ms-blob-type": "BlockBlob",
|
|
303
|
+
"Content-Type": "audio/wav",
|
|
304
|
+
},
|
|
305
|
+
)
|
|
306
|
+
if response.status_code != 201:
|
|
307
|
+
raise RuntimeError(
|
|
308
|
+
f"Upload failed for {file_name}: {response.status_code}"
|
|
309
|
+
)
|
|
310
|
+
return True
|
|
311
|
+
|
|
312
|
+
def wait_until_complete(
|
|
313
|
+
self, poll_interval: int = 5, timeout: int = 600
|
|
314
|
+
) -> JobStatusV1:
|
|
315
|
+
"""
|
|
316
|
+
Polls job status until it completes or fails.
|
|
317
|
+
|
|
318
|
+
Parameters
|
|
319
|
+
----------
|
|
320
|
+
poll_interval : int, optional
|
|
321
|
+
Time in seconds between polling attempts (default is 5).
|
|
322
|
+
|
|
323
|
+
timeout : int, optional
|
|
324
|
+
Maximum time to wait for completion in seconds (default is 600).
|
|
325
|
+
|
|
326
|
+
Returns
|
|
327
|
+
-------
|
|
328
|
+
JobStatusV1
|
|
329
|
+
Final job status.
|
|
330
|
+
|
|
331
|
+
Raises
|
|
332
|
+
------
|
|
333
|
+
TimeoutError
|
|
334
|
+
If the job does not complete within the given timeout.
|
|
335
|
+
"""
|
|
336
|
+
start = time.monotonic()
|
|
337
|
+
while True:
|
|
338
|
+
status = self.get_status()
|
|
339
|
+
state = status.job_state.lower()
|
|
340
|
+
if state in {"completed", "failed"}:
|
|
341
|
+
return status
|
|
342
|
+
if time.monotonic() - start > timeout:
|
|
343
|
+
raise TimeoutError(
|
|
344
|
+
f"Job {self._job_id} did not complete within {timeout} seconds."
|
|
345
|
+
)
|
|
346
|
+
time.sleep(poll_interval)
|
|
347
|
+
|
|
348
|
+
def get_output_mappings(self) -> typing.List[typing.Dict[str, str]]:
|
|
349
|
+
"""
|
|
350
|
+
Get the mapping of input files to their corresponding output files.
|
|
351
|
+
|
|
352
|
+
Returns
|
|
353
|
+
-------
|
|
354
|
+
List[Dict[str, str]]
|
|
355
|
+
List of mappings with keys 'input_file' and 'output_file'.
|
|
356
|
+
"""
|
|
357
|
+
job_status = self.get_status()
|
|
358
|
+
return [
|
|
359
|
+
{
|
|
360
|
+
"input_file": detail.inputs[0].file_name,
|
|
361
|
+
"output_file": detail.outputs[0].file_name,
|
|
362
|
+
}
|
|
363
|
+
for detail in (job_status.job_details or [])
|
|
364
|
+
if detail.inputs and detail.outputs
|
|
365
|
+
]
|
|
366
|
+
|
|
367
|
+
def download_outputs(self, output_dir: str) -> bool:
|
|
368
|
+
"""
|
|
369
|
+
Download output files to the specified directory.
|
|
370
|
+
|
|
371
|
+
Parameters
|
|
372
|
+
----------
|
|
373
|
+
output_dir : str
|
|
374
|
+
Local directory where outputs will be saved.
|
|
375
|
+
|
|
376
|
+
Returns
|
|
377
|
+
-------
|
|
378
|
+
bool
|
|
379
|
+
True if all files downloaded successfully.
|
|
380
|
+
|
|
381
|
+
Raises
|
|
382
|
+
------
|
|
383
|
+
RuntimeError
|
|
384
|
+
If a file fails to download.
|
|
385
|
+
"""
|
|
386
|
+
mappings = self.get_output_mappings()
|
|
387
|
+
file_names = [m["output_file"] for m in mappings]
|
|
388
|
+
download_links = self._client.get_download_links(
|
|
389
|
+
job_id=self._job_id, files=file_names
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
393
|
+
with httpx.Client() as client:
|
|
394
|
+
for m in mappings:
|
|
395
|
+
url = download_links.download_urls[m["output_file"]].file_url
|
|
396
|
+
response = client.get(url)
|
|
397
|
+
if response.status_code != 200:
|
|
398
|
+
raise RuntimeError(
|
|
399
|
+
f"Download failed for {m['output_file']}: {response.status_code}"
|
|
400
|
+
)
|
|
401
|
+
output_path = os.path.join(output_dir, f"{m['input_file']}.json")
|
|
402
|
+
with open(output_path, "wb") as f:
|
|
403
|
+
f.write(response.content)
|
|
404
|
+
return True
|
|
405
|
+
|
|
406
|
+
def get_status(self) -> JobStatusV1:
|
|
407
|
+
"""
|
|
408
|
+
Retrieve the current status of the job.
|
|
409
|
+
|
|
410
|
+
Returns
|
|
411
|
+
-------
|
|
412
|
+
JobStatusV1
|
|
413
|
+
"""
|
|
414
|
+
return self._client.get_status(self._job_id)
|
|
415
|
+
|
|
416
|
+
def start(self) -> JobStatusV1:
|
|
417
|
+
"""
|
|
418
|
+
Start the speech-to-text job processing.
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
JobStatusV1
|
|
423
|
+
"""
|
|
424
|
+
return self._client.start(job_id=self._job_id)
|
|
425
|
+
|
|
426
|
+
def exists(self) -> bool:
|
|
427
|
+
"""
|
|
428
|
+
Check if the job exists in the system.
|
|
429
|
+
|
|
430
|
+
Returns
|
|
431
|
+
-------
|
|
432
|
+
bool
|
|
433
|
+
"""
|
|
434
|
+
try:
|
|
435
|
+
self.get_status()
|
|
436
|
+
return True
|
|
437
|
+
except httpx.HTTPStatusError:
|
|
438
|
+
return False
|
|
439
|
+
|
|
440
|
+
def is_complete(self) -> bool:
|
|
441
|
+
"""
|
|
442
|
+
Check if the job is either completed or failed.
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
bool
|
|
447
|
+
"""
|
|
448
|
+
return self.get_status().job_state.lower() in {"completed", "failed"}
|
|
449
|
+
|
|
450
|
+
def is_successful(self) -> bool:
|
|
451
|
+
"""
|
|
452
|
+
Check if the job completed successfully.
|
|
453
|
+
|
|
454
|
+
Returns
|
|
455
|
+
-------
|
|
456
|
+
bool
|
|
457
|
+
"""
|
|
458
|
+
return self.get_status().job_state.lower() == "completed"
|
|
459
|
+
|
|
460
|
+
def is_failed(self) -> bool:
|
|
461
|
+
"""
|
|
462
|
+
Check if the job has failed.
|
|
463
|
+
|
|
464
|
+
Returns
|
|
465
|
+
-------
|
|
466
|
+
bool
|
|
467
|
+
"""
|
|
468
|
+
return self.get_status().job_state.lower() == "failed"
|
|
@@ -5,7 +5,7 @@ sarvamai/chat/raw_client.py,sha256=A2kRuZcVWlJhyYCD7YKgqNkZEp3cYa1731KhRkhirU0,1
|
|
|
5
5
|
sarvamai/client.py,sha256=5YC2fxVENOxQXoY-t3n8qZ0aQ9UasDjFRzBZw8ce9OQ,7861
|
|
6
6
|
sarvamai/core/__init__.py,sha256=YE2CtXeASe1RAbaI39twKWYKCuT4tW5is9HWHhJjR_g,1653
|
|
7
7
|
sarvamai/core/api_error.py,sha256=44vPoTyWN59gonCIZMdzw7M1uspygiLnr3GNFOoVL2Q,614
|
|
8
|
-
sarvamai/core/client_wrapper.py,sha256=
|
|
8
|
+
sarvamai/core/client_wrapper.py,sha256=jXSnpwjhgnSazz2XKOdWnRWGQVqhKTopyF7ZXCoL2jo,2570
|
|
9
9
|
sarvamai/core/datetime_utils.py,sha256=nBys2IsYrhPdszxGKCNRPSOCwa-5DWOHG95FB8G9PKo,1047
|
|
10
10
|
sarvamai/core/events.py,sha256=j7VWXgMpOsjCXdzY22wIhI7Q-v5InZ4WchRzA88x_Sk,856
|
|
11
11
|
sarvamai/core/file.py,sha256=d4NNbX8XvXP32z8KpK2Xovv33nFfruIrpz0QWxlgpZk,2663
|
|
@@ -86,7 +86,8 @@ sarvamai/speech_to_text/__init__.py,sha256=_VhToAyIt_5axN6CLJwtxg3-CO7THa_23pbUz
|
|
|
86
86
|
sarvamai/speech_to_text/client.py,sha256=lp2G2fI9SUbeOBBE1S5tjcp-Xb8wIhAuVadLKwXveh8,11003
|
|
87
87
|
sarvamai/speech_to_text/raw_client.py,sha256=A_56vEVeJdyttVJRiFxTMJ4n-s4l_PS8rI1DiLZlOmc,25331
|
|
88
88
|
sarvamai/speech_to_text_job/__init__.py,sha256=_VhToAyIt_5axN6CLJwtxg3-CO7THa_23pbUzqhXJa4,85
|
|
89
|
-
sarvamai/speech_to_text_job/client.py,sha256=
|
|
89
|
+
sarvamai/speech_to_text_job/client.py,sha256=DJhCmYQ1EYbmrhLalsqEv_3rZYJWTsT-W2wQrU6IaXU,14275
|
|
90
|
+
sarvamai/speech_to_text_job/job.py,sha256=6h9hrpsKX21ql-umxEThtx8gU38cZj25WuBY9iBdnbI,13744
|
|
90
91
|
sarvamai/speech_to_text_job/raw_client.py,sha256=v14drcQLAmpqozRUNKmw1F9j3omieMPC8R88Th1BID8,48055
|
|
91
92
|
sarvamai/speech_to_text_streaming/__init__.py,sha256=q7QygMmZCHJ-4FMhhL_6XNV_dsqlIFRCO1iSxoyxaaY,437
|
|
92
93
|
sarvamai/speech_to_text_streaming/client.py,sha256=WdkzZxKMdnQ2hHv9hzJlfSNggRJLKFljRiC7695Jcog,8224
|
|
@@ -202,6 +203,6 @@ sarvamai/types/transliterate_mode.py,sha256=1jSEMlGcoLkWuk12TgoOpSgwifa4rThGKZ1h
|
|
|
202
203
|
sarvamai/types/transliterate_source_language.py,sha256=bSY9wJszF0sg-Cgg6F-YcWC8ly1mIlj9rqa15-jBtx8,283
|
|
203
204
|
sarvamai/types/transliteration_response.py,sha256=yt-lzTbDeJ_ZL4I8kQa6oESxA9ebeJJY7LfFHpdEsmM,815
|
|
204
205
|
sarvamai/version.py,sha256=Qkp3Ee9YH-O9RTix90e0i7iNrFAGN-QDt2AFwGA4n8k,75
|
|
205
|
-
sarvamai-0.1.
|
|
206
|
-
sarvamai-0.1.
|
|
207
|
-
sarvamai-0.1.
|
|
206
|
+
sarvamai-0.1.11a1.dist-info/METADATA,sha256=dfnuJp6su4GLfw335hVroaiLC44B37vrSjV6-0aVnfY,26753
|
|
207
|
+
sarvamai-0.1.11a1.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
208
|
+
sarvamai-0.1.11a1.dist-info/RECORD,,
|
|
File without changes
|