sarvamai 0.1.5a5__py3-none-any.whl → 0.1.5a6__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 +1 -45
- sarvamai/chat/__init__.py +0 -2
- sarvamai/chat/client.py +10 -9
- sarvamai/chat/raw_client.py +37 -48
- sarvamai/client.py +31 -13
- sarvamai/core/__init__.py +0 -5
- sarvamai/core/api_error.py +5 -13
- sarvamai/core/client_wrapper.py +20 -17
- sarvamai/core/http_client.py +24 -70
- sarvamai/core/http_response.py +11 -19
- sarvamai/core/pydantic_utilities.py +108 -69
- sarvamai/environment.py +3 -10
- sarvamai/errors/__init__.py +0 -2
- sarvamai/errors/bad_request_error.py +3 -4
- sarvamai/errors/forbidden_error.py +3 -4
- sarvamai/errors/internal_server_error.py +3 -4
- sarvamai/errors/service_unavailable_error.py +2 -4
- sarvamai/errors/too_many_requests_error.py +3 -4
- sarvamai/errors/unprocessable_entity_error.py +3 -4
- sarvamai/requests/__init__.py +0 -18
- sarvamai/requests/chat_completion_request_message.py +1 -3
- sarvamai/requests/create_chat_completion_response.py +2 -2
- sarvamai/requests/diarized_transcript.py +1 -2
- sarvamai/requests/error_details.py +1 -0
- sarvamai/requests/language_identification_response.py +1 -0
- sarvamai/requests/speech_to_text_response.py +2 -1
- sarvamai/requests/speech_to_text_translate_response.py +1 -0
- sarvamai/requests/text_to_speech_response.py +2 -2
- sarvamai/requests/timestamps_model.py +1 -2
- sarvamai/requests/translation_response.py +1 -0
- sarvamai/requests/transliteration_response.py +1 -0
- sarvamai/speech_to_text/__init__.py +0 -2
- sarvamai/speech_to_text/client.py +14 -13
- sarvamai/speech_to_text/raw_client.py +68 -99
- sarvamai/text/__init__.py +0 -2
- sarvamai/text/client.py +25 -24
- sarvamai/text/raw_client.py +91 -126
- sarvamai/text_to_speech/__init__.py +0 -2
- sarvamai/text_to_speech/client.py +11 -10
- sarvamai/text_to_speech/raw_client.py +38 -49
- sarvamai/types/__init__.py +0 -24
- sarvamai/types/chat_completion_request_assistant_message.py +3 -3
- sarvamai/types/chat_completion_request_message.py +2 -3
- 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_details.py +3 -3
- sarvamai/types/error_message.py +4 -4
- sarvamai/types/language_identification_response.py +2 -2
- sarvamai/types/speech_to_text_response.py +3 -3
- 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/translation_response.py +2 -2
- sarvamai/types/transliteration_response.py +2 -2
- sarvamai-0.1.5a6.dist-info/METADATA +174 -0
- sarvamai-0.1.5a6.dist-info/RECORD +106 -0
- sarvamai/core/events.py +0 -30
- sarvamai/core/force_multipart.py +0 -16
- sarvamai/requests/audio_data.py +0 -21
- sarvamai/requests/audio_message.py +0 -8
- sarvamai/requests/error_data.py +0 -15
- sarvamai/requests/events_data.py +0 -17
- sarvamai/requests/speech_to_text_streaming_response.py +0 -10
- sarvamai/requests/speech_to_text_streaming_response_data.py +0 -9
- sarvamai/requests/transcription_data.py +0 -35
- sarvamai/requests/transcription_metrics.py +0 -15
- sarvamai/speech_to_text_streaming/__init__.py +0 -7
- sarvamai/speech_to_text_streaming/client.py +0 -189
- sarvamai/speech_to_text_streaming/raw_client.py +0 -166
- sarvamai/speech_to_text_streaming/socket_client.py +0 -129
- sarvamai/speech_to_text_streaming/types/__init__.py +0 -8
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_language_code.py +0 -8
- sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_model.py +0 -5
- sarvamai/types/audio_data.py +0 -33
- sarvamai/types/audio_data_encoding.py +0 -5
- sarvamai/types/audio_message.py +0 -20
- sarvamai/types/error_data.py +0 -27
- sarvamai/types/events_data.py +0 -28
- sarvamai/types/format.py +0 -5
- sarvamai/types/speech_to_text_streaming_response.py +0 -22
- sarvamai/types/speech_to_text_streaming_response_data.py +0 -9
- sarvamai/types/speech_to_text_streaming_response_type.py +0 -5
- sarvamai/types/transcription_data.py +0 -45
- sarvamai/types/transcription_metrics.py +0 -27
- sarvamai-0.1.5a5.dist-info/METADATA +0 -28
- sarvamai-0.1.5a5.dist-info/RECORD +0 -134
- {sarvamai-0.1.5a5.dist-info → sarvamai-0.1.5a6.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sarvamai
|
|
3
|
+
Version: 0.1.5a6
|
|
4
|
+
Summary:
|
|
5
|
+
Requires-Python: >=3.8,<4.0
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: Operating System :: MacOS
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Operating System :: POSIX
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Dist: httpx (>=0.21.2)
|
|
22
|
+
Requires-Dist: pydantic (>=1.9.2)
|
|
23
|
+
Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
|
|
24
|
+
Requires-Dist: typing_extensions (>=4.0.0)
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Sarvam Python Library
|
|
28
|
+
|
|
29
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fsarvamai%2Fsarvam-python-sdk)
|
|
30
|
+
[](https://pypi.python.org/pypi/sarvamai)
|
|
31
|
+
|
|
32
|
+
The Sarvam Python library provides convenient access to the Sarvam API from Python.
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
API reference documentation is available [here](https://www.sarvam.ai/).
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pip install sarvamai
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Reference
|
|
45
|
+
|
|
46
|
+
A full reference for this library is available [here](https://github.com/sarvamai/sarvam-python-sdk/blob/HEAD/./reference.md).
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
Instantiate and use the client with the following:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from sarvamai import SarvamAI
|
|
54
|
+
|
|
55
|
+
client = SarvamAI(
|
|
56
|
+
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
|
|
57
|
+
)
|
|
58
|
+
client.text.translate(
|
|
59
|
+
input="input",
|
|
60
|
+
source_language_code="auto",
|
|
61
|
+
target_language_code="bn-IN",
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Async Client
|
|
66
|
+
|
|
67
|
+
The SDK also exports an `async` client so that you can make non-blocking calls to our API.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
|
|
72
|
+
from sarvamai import AsyncSarvamAI
|
|
73
|
+
|
|
74
|
+
client = AsyncSarvamAI(
|
|
75
|
+
api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
async def main() -> None:
|
|
80
|
+
await client.text.translate(
|
|
81
|
+
input="input",
|
|
82
|
+
source_language_code="auto",
|
|
83
|
+
target_language_code="bn-IN",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
asyncio.run(main())
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Exception Handling
|
|
91
|
+
|
|
92
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
|
93
|
+
will be thrown.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from sarvamai.core.api_error import ApiError
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
client.text.translate(...)
|
|
100
|
+
except ApiError as e:
|
|
101
|
+
print(e.status_code)
|
|
102
|
+
print(e.body)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Advanced
|
|
106
|
+
|
|
107
|
+
### Retries
|
|
108
|
+
|
|
109
|
+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
110
|
+
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
|
|
111
|
+
retry limit (default: 2).
|
|
112
|
+
|
|
113
|
+
A request is deemed retryable when any of the following HTTP status codes is returned:
|
|
114
|
+
|
|
115
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
116
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
117
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
|
|
118
|
+
|
|
119
|
+
Use the `max_retries` request option to configure this behavior.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
client.text.translate(..., request_options={
|
|
123
|
+
"max_retries": 1
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Timeouts
|
|
128
|
+
|
|
129
|
+
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
|
|
133
|
+
from sarvamai import SarvamAI
|
|
134
|
+
|
|
135
|
+
client = SarvamAI(
|
|
136
|
+
...,
|
|
137
|
+
timeout=20.0,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# Override timeout for a specific method
|
|
142
|
+
client.text.translate(..., request_options={
|
|
143
|
+
"timeout_in_seconds": 1
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Custom Client
|
|
148
|
+
|
|
149
|
+
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
|
|
150
|
+
and transports.
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import httpx
|
|
154
|
+
from sarvamai import SarvamAI
|
|
155
|
+
|
|
156
|
+
client = SarvamAI(
|
|
157
|
+
...,
|
|
158
|
+
httpx_client=httpx.Client(
|
|
159
|
+
proxies="http://my.test.proxy.example.com",
|
|
160
|
+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
168
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
169
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
170
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
171
|
+
an issue first to discuss with us!
|
|
172
|
+
|
|
173
|
+
On the other hand, contributions to the README are always very welcome!
|
|
174
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
sarvamai/__init__.py,sha256=7mG0Weo4kgxNnj4TNGSC7JDJ6FFzGXN3brR9EuJCUCg,5059
|
|
2
|
+
sarvamai/chat/__init__.py,sha256=FTtvy8EDg9nNNg9WCatVgKTRYV8-_v1roeGPAKoa_pw,65
|
|
3
|
+
sarvamai/chat/client.py,sha256=j3r7Y3wa_jP6wuzuau4RA1E39ica1ni1hvH_1OZOm4k,11073
|
|
4
|
+
sarvamai/chat/raw_client.py,sha256=CVTJknNXVUejPYvBMLNS3ExeBwPsuNKVGWrH90bHRgg,17095
|
|
5
|
+
sarvamai/client.py,sha256=NrpjDx6AusBR2AfUWUrFSfteIlYkUhv5ahjdlCBNPeM,6936
|
|
6
|
+
sarvamai/core/__init__.py,sha256=JZDozMOUlhvOLnOO6kGBxye5Ctfg_KDOjeUTSUoMmV8,1542
|
|
7
|
+
sarvamai/core/api_error.py,sha256=RE8LELok2QCjABadECTvtDp7qejA1VmINCh6TbqPwSE,426
|
|
8
|
+
sarvamai/core/client_wrapper.py,sha256=NLDY0Q51uWMEkfj5GBi5yjwf9oRjaSaLwxU_-KwecV4,2074
|
|
9
|
+
sarvamai/core/datetime_utils.py,sha256=nBys2IsYrhPdszxGKCNRPSOCwa-5DWOHG95FB8G9PKo,1047
|
|
10
|
+
sarvamai/core/file.py,sha256=d4NNbX8XvXP32z8KpK2Xovv33nFfruIrpz0QWxlgpZk,2663
|
|
11
|
+
sarvamai/core/http_client.py,sha256=cKs2w0ybDBk1wHQf-fTALm_MmvaMe3cZKcYJxqmCxkE,19539
|
|
12
|
+
sarvamai/core/http_response.py,sha256=Argerx6pFZdCpe637AT3EejZw5zlMGgsshZq6rb7krQ,1005
|
|
13
|
+
sarvamai/core/jsonable_encoder.py,sha256=hGgcEEeX11sqxxsll7h15pO3pTNVxk_n79Kcn0laoWA,3655
|
|
14
|
+
sarvamai/core/pydantic_utilities.py,sha256=Q2ZdeXKMwntaR9k2PJoMEhtHPlSgnG95c1v3iIrCFyA,11971
|
|
15
|
+
sarvamai/core/query_encoder.py,sha256=ekulqNd0j8TgD7ox-Qbz7liqX8-KP9blvT9DsRCenYM,2144
|
|
16
|
+
sarvamai/core/remove_none_from_dict.py,sha256=EU9SGgYidWq7SexuJbNs4-PZ-5Bl3Vppd864mS6vQZw,342
|
|
17
|
+
sarvamai/core/request_options.py,sha256=h0QUNCFVdCW_7GclVySCAY2w4NhtXVBUCmHgmzaxpcg,1681
|
|
18
|
+
sarvamai/core/serialization.py,sha256=ECL3bvv_0i7U4uvPidZCNel--MUbA0iq0aGcNKi3kws,9818
|
|
19
|
+
sarvamai/environment.py,sha256=86s94KkJUHmMqmGiehN2SiNYxHoBFgIxCHH41T_BZNs,158
|
|
20
|
+
sarvamai/errors/__init__.py,sha256=Rjcid1bNnxJ95F5ACvzU2L5aYJNuJh4OpRG1JSyj8G0,575
|
|
21
|
+
sarvamai/errors/bad_request_error.py,sha256=_EbO8mWqN9kFZPvIap8qa1lL_EWkRcsZe1HKV9GDWJY,264
|
|
22
|
+
sarvamai/errors/forbidden_error.py,sha256=QO1kKlhClAPES6zsEK7g9pglWnxn3KWaOCAawWOg6Aw,263
|
|
23
|
+
sarvamai/errors/internal_server_error.py,sha256=8USCagXyJJ1MOm9snpcXIUt6eNXvrd_aq7Gfcu1vlOI,268
|
|
24
|
+
sarvamai/errors/service_unavailable_error.py,sha256=kBwNhnOm3Je1t6ZHX-jc_3uimn8P_pHaXBM-s9ICo4A,290
|
|
25
|
+
sarvamai/errors/too_many_requests_error.py,sha256=8nFkKVRqHHehkZZuQaxQtul-jK1vxQxgxZ0RpAjgBzk,269
|
|
26
|
+
sarvamai/errors/unprocessable_entity_error.py,sha256=vd8X3DZR5hSzdWlO3yczFT6aGOvU_3LKp9P-UwSQNr8,273
|
|
27
|
+
sarvamai/play.py,sha256=4fh86zy8g8IPU2O8yPBY7QxXQOivv_nWQvPQsOa1arw,2183
|
|
28
|
+
sarvamai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
+
sarvamai/requests/__init__.py,sha256=Rp8H6sD9mn3ZEwMqe3EPXDHbvpbV_kIxWDQnLzsTeLo,2432
|
|
30
|
+
sarvamai/requests/chat_completion_request_assistant_message.py,sha256=xI6nqqY2t4j56DGEAt2aasDnI7no_mxxCBk_ChxNQjg,247
|
|
31
|
+
sarvamai/requests/chat_completion_request_message.py,sha256=iCVKmu86JB8WagaY32W9LheFHWODYvbw2oUiyA6B98o,734
|
|
32
|
+
sarvamai/requests/chat_completion_request_system_message.py,sha256=ZvjBuyL0oM7Vwd9bR_Yc7yGXUGLHYn9Np9jqEebiMRs,242
|
|
33
|
+
sarvamai/requests/chat_completion_request_user_message.py,sha256=IqYy7K-qF9oQ8AUIvuH06EsLL-Wn6QufPMPpSR-VNGI,238
|
|
34
|
+
sarvamai/requests/chat_completion_response_message.py,sha256=JFazj4zK-nj_wjdvNLDkcfIFxIlqw49Xf_P8o7d70aY,336
|
|
35
|
+
sarvamai/requests/choice.py,sha256=uulX4MZUoThEMcD3a80o_3V5YpnpqN8DfPaNZWVz-1o,867
|
|
36
|
+
sarvamai/requests/completion_usage.py,sha256=LbZV-RxcxKdCAYqhCiaRtSFF3VwMJq71A989Z1rm-I8,428
|
|
37
|
+
sarvamai/requests/create_chat_completion_response.py,sha256=UWDcjiwYfpSaoqdpg7MUX223b8nmVIMR6N9-HMpEnf0,881
|
|
38
|
+
sarvamai/requests/diarized_entry.py,sha256=gbXB4D_r5_Q8gs1arRKjxPeFcYg16dVDLcg2VhxmKQA,462
|
|
39
|
+
sarvamai/requests/diarized_transcript.py,sha256=gEV0sDdR-I2IBGh0RqloHyn6C8hlx-79NLCPl9_vpjk,322
|
|
40
|
+
sarvamai/requests/error_details.py,sha256=FvdXzgSa33MGLiyxXK32NkEiu-Zs4ffSDH_zlthKziU,554
|
|
41
|
+
sarvamai/requests/error_message.py,sha256=-J21pfEJghsms4pNe55O_9qkODNd-BKLMt96AOztYUs,257
|
|
42
|
+
sarvamai/requests/language_identification_response.py,sha256=KrgEPe4BFQrcw6THOEadZGhAi2TrLOLM3pvuU4L7KMQ,1123
|
|
43
|
+
sarvamai/requests/speech_to_text_response.py,sha256=ualIhmOvRkru-uUwAWtMX5UbjxvmoH9TZ2BUhu8QW3Q,1066
|
|
44
|
+
sarvamai/requests/speech_to_text_translate_response.py,sha256=t47712OZg8iJN-JmVLS8wfv11r3FhvFMKk_dpGht9IU,918
|
|
45
|
+
sarvamai/requests/stop_configuration.py,sha256=Xmp8zyUpnN65pH5A7NqefckB8wk53_BBzOUrgRm2gXs,146
|
|
46
|
+
sarvamai/requests/text_to_speech_response.py,sha256=1Ka6uLFqGlr8L_6rhwx_pyVeDWjJf1k0Fa_lSpz3onQ,415
|
|
47
|
+
sarvamai/requests/timestamps_model.py,sha256=eGGwbGERv5Oa9KuGJ0XUTTdn1tvP2QrLTXl0lrcBzis,463
|
|
48
|
+
sarvamai/requests/translation_response.py,sha256=zEL7LhnLIxwAz89NOkjkSDdnR1LaUa80T6lM32co3g8,439
|
|
49
|
+
sarvamai/requests/transliteration_response.py,sha256=9ZYsJ-9MSjyRWatEbpsI69Hx86JVACCZCU3BEvN77M4,451
|
|
50
|
+
sarvamai/speech_to_text/__init__.py,sha256=FTtvy8EDg9nNNg9WCatVgKTRYV8-_v1roeGPAKoa_pw,65
|
|
51
|
+
sarvamai/speech_to_text/client.py,sha256=FnZnTi0XDOnVcD4pxcXmb5brVpU6kOmIM9-CwYyuaWM,11482
|
|
52
|
+
sarvamai/speech_to_text/raw_client.py,sha256=k9J82zyF1oCHqkE_sGZUuxABPs1q6rVdLX3J-yByixE,23674
|
|
53
|
+
sarvamai/text/__init__.py,sha256=FTtvy8EDg9nNNg9WCatVgKTRYV8-_v1roeGPAKoa_pw,65
|
|
54
|
+
sarvamai/text/client.py,sha256=8CMxMZ9mzFsL4Tk4ZNObhLvGhY4NVZE3e0Bw_xNYw6s,30568
|
|
55
|
+
sarvamai/text/raw_client.py,sha256=1ej_A_Au1yybdJFlDsUoW_oUy8RdpbLkUC_pNJPzlXc,46127
|
|
56
|
+
sarvamai/text_to_speech/__init__.py,sha256=FTtvy8EDg9nNNg9WCatVgKTRYV8-_v1roeGPAKoa_pw,65
|
|
57
|
+
sarvamai/text_to_speech/client.py,sha256=1T_P7dpVmZBzUNPbKFGBDPXRwpDV-5zY6KcEOQoLrs8,9215
|
|
58
|
+
sarvamai/text_to_speech/raw_client.py,sha256=VIgGQ8WKQOY9RTAEfboWeCe1zZM1l8wZ3jOUAnYrxxg,14312
|
|
59
|
+
sarvamai/types/__init__.py,sha256=e1Yt8Un0_BDq_y20kLVjAuiylcajGTp2sUJkjzvoCbY,4004
|
|
60
|
+
sarvamai/types/chat_completion_request_assistant_message.py,sha256=EUkQKNCaBvrL2PIOIN9Q4GXIV7uJ6C86k-BreA-83uE,660
|
|
61
|
+
sarvamai/types/chat_completion_request_message.py,sha256=4M8Rkc1kNHfORTNDFrc8wbq8eR37kq5nrsd-wNvL4kw,1673
|
|
62
|
+
sarvamai/types/chat_completion_request_system_message.py,sha256=my0yA0q9xHpZD7mtDhekxizSKxWBb4lKxbaI5nbcE50,655
|
|
63
|
+
sarvamai/types/chat_completion_request_user_message.py,sha256=t_xOnP-Ule6mbs1msgYpfcM9ESZ1OTb7Bk2899LMTMQ,651
|
|
64
|
+
sarvamai/types/chat_completion_response_message.py,sha256=0XzcRWQaC47e6X3bv_08sAMl_lEFBHa94YCHnNsNmA8,780
|
|
65
|
+
sarvamai/types/choice.py,sha256=ORVAl41SDc8W6QGqCkEGW6TruRKo2VchvE07D-tE01w,1280
|
|
66
|
+
sarvamai/types/completion_usage.py,sha256=4x32_8qX4dy84vOBu9i0403rdUMjNCWjh7KNm8HIETM,879
|
|
67
|
+
sarvamai/types/create_chat_completion_response.py,sha256=Sl7O22ZGC-COGTu9qPmXRGnzClMNlQnMXC5__MdhWtk,1321
|
|
68
|
+
sarvamai/types/diarized_entry.py,sha256=7uCr_QTOtVIPxxLQrnM1KXkEWl7WwwGFx2PZ3VjNYdI,932
|
|
69
|
+
sarvamai/types/diarized_transcript.py,sha256=bzd731RIpb5rtPwskrXq2HT6kjCyaErBBHwMRZIaiYk,705
|
|
70
|
+
sarvamai/types/error_code.py,sha256=Ts_zcCTJiKoA1rAK9VaW9SfuQDk-DT3pd6KKwzz2udQ,420
|
|
71
|
+
sarvamai/types/error_details.py,sha256=7rg_YGt9kzmqwKrJQik97S5UFm5XolN5b6fb5qM65tA,971
|
|
72
|
+
sarvamai/types/error_message.py,sha256=gBuy-7XE-mtwAgqBP5YOjupMc0NqRcc2v0-RdvB4EVw,658
|
|
73
|
+
sarvamai/types/finish_reason.py,sha256=PBWtBNkX4FMaODmlUehpF6qLB5uH_zR-Mw3M4uhIB6U,209
|
|
74
|
+
sarvamai/types/language_identification_response.py,sha256=WGDWLFiam79qLKKWayfUHtAKrjsrjdkojDImgybe3I0,1519
|
|
75
|
+
sarvamai/types/numerals_format.py,sha256=xg3lYiHcnzyFwuwRcaIteJLH_Pz6pJ9n9kTlYPEnCBU,165
|
|
76
|
+
sarvamai/types/reasoning_effort.py,sha256=_TBLn3rQgzJAdnKqV2g0PETbrSBZl0fPLfQ5ZE9H4Pc,164
|
|
77
|
+
sarvamai/types/role.py,sha256=3eY01zZQKB8BSD4cFDeVjz-o2qnHJKz1vnToLqbExxs,115
|
|
78
|
+
sarvamai/types/sarvam_model_ids.py,sha256=iYBMglf31KQ1iUZeAMQ-2PP9NDcyHRG7goz7O9VG8qg,124
|
|
79
|
+
sarvamai/types/speech_sample_rate.py,sha256=Hfi79KL2Y1W7OIvvrfWnt7EUvmU5i7bxYvXivrY_aUA,88
|
|
80
|
+
sarvamai/types/speech_to_text_language.py,sha256=cq8FBOX0DfYB3v8jgNteQtHeJcqWqzKWJVyYGwwo_w0,279
|
|
81
|
+
sarvamai/types/speech_to_text_model.py,sha256=cYANeE-1Kjdpju97bLdQa8GuGqMBn0hVK4McFVqUGT0,208
|
|
82
|
+
sarvamai/types/speech_to_text_response.py,sha256=iS6unuJRV2JIfFhMIjQ8w93Va8pk8PD45lJwt8y9icQ,1474
|
|
83
|
+
sarvamai/types/speech_to_text_translate_language.py,sha256=yikNM-roIumVG-eqBWss93wLGudZdLPwd0i3VcXH5zo,263
|
|
84
|
+
sarvamai/types/speech_to_text_translate_model.py,sha256=hxKnhnelhH5Ah8QO5SymTJMnDw_WWAhGDJnutoNk3qw,213
|
|
85
|
+
sarvamai/types/speech_to_text_translate_response.py,sha256=3cxJzEZyVY9WHKEWU_mcqK5e4FWgBuMwS-0GDJx3Wec,1314
|
|
86
|
+
sarvamai/types/spoken_form_numerals_format.py,sha256=soBly93wMkazIcp2GDM0Mf1MjY140Pe24hBlwNoWge0,169
|
|
87
|
+
sarvamai/types/stop_configuration.py,sha256=yA_q4s4BIrbl3FotZpg4ZcyL10C7gVI0s2dqvH32BNw,136
|
|
88
|
+
sarvamai/types/text_to_speech_language.py,sha256=T5-rP93WyJwkdJTmNZuvNkkoVtgU0G25a8R2F3OwRZ4,254
|
|
89
|
+
sarvamai/types/text_to_speech_model.py,sha256=pQT3AA7CgxbwFAHLAsMM0ZIXmtLbellJF-jtP5U7bLc,167
|
|
90
|
+
sarvamai/types/text_to_speech_response.py,sha256=RK5-us44cXSYV3sCSfpWM1Z7qTVf64j0zKwqnqJcA0w,778
|
|
91
|
+
sarvamai/types/text_to_speech_speaker.py,sha256=r-khCl0iD-oZu5Mf9FMoO3FzFKKLTzaUmfi0CySrFok,495
|
|
92
|
+
sarvamai/types/timestamps_model.py,sha256=QobDiQ6g4XMhAWyQMmKBm29nU8w93HJ2N2qsvKo2Te0,888
|
|
93
|
+
sarvamai/types/translate_mode.py,sha256=lLBJyAaawLMH1eCGWTZKuzAA0iCEc2TL_7cpRZzmIac,210
|
|
94
|
+
sarvamai/types/translate_model.py,sha256=4SeSkh-dOcdo9L8vZGgyOvuCmv0kYiZVpHrcJoOcyYQ,174
|
|
95
|
+
sarvamai/types/translate_source_language.py,sha256=0EJYLaLZt5Xu6d8tqlktVnDGhy00RxgXzoJoXKuCiys,578
|
|
96
|
+
sarvamai/types/translate_speaker_gender.py,sha256=MOd3qRMj3YjjmgF6AV1Juqlnm1l55g25mkORIo-zNNU,164
|
|
97
|
+
sarvamai/types/translate_target_language.py,sha256=iJcGMyqoJT1HJKddDldtT2SrIcG01z_O-ElKCfjXkgw,562
|
|
98
|
+
sarvamai/types/translation_response.py,sha256=88efF0zhRJbyGt_ARYH3E9UcsawMr5v-OH0XhGUSu4Q,839
|
|
99
|
+
sarvamai/types/translatiterate_target_language.py,sha256=QFro2kVbqK2Icivgy_TyqN3e3Ll4nBTTuwPyN64vKRU,263
|
|
100
|
+
sarvamai/types/transliterate_mode.py,sha256=1jSEMlGcoLkWuk12TgoOpSgwifa4rThGKZ1hLEjW8sI,191
|
|
101
|
+
sarvamai/types/transliterate_source_language.py,sha256=bSY9wJszF0sg-Cgg6F-YcWC8ly1mIlj9rqa15-jBtx8,283
|
|
102
|
+
sarvamai/types/transliteration_response.py,sha256=RZcsRP73Si24t4LF8MZCw_qZyVbX3gvMz88O41oMk8s,851
|
|
103
|
+
sarvamai/version.py,sha256=Qkp3Ee9YH-O9RTix90e0i7iNrFAGN-QDt2AFwGA4n8k,75
|
|
104
|
+
sarvamai-0.1.5a6.dist-info/METADATA,sha256=BuC2tTr8sFq3I43LbtlwPuqUY-m-xvBgLQ693gEo27Q,4792
|
|
105
|
+
sarvamai-0.1.5a6.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
106
|
+
sarvamai-0.1.5a6.dist-info/RECORD,,
|
sarvamai/core/events.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing
|
|
4
|
-
from enum import Enum
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class EventType(str, Enum):
|
|
8
|
-
OPEN = "open"
|
|
9
|
-
MESSAGE = "message"
|
|
10
|
-
ERROR = "error"
|
|
11
|
-
CLOSE = "close"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class EventEmitterMixin:
|
|
15
|
-
"""
|
|
16
|
-
Simple mixin for registering and emitting events.
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
def __init__(self) -> None:
|
|
20
|
-
self._callbacks: typing.Dict[EventType, typing.List[typing.Callable]] = {}
|
|
21
|
-
|
|
22
|
-
def on(self, event_name: EventType, callback: typing.Callable[[typing.Any], None]) -> None:
|
|
23
|
-
if event_name not in self._callbacks:
|
|
24
|
-
self._callbacks[event_name] = []
|
|
25
|
-
self._callbacks[event_name].append(callback)
|
|
26
|
-
|
|
27
|
-
def _emit(self, event_name: EventType, data: typing.Any) -> None:
|
|
28
|
-
if event_name in self._callbacks:
|
|
29
|
-
for cb in self._callbacks[event_name]:
|
|
30
|
-
cb(data)
|
sarvamai/core/force_multipart.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class ForceMultipartDict(dict):
|
|
5
|
-
"""
|
|
6
|
-
A dictionary subclass that always evaluates to True in boolean contexts.
|
|
7
|
-
|
|
8
|
-
This is used to force multipart/form-data encoding in HTTP requests even when
|
|
9
|
-
the dictionary is empty, which would normally evaluate to False.
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
def __bool__(self):
|
|
13
|
-
return True
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
FORCE_MULTIPART = ForceMultipartDict()
|
sarvamai/requests/audio_data.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing_extensions
|
|
4
|
-
from ..types.audio_data_encoding import AudioDataEncoding
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class AudioDataParams(typing_extensions.TypedDict):
|
|
8
|
-
data: str
|
|
9
|
-
"""
|
|
10
|
-
Base64 encoded audio data
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
sample_rate: int
|
|
14
|
-
"""
|
|
15
|
-
Audio sample rate in Hz (16kHz preferred, 8kHz least preferred)
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
encoding: AudioDataEncoding
|
|
19
|
-
"""
|
|
20
|
-
Audio encoding format
|
|
21
|
-
"""
|
sarvamai/requests/error_data.py
DELETED
sarvamai/requests/events_data.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import datetime as dt
|
|
4
|
-
|
|
5
|
-
import typing_extensions
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class EventsDataParams(typing_extensions.TypedDict):
|
|
9
|
-
event_type: str
|
|
10
|
-
"""
|
|
11
|
-
Type of event
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
timestamp: dt.datetime
|
|
15
|
-
"""
|
|
16
|
-
Event timestamp
|
|
17
|
-
"""
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing_extensions
|
|
4
|
-
from ..types.speech_to_text_streaming_response_type import SpeechToTextStreamingResponseType
|
|
5
|
-
from .speech_to_text_streaming_response_data import SpeechToTextStreamingResponseDataParams
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class SpeechToTextStreamingResponseParams(typing_extensions.TypedDict):
|
|
9
|
-
type: SpeechToTextStreamingResponseType
|
|
10
|
-
data: SpeechToTextStreamingResponseDataParams
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing
|
|
4
|
-
|
|
5
|
-
from .error_data import ErrorDataParams
|
|
6
|
-
from .events_data import EventsDataParams
|
|
7
|
-
from .transcription_data import TranscriptionDataParams
|
|
8
|
-
|
|
9
|
-
SpeechToTextStreamingResponseDataParams = typing.Union[TranscriptionDataParams, ErrorDataParams, EventsDataParams]
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing
|
|
4
|
-
|
|
5
|
-
import typing_extensions
|
|
6
|
-
from .transcription_metrics import TranscriptionMetricsParams
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TranscriptionDataParams(typing_extensions.TypedDict):
|
|
10
|
-
request_id: str
|
|
11
|
-
"""
|
|
12
|
-
Unique identifier for the request
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
transcript: str
|
|
16
|
-
"""
|
|
17
|
-
Transcript of the provided speech
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
timestamps: typing_extensions.NotRequired[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
21
|
-
"""
|
|
22
|
-
Timestamp information (if available)
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
diarized_transcript: typing_extensions.NotRequired[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
26
|
-
"""
|
|
27
|
-
Diarized transcript of the provided speech
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
language_code: typing_extensions.NotRequired[str]
|
|
31
|
-
"""
|
|
32
|
-
BCP-47 code of detected language
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
metrics: TranscriptionMetricsParams
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing_extensions
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class TranscriptionMetricsParams(typing_extensions.TypedDict):
|
|
7
|
-
audio_duration: float
|
|
8
|
-
"""
|
|
9
|
-
Duration of processed audio in seconds
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
processing_latency: float
|
|
13
|
-
"""
|
|
14
|
-
Processing latency in seconds
|
|
15
|
-
"""
|
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
)
|