sarvamai 0.1.19a0__py3-none-any.whl → 0.1.19a2__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_streaming/socket_client.py +68 -13
- {sarvamai-0.1.19a0.dist-info → sarvamai-0.1.19a2.dist-info}/METADATA +1 -1
- {sarvamai-0.1.19a0.dist-info → sarvamai-0.1.19a2.dist-info}/RECORD +5 -5
- {sarvamai-0.1.19a0.dist-info → sarvamai-0.1.19a2.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.19a2",
|
|
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.19a2",
|
|
30
30
|
**(self.get_custom_headers() or {}),
|
|
31
31
|
}
|
|
32
32
|
headers["api-subscription-key"] = self.api_subscription_key
|
|
@@ -9,7 +9,10 @@ from ..core.events import EventEmitterMixin, EventType
|
|
|
9
9
|
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
|
-
from ..types.speech_to_text_streaming_response import
|
|
12
|
+
from ..types.speech_to_text_streaming_response import (
|
|
13
|
+
SpeechToTextStreamingResponse,
|
|
14
|
+
)
|
|
15
|
+
from ..types.stt_flush_signal import SttFlushSignal
|
|
13
16
|
|
|
14
17
|
SpeechToTextStreamingSocketClientResponse = typing.Union[SpeechToTextStreamingResponse]
|
|
15
18
|
|
|
@@ -22,7 +25,9 @@ class AsyncSpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
22
25
|
async def __aiter__(self):
|
|
23
26
|
async for message in self._websocket:
|
|
24
27
|
message = json.loads(message) if isinstance(message, str) else message
|
|
25
|
-
yield parse_obj_as(
|
|
28
|
+
yield parse_obj_as(
|
|
29
|
+
SpeechToTextStreamingSocketClientResponse, message
|
|
30
|
+
) # type: ignore
|
|
26
31
|
|
|
27
32
|
async def start_listening(self):
|
|
28
33
|
"""
|
|
@@ -37,8 +42,14 @@ class AsyncSpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
37
42
|
self._emit(EventType.OPEN, None)
|
|
38
43
|
try:
|
|
39
44
|
async for raw_message in self._websocket:
|
|
40
|
-
raw_message =
|
|
41
|
-
|
|
45
|
+
raw_message = (
|
|
46
|
+
json.loads(raw_message)
|
|
47
|
+
if isinstance(raw_message, str)
|
|
48
|
+
else raw_message
|
|
49
|
+
)
|
|
50
|
+
parsed = parse_obj_as(
|
|
51
|
+
SpeechToTextStreamingSocketClientResponse, raw_message
|
|
52
|
+
) # type: ignore
|
|
42
53
|
self._emit(EventType.MESSAGE, parsed)
|
|
43
54
|
except websockets.WebSocketException as exc:
|
|
44
55
|
self._emit(EventType.ERROR, exc)
|
|
@@ -54,10 +65,26 @@ class AsyncSpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
54
65
|
"""
|
|
55
66
|
|
|
56
67
|
return await self._send_speech_to_text_streaming_audio_message(
|
|
57
|
-
message=AudioMessage(
|
|
68
|
+
message=AudioMessage(
|
|
69
|
+
audio=AudioData(data=audio, sample_rate=sample_rate, encoding=encoding)
|
|
70
|
+
)
|
|
58
71
|
)
|
|
59
72
|
|
|
60
|
-
async def
|
|
73
|
+
async def flush(self, reason: typing.Optional[str] = None) -> None:
|
|
74
|
+
"""
|
|
75
|
+
Signal to flush the audio buffer and force finalize partial transcriptions.
|
|
76
|
+
Use this to force processing of any remaining audio that hasn't been
|
|
77
|
+
transcribed yet.
|
|
78
|
+
|
|
79
|
+
:param reason: Optional reason for flushing (e.g., "end_of_segment",
|
|
80
|
+
"manual_flush")
|
|
81
|
+
"""
|
|
82
|
+
message = SttFlushSignal(reason=reason)
|
|
83
|
+
await self._send_model(message)
|
|
84
|
+
|
|
85
|
+
async def _send_speech_to_text_streaming_audio_message(
|
|
86
|
+
self, message: AudioMessage
|
|
87
|
+
) -> None:
|
|
61
88
|
"""
|
|
62
89
|
Send a message to the websocket connection.
|
|
63
90
|
The message will be sent as a AudioMessage.
|
|
@@ -70,7 +97,9 @@ class AsyncSpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
70
97
|
"""
|
|
71
98
|
data = await self._websocket.recv()
|
|
72
99
|
data = json.loads(data) if isinstance(data, str) else data
|
|
73
|
-
return parse_obj_as(
|
|
100
|
+
return parse_obj_as(
|
|
101
|
+
SpeechToTextStreamingSocketClientResponse, data
|
|
102
|
+
) # type: ignore
|
|
74
103
|
|
|
75
104
|
async def _send(self, data: typing.Any) -> None:
|
|
76
105
|
"""
|
|
@@ -95,7 +124,9 @@ class SpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
95
124
|
def __iter__(self):
|
|
96
125
|
for message in self._websocket:
|
|
97
126
|
message = json.loads(message) if isinstance(message, str) else message
|
|
98
|
-
yield parse_obj_as(
|
|
127
|
+
yield parse_obj_as(
|
|
128
|
+
SpeechToTextStreamingSocketClientResponse, message
|
|
129
|
+
) # type: ignore
|
|
99
130
|
|
|
100
131
|
def start_listening(self):
|
|
101
132
|
"""
|
|
@@ -110,8 +141,14 @@ class SpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
110
141
|
self._emit(EventType.OPEN, None)
|
|
111
142
|
try:
|
|
112
143
|
for raw_message in self._websocket:
|
|
113
|
-
raw_message =
|
|
114
|
-
|
|
144
|
+
raw_message = (
|
|
145
|
+
json.loads(raw_message)
|
|
146
|
+
if isinstance(raw_message, str)
|
|
147
|
+
else raw_message
|
|
148
|
+
)
|
|
149
|
+
parsed = parse_obj_as(
|
|
150
|
+
SpeechToTextStreamingSocketClientResponse, raw_message
|
|
151
|
+
) # type: ignore
|
|
115
152
|
self._emit(EventType.MESSAGE, parsed)
|
|
116
153
|
except websockets.WebSocketException as exc:
|
|
117
154
|
self._emit(EventType.ERROR, exc)
|
|
@@ -126,18 +163,36 @@ class SpeechToTextStreamingSocketClient(EventEmitterMixin):
|
|
|
126
163
|
:param sample_rate (Optional): Audio sample rate in Hz (default is 16000)
|
|
127
164
|
"""
|
|
128
165
|
return self._send_speech_to_text_streaming_audio_message(
|
|
129
|
-
message=AudioMessage(
|
|
166
|
+
message=AudioMessage(
|
|
167
|
+
audio=AudioData(data=audio, sample_rate=sample_rate, encoding=encoding)
|
|
168
|
+
)
|
|
130
169
|
)
|
|
131
170
|
|
|
171
|
+
def flush(self, reason: typing.Optional[str] = None) -> None:
|
|
172
|
+
"""
|
|
173
|
+
Signal to flush the audio buffer and force finalize partial transcriptions.
|
|
174
|
+
Use this to force processing of any remaining audio that hasn't been
|
|
175
|
+
transcribed yet.
|
|
176
|
+
|
|
177
|
+
:param reason: Optional reason for flushing (e.g., "end_of_segment",
|
|
178
|
+
"manual_flush")
|
|
179
|
+
"""
|
|
180
|
+
message = SttFlushSignal(reason=reason)
|
|
181
|
+
self._send_model(message)
|
|
182
|
+
|
|
132
183
|
def recv(self) -> SpeechToTextStreamingSocketClientResponse:
|
|
133
184
|
"""
|
|
134
185
|
Receive a message from the websocket connection.
|
|
135
186
|
"""
|
|
136
187
|
data = self._websocket.recv()
|
|
137
188
|
data = json.loads(data) if isinstance(data, str) else data
|
|
138
|
-
return parse_obj_as(
|
|
189
|
+
return parse_obj_as(
|
|
190
|
+
SpeechToTextStreamingSocketClientResponse, data
|
|
191
|
+
) # type: ignore
|
|
139
192
|
|
|
140
|
-
def _send_speech_to_text_streaming_audio_message(
|
|
193
|
+
def _send_speech_to_text_streaming_audio_message(
|
|
194
|
+
self, message: AudioMessage
|
|
195
|
+
) -> None:
|
|
141
196
|
"""
|
|
142
197
|
Send a message to the websocket connection.
|
|
143
198
|
The message will be sent as a AudioMessage.
|
|
@@ -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=wE2VNWPeyHeA2m4ZKv3TvURhnIPSxCz9G48V5lZPbX4,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
|
|
@@ -94,7 +94,7 @@ sarvamai/speech_to_text_job/raw_client.py,sha256=OZTPzMhAn-ckE_xKzfZ9QLsEX5EZVOJ
|
|
|
94
94
|
sarvamai/speech_to_text_streaming/__init__.py,sha256=aVcI8kSlUpwLrPtA-4oUkuJ_D9Onha_qU49lA2vtEqU,515
|
|
95
95
|
sarvamai/speech_to_text_streaming/client.py,sha256=15k-UH2ROia2EymXia0BxVKbzBz7k1Rh9k7L9hgO5Fg,9206
|
|
96
96
|
sarvamai/speech_to_text_streaming/raw_client.py,sha256=69hAAD9mcpplo3gR7B5JXbo6Yys8bPT3DfSk1FjyI8Q,8387
|
|
97
|
-
sarvamai/speech_to_text_streaming/socket_client.py,sha256=
|
|
97
|
+
sarvamai/speech_to_text_streaming/socket_client.py,sha256=N0wjuQ37WtTggQysWfB8pOwLIwmIkGRglZO9N2y5yHI,7870
|
|
98
98
|
sarvamai/speech_to_text_streaming/types/__init__.py,sha256=A99VJwG5fkik5SFTMDMKPZCjvKSaU2aQ02EbA5rrDlM,723
|
|
99
99
|
sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_flush_signal.py,sha256=dDJOBlzAjhuiSVqW2RHHY1f6xy0DU_Yoo9UV8-7MjnA,173
|
|
100
100
|
sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_high_vad_sensitivity.py,sha256=OwPwffa8TkLPGMnOTn5S7d-HmV8QmN3B7fHz8I1-VT8,180
|
|
@@ -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.19a2.dist-info/METADATA,sha256=YaTRDFMvJFy1UF8DtXSN2itvtgQqEcrKns2JglAUHn8,26753
|
|
219
|
+
sarvamai-0.1.19a2.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
220
|
+
sarvamai-0.1.19a2.dist-info/RECORD,,
|
|
File without changes
|