sarvamai 0.1.19a1__py3-none-any.whl → 0.1.19a3__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/requests/config_message.py +1 -1
- sarvamai/speech_to_text_translate_streaming/socket_client.py +62 -11
- sarvamai/types/config_message.py +1 -1
- {sarvamai-0.1.19a1.dist-info → sarvamai-0.1.19a3.dist-info}/METADATA +1 -1
- {sarvamai-0.1.19a1.dist-info → sarvamai-0.1.19a3.dist-info}/RECORD +7 -7
- {sarvamai-0.1.19a1.dist-info → sarvamai-0.1.19a3.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.19a3",
|
|
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.19a3",
|
|
30
30
|
**(self.get_custom_headers() or {}),
|
|
31
31
|
}
|
|
32
32
|
headers["api-subscription-key"] = self.api_subscription_key
|
|
@@ -10,9 +10,14 @@ from ..core.pydantic_utilities import parse_obj_as
|
|
|
10
10
|
from ..types.audio_data import AudioData
|
|
11
11
|
from ..types.audio_message import AudioMessage
|
|
12
12
|
from ..types.config_message import ConfigMessage
|
|
13
|
-
from ..types.speech_to_text_translate_streaming_response import
|
|
13
|
+
from ..types.speech_to_text_translate_streaming_response import (
|
|
14
|
+
SpeechToTextTranslateStreamingResponse,
|
|
15
|
+
)
|
|
16
|
+
from ..types.stt_flush_signal import SttFlushSignal
|
|
14
17
|
|
|
15
|
-
SpeechToTextTranslateStreamingSocketClientResponse = typing.Union[
|
|
18
|
+
SpeechToTextTranslateStreamingSocketClientResponse = typing.Union[
|
|
19
|
+
SpeechToTextTranslateStreamingResponse
|
|
20
|
+
]
|
|
16
21
|
|
|
17
22
|
|
|
18
23
|
class AsyncSpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
@@ -38,7 +43,11 @@ class AsyncSpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
38
43
|
self._emit(EventType.OPEN, None)
|
|
39
44
|
try:
|
|
40
45
|
async for raw_message in self._websocket:
|
|
41
|
-
raw_message =
|
|
46
|
+
raw_message = (
|
|
47
|
+
json.loads(raw_message)
|
|
48
|
+
if isinstance(raw_message, str)
|
|
49
|
+
else raw_message
|
|
50
|
+
)
|
|
42
51
|
parsed = parse_obj_as(SpeechToTextTranslateStreamingSocketClientResponse, raw_message) # type: ignore
|
|
43
52
|
self._emit(EventType.MESSAGE, parsed)
|
|
44
53
|
except websockets.WebSocketException as exc:
|
|
@@ -46,7 +55,9 @@ class AsyncSpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
46
55
|
finally:
|
|
47
56
|
self._emit(EventType.CLOSE, None)
|
|
48
57
|
|
|
49
|
-
async def translate(
|
|
58
|
+
async def translate(
|
|
59
|
+
self, audio: str, encoding: str = "audio/wav", sample_rate: int = 16000
|
|
60
|
+
):
|
|
50
61
|
"""
|
|
51
62
|
Sends audio translation request to the server.
|
|
52
63
|
:param audio: Base64 encoded audio data
|
|
@@ -54,7 +65,9 @@ class AsyncSpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
54
65
|
:param sample_rate (Optional): Audio sample rate in Hz (default is 16000)
|
|
55
66
|
"""
|
|
56
67
|
return await self._send_speech_to_text_translate_streaming_audio_message(
|
|
57
|
-
message=AudioMessage(
|
|
68
|
+
message=AudioMessage(
|
|
69
|
+
audio=AudioData(data=audio, encoding=encoding, sample_rate=sample_rate)
|
|
70
|
+
)
|
|
58
71
|
)
|
|
59
72
|
|
|
60
73
|
async def set_prompt(self, prompt: str) -> None:
|
|
@@ -66,15 +79,31 @@ class AsyncSpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
66
79
|
message = ConfigMessage(prompt=prompt)
|
|
67
80
|
await self._send_config_message(message)
|
|
68
81
|
|
|
82
|
+
async def flush(self, reason: typing.Optional[str] = None) -> None:
|
|
83
|
+
"""
|
|
84
|
+
Signal to flush the audio buffer and force finalize partial
|
|
85
|
+
transcriptions and translations. Use this to force processing of any
|
|
86
|
+
remaining audio that hasn't been transcribed and translated yet.
|
|
87
|
+
|
|
88
|
+
:param reason: Optional reason for flushing (e.g., "end_of_segment",
|
|
89
|
+
"manual_flush")
|
|
90
|
+
"""
|
|
91
|
+
message = SttFlushSignal(reason=reason)
|
|
92
|
+
await self._send_model(message)
|
|
93
|
+
|
|
69
94
|
async def recv(self) -> SpeechToTextTranslateStreamingSocketClientResponse:
|
|
70
95
|
"""
|
|
71
96
|
Receive a message from the websocket connection.
|
|
72
97
|
"""
|
|
73
98
|
data = await self._websocket.recv()
|
|
74
99
|
data = json.loads(data) if isinstance(data, str) else data
|
|
75
|
-
return parse_obj_as(
|
|
100
|
+
return parse_obj_as(
|
|
101
|
+
SpeechToTextTranslateStreamingSocketClientResponse, data
|
|
102
|
+
) # type: ignore
|
|
76
103
|
|
|
77
|
-
async def _send_speech_to_text_translate_streaming_audio_message(
|
|
104
|
+
async def _send_speech_to_text_translate_streaming_audio_message(
|
|
105
|
+
self, message: AudioMessage
|
|
106
|
+
) -> None:
|
|
78
107
|
"""
|
|
79
108
|
Send a message to the websocket connection.
|
|
80
109
|
The message will be sent as a AudioMessage.
|
|
@@ -126,7 +155,11 @@ class SpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
126
155
|
self._emit(EventType.OPEN, None)
|
|
127
156
|
try:
|
|
128
157
|
for raw_message in self._websocket:
|
|
129
|
-
raw_message =
|
|
158
|
+
raw_message = (
|
|
159
|
+
json.loads(raw_message)
|
|
160
|
+
if isinstance(raw_message, str)
|
|
161
|
+
else raw_message
|
|
162
|
+
)
|
|
130
163
|
parsed = parse_obj_as(SpeechToTextTranslateStreamingSocketClientResponse, raw_message) # type: ignore
|
|
131
164
|
self._emit(EventType.MESSAGE, parsed)
|
|
132
165
|
except websockets.WebSocketException as exc:
|
|
@@ -134,7 +167,9 @@ class SpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
134
167
|
finally:
|
|
135
168
|
self._emit(EventType.CLOSE, None)
|
|
136
169
|
|
|
137
|
-
def translate(
|
|
170
|
+
def translate(
|
|
171
|
+
self, audio: str, encoding: str = "audio/wav", sample_rate: int = 16000
|
|
172
|
+
):
|
|
138
173
|
"""
|
|
139
174
|
Sends audio translation request to the server.
|
|
140
175
|
:param audio: Base64 encoded audio data
|
|
@@ -142,7 +177,9 @@ class SpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
142
177
|
:param sample_rate: Audio sample rate in Hz (default is 16000)
|
|
143
178
|
"""
|
|
144
179
|
return self._send_speech_to_text_translate_streaming_audio_message(
|
|
145
|
-
message=AudioMessage(
|
|
180
|
+
message=AudioMessage(
|
|
181
|
+
audio=AudioData(data=audio, encoding=encoding, sample_rate=sample_rate)
|
|
182
|
+
)
|
|
146
183
|
)
|
|
147
184
|
|
|
148
185
|
def set_prompt(self, prompt: str) -> None:
|
|
@@ -154,6 +191,18 @@ class SpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
154
191
|
message = ConfigMessage(prompt=prompt)
|
|
155
192
|
self._send_config_message(message)
|
|
156
193
|
|
|
194
|
+
def flush(self, reason: typing.Optional[str] = None) -> None:
|
|
195
|
+
"""
|
|
196
|
+
Signal to flush the audio buffer and force finalize partial transcriptions and translations.
|
|
197
|
+
Use this to force processing of any remaining audio that hasn't been
|
|
198
|
+
transcribed and translated yet.
|
|
199
|
+
|
|
200
|
+
:param reason: Optional reason for flushing (e.g., "end_of_segment",
|
|
201
|
+
"manual_flush")
|
|
202
|
+
"""
|
|
203
|
+
message = SttFlushSignal(reason=reason)
|
|
204
|
+
self._send_model(message)
|
|
205
|
+
|
|
157
206
|
def recv(self) -> SpeechToTextTranslateStreamingSocketClientResponse:
|
|
158
207
|
"""
|
|
159
208
|
Receive a message from the websocket connection.
|
|
@@ -169,7 +218,9 @@ class SpeechToTextTranslateStreamingSocketClient(EventEmitterMixin):
|
|
|
169
218
|
"""
|
|
170
219
|
self._send_model(message)
|
|
171
220
|
|
|
172
|
-
def _send_speech_to_text_translate_streaming_audio_message(
|
|
221
|
+
def _send_speech_to_text_translate_streaming_audio_message(
|
|
222
|
+
self, message: AudioMessage
|
|
223
|
+
) -> None:
|
|
173
224
|
"""
|
|
174
225
|
Send a message to the websocket connection.
|
|
175
226
|
The message will be sent as a AudioMessage.
|
sarvamai/types/config_message.py
CHANGED
|
@@ -14,7 +14,7 @@ class ConfigMessage(UniversalBaseModel):
|
|
|
14
14
|
|
|
15
15
|
prompt: typing.Optional[str] = pydantic.Field(default=None)
|
|
16
16
|
"""
|
|
17
|
-
Prompt for ASR model to improve transcription accuracy
|
|
17
|
+
Prompt for ASR model to improve transcription accuracy.
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
20
|
if IS_PYDANTIC_V2:
|
|
@@ -5,7 +5,7 @@ sarvamai/chat/raw_client.py,sha256=A2kRuZcVWlJhyYCD7YKgqNkZEp3cYa1731KhRkhirU0,1
|
|
|
5
5
|
sarvamai/client.py,sha256=J30X_os1lPf8Wml0KDFEf6p8VGHhgF_lf3nw1T2D3qo,8207
|
|
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=2raeN4Q7mBnfXfOn3pAn2w8SM1aeo2yVzgS1q0nlEl8,2570
|
|
9
9
|
sarvamai/core/datetime_utils.py,sha256=nBys2IsYrhPdszxGKCNRPSOCwa-5DWOHG95FB8G9PKo,1047
|
|
10
10
|
sarvamai/core/events.py,sha256=HvKBdSoYcFetk7cgNXb7FxuY-FtY8NtUhZIN7mGVx8U,1159
|
|
11
11
|
sarvamai/core/file.py,sha256=d4NNbX8XvXP32z8KpK2Xovv33nFfruIrpz0QWxlgpZk,2663
|
|
@@ -43,7 +43,7 @@ sarvamai/requests/chat_completion_request_user_message.py,sha256=IqYy7K-qF9oQ8AU
|
|
|
43
43
|
sarvamai/requests/chat_completion_response_message.py,sha256=JFazj4zK-nj_wjdvNLDkcfIFxIlqw49Xf_P8o7d70aY,336
|
|
44
44
|
sarvamai/requests/choice.py,sha256=uulX4MZUoThEMcD3a80o_3V5YpnpqN8DfPaNZWVz-1o,867
|
|
45
45
|
sarvamai/requests/completion_usage.py,sha256=LbZV-RxcxKdCAYqhCiaRtSFF3VwMJq71A989Z1rm-I8,428
|
|
46
|
-
sarvamai/requests/config_message.py,sha256=
|
|
46
|
+
sarvamai/requests/config_message.py,sha256=SeWZB5OEVzgL3aAtLehpGZzLdSEkxr-6RI3372j_Blg,384
|
|
47
47
|
sarvamai/requests/configure_connection.py,sha256=a-foQtLxArL4CulvKEdeebbRqmS1GRmko3MZdnHVPEk,716
|
|
48
48
|
sarvamai/requests/configure_connection_data.py,sha256=lRk_4rYPQLLlwS2HXjQ9Abxdf98_DuOOja-VkrIR44Q,3016
|
|
49
49
|
sarvamai/requests/create_chat_completion_response.py,sha256=TqS9u5_WVWMok_NreT4TeOsLJQeybPkbJm45Q0Zxw30,857
|
|
@@ -108,7 +108,7 @@ sarvamai/speech_to_text_translate_job/raw_client.py,sha256=dAitbu2B9afPK6iT9zNjU
|
|
|
108
108
|
sarvamai/speech_to_text_translate_streaming/__init__.py,sha256=sDeWLagKUTg34tL7vpNNwr2gX4AznEn6NAy9jY-Znf4,507
|
|
109
109
|
sarvamai/speech_to_text_translate_streaming/client.py,sha256=41FAJekotqq08tDdxWqhT966B5Ofx9MuZgHAJ9xmwRQ,9137
|
|
110
110
|
sarvamai/speech_to_text_translate_streaming/raw_client.py,sha256=P-p7pNJNLrgra4HoUx1vG34RcLADYfQEpoVMYe-aMa0,8246
|
|
111
|
-
sarvamai/speech_to_text_translate_streaming/socket_client.py,sha256=
|
|
111
|
+
sarvamai/speech_to_text_translate_streaming/socket_client.py,sha256=N0-mlrD1c6J34hb3YOjUrpvhGyCE62j_CeFnrdQGjUU,9233
|
|
112
112
|
sarvamai/speech_to_text_translate_streaming/types/__init__.py,sha256=sK4Zv64ZcV33opFFaVd1kgnQnzjfXrSDhUwiEM85sZc,708
|
|
113
113
|
sarvamai/speech_to_text_translate_streaming/types/speech_to_text_translate_streaming_flush_signal.py,sha256=jkjvCGJ1pFKi3AOTkwMW-lo18WGgrgAhMpoe5P0AMzA,182
|
|
114
114
|
sarvamai/speech_to_text_translate_streaming/types/speech_to_text_translate_streaming_high_vad_sensitivity.py,sha256=r6MvTlkM0VEpb4dpnMHtINOZ-gYc22o0Fx_Xce2rjvo,189
|
|
@@ -139,7 +139,7 @@ sarvamai/types/chat_completion_request_user_message.py,sha256=J3WhlrfOfCCe7ugmJI
|
|
|
139
139
|
sarvamai/types/chat_completion_response_message.py,sha256=wz935eBnCkSIl0I0qMxBuH4vAUCso1aHDGReMW1VHGE,744
|
|
140
140
|
sarvamai/types/choice.py,sha256=uXBCsjWP9VK3XWQWZUeI4EnU10w0G9nAfKn2tJZvxko,1244
|
|
141
141
|
sarvamai/types/completion_usage.py,sha256=xYQGlQUbKqsksuV73H-1ajjfT5M7w47eLfdWXSlrI5M,843
|
|
142
|
-
sarvamai/types/config_message.py,sha256=
|
|
142
|
+
sarvamai/types/config_message.py,sha256=xLD2wZcXejYrmREMd-cn38da4hKfsNPKRtyAGCW0Zcg,779
|
|
143
143
|
sarvamai/types/configure_connection.py,sha256=SnSNk02gQqP8e4VB4y88jjeFQ4ClpImjGLn2ANI8cZ4,1058
|
|
144
144
|
sarvamai/types/configure_connection_data.py,sha256=uXC7fhNJWCpaKc2Vrz2DNpUxx1gN3PwAoDL-H8L401A,3537
|
|
145
145
|
sarvamai/types/configure_connection_data_output_audio_bitrate.py,sha256=h00YvKLxsZC8L3__rH4XH53nN_GY40UElW1EjysCwUs,208
|
|
@@ -215,6 +215,6 @@ sarvamai/types/transliterate_mode.py,sha256=1jSEMlGcoLkWuk12TgoOpSgwifa4rThGKZ1h
|
|
|
215
215
|
sarvamai/types/transliterate_source_language.py,sha256=bSY9wJszF0sg-Cgg6F-YcWC8ly1mIlj9rqa15-jBtx8,283
|
|
216
216
|
sarvamai/types/transliteration_response.py,sha256=yt-lzTbDeJ_ZL4I8kQa6oESxA9ebeJJY7LfFHpdEsmM,815
|
|
217
217
|
sarvamai/version.py,sha256=Qkp3Ee9YH-O9RTix90e0i7iNrFAGN-QDt2AFwGA4n8k,75
|
|
218
|
-
sarvamai-0.1.
|
|
219
|
-
sarvamai-0.1.
|
|
220
|
-
sarvamai-0.1.
|
|
218
|
+
sarvamai-0.1.19a3.dist-info/METADATA,sha256=lwfEWnVj0lP9LBb6B4ixr2995S8ph7-LNOsTbtWgdPU,26753
|
|
219
|
+
sarvamai-0.1.19a3.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
220
|
+
sarvamai-0.1.19a3.dist-info/RECORD,,
|
|
File without changes
|