sarvamai 0.1.7a0__py3-none-any.whl → 0.1.8b0__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 +50 -52
- sarvamai/client.py +3 -3
- sarvamai/core/client_wrapper.py +2 -2
- sarvamai/errors/service_unavailable_error.py +2 -1
- sarvamai/requests/__init__.py +20 -22
- sarvamai/requests/audio_output.py +11 -0
- sarvamai/requests/audio_output_data.py +15 -0
- sarvamai/requests/{files_request.py → close_connection.py} +2 -3
- sarvamai/requests/error_response.py +11 -0
- sarvamai/requests/error_response_data.py +18 -0
- sarvamai/requests/initialize_connection.py +11 -0
- sarvamai/requests/initialize_connection_data.py +24 -0
- sarvamai/requests/ping_signal.py +9 -0
- sarvamai/requests/send_text.py +11 -0
- sarvamai/requests/{base_job_parameters.py → send_text_data.py} +2 -2
- sarvamai/speech_to_text/raw_client.py +9 -8
- sarvamai/text_to_speech_streaming/client.py +136 -0
- sarvamai/text_to_speech_streaming/raw_client.py +113 -0
- sarvamai/text_to_speech_streaming/socket_client.py +177 -0
- sarvamai/types/__init__.py +28 -28
- sarvamai/types/audio_output.py +21 -0
- sarvamai/types/{bulk_job_callback.py → audio_output_data.py} +5 -5
- sarvamai/types/{files_request.py → close_connection.py} +2 -3
- sarvamai/types/error_response.py +21 -0
- sarvamai/types/{files_download_response.py → error_response_data.py} +11 -8
- sarvamai/types/initialize_connection.py +21 -0
- sarvamai/types/initialize_connection_data.py +34 -0
- sarvamai/types/initialize_connection_data_model.py +5 -0
- sarvamai/types/initialize_connection_data_output_audio_bitrate.py +7 -0
- sarvamai/types/initialize_connection_data_speaker.py +28 -0
- sarvamai/types/initialize_connection_data_target_language_code.py +8 -0
- sarvamai/types/{task_file_details.py → ping_signal.py} +2 -3
- sarvamai/types/{file_signed_url_details.py → send_text.py} +4 -3
- sarvamai/types/{base_job_parameters.py → send_text_data.py} +3 -1
- {sarvamai-0.1.7a0.dist-info → sarvamai-0.1.8b0.dist-info}/METADATA +1 -1
- {sarvamai-0.1.7a0.dist-info → sarvamai-0.1.8b0.dist-info}/RECORD +38 -38
- sarvamai/requests/bulk_job_callback.py +0 -15
- sarvamai/requests/bulk_job_init_response_v_1.py +0 -27
- sarvamai/requests/file_signed_url_details.py +0 -10
- sarvamai/requests/files_download_response.py +0 -15
- sarvamai/requests/files_upload_response.py +0 -15
- sarvamai/requests/job_status_v_1.py +0 -70
- sarvamai/requests/speech_to_text_job_parameters.py +0 -32
- sarvamai/requests/task_detail_v_1.py +0 -15
- sarvamai/requests/task_file_details.py +0 -8
- sarvamai/speech_to_text_job/client.py +0 -454
- sarvamai/speech_to_text_job/raw_client.py +0 -1189
- sarvamai/types/bulk_job_init_response_v_1.py +0 -39
- sarvamai/types/files_upload_response.py +0 -25
- sarvamai/types/job_state.py +0 -5
- sarvamai/types/job_status_v_1.py +0 -80
- sarvamai/types/speech_to_text_job_parameters.py +0 -44
- sarvamai/types/storage_container_type.py +0 -5
- sarvamai/types/task_detail_v_1.py +0 -25
- sarvamai/types/task_state.py +0 -5
- /sarvamai/{speech_to_text_job → text_to_speech_streaming}/__init__.py +0 -0
- {sarvamai-0.1.7a0.dist-info → sarvamai-0.1.8b0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,136 @@
|
|
|
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 websockets
|
|
7
|
+
import websockets.sync.client as websockets_sync_client
|
|
8
|
+
from ..core.api_error import ApiError
|
|
9
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
10
|
+
from ..core.request_options import RequestOptions
|
|
11
|
+
from .raw_client import AsyncRawTextToSpeechStreamingClient, RawTextToSpeechStreamingClient
|
|
12
|
+
from .socket_client import AsyncTextToSpeechStreamingSocketClient, TextToSpeechStreamingSocketClient
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TextToSpeechStreamingClient:
|
|
16
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
17
|
+
self._raw_client = RawTextToSpeechStreamingClient(client_wrapper=client_wrapper)
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def with_raw_response(self) -> RawTextToSpeechStreamingClient:
|
|
21
|
+
"""
|
|
22
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
23
|
+
|
|
24
|
+
Returns
|
|
25
|
+
-------
|
|
26
|
+
RawTextToSpeechStreamingClient
|
|
27
|
+
"""
|
|
28
|
+
return self._raw_client
|
|
29
|
+
|
|
30
|
+
@contextmanager
|
|
31
|
+
def connect(
|
|
32
|
+
self,
|
|
33
|
+
*,
|
|
34
|
+
api_subscription_key: typing.Optional[str] = None,
|
|
35
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
36
|
+
) -> typing.Iterator[TextToSpeechStreamingSocketClient]:
|
|
37
|
+
"""
|
|
38
|
+
Bidirectional WebSocket channel for real-time TTS synthesis.
|
|
39
|
+
Supports streaming, flushing, config updates, and audio playback.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
api_subscription_key : typing.Optional[str]
|
|
44
|
+
API subscription key for authentication
|
|
45
|
+
|
|
46
|
+
request_options : typing.Optional[RequestOptions]
|
|
47
|
+
Request-specific configuration.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
TextToSpeechStreamingSocketClient
|
|
52
|
+
"""
|
|
53
|
+
ws_url = self._raw_client._client_wrapper.get_environment().production + "/text-to-speech/ws"
|
|
54
|
+
headers = self._raw_client._client_wrapper.get_headers()
|
|
55
|
+
if api_subscription_key is not None:
|
|
56
|
+
headers["Api-Subscription-Key"] = str(api_subscription_key)
|
|
57
|
+
if request_options and "additional_headers" in request_options:
|
|
58
|
+
headers.update(request_options["additional_headers"])
|
|
59
|
+
try:
|
|
60
|
+
with websockets_sync_client.connect(ws_url, additional_headers=headers) as protocol:
|
|
61
|
+
yield TextToSpeechStreamingSocketClient(websocket=protocol)
|
|
62
|
+
except websockets.exceptions.InvalidStatusCode as exc:
|
|
63
|
+
status_code: int = exc.status_code
|
|
64
|
+
if status_code == 401:
|
|
65
|
+
raise ApiError(
|
|
66
|
+
status_code=status_code,
|
|
67
|
+
headers=dict(headers),
|
|
68
|
+
body="Websocket initialized with invalid credentials.",
|
|
69
|
+
)
|
|
70
|
+
raise ApiError(
|
|
71
|
+
status_code=status_code,
|
|
72
|
+
headers=dict(headers),
|
|
73
|
+
body="Unexpected error when initializing websocket connection.",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class AsyncTextToSpeechStreamingClient:
|
|
78
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
79
|
+
self._raw_client = AsyncRawTextToSpeechStreamingClient(client_wrapper=client_wrapper)
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def with_raw_response(self) -> AsyncRawTextToSpeechStreamingClient:
|
|
83
|
+
"""
|
|
84
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
AsyncRawTextToSpeechStreamingClient
|
|
89
|
+
"""
|
|
90
|
+
return self._raw_client
|
|
91
|
+
|
|
92
|
+
@asynccontextmanager
|
|
93
|
+
async def connect(
|
|
94
|
+
self,
|
|
95
|
+
*,
|
|
96
|
+
api_subscription_key: typing.Optional[str] = None,
|
|
97
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
98
|
+
) -> typing.AsyncIterator[AsyncTextToSpeechStreamingSocketClient]:
|
|
99
|
+
"""
|
|
100
|
+
Bidirectional WebSocket channel for real-time TTS synthesis.
|
|
101
|
+
Supports streaming, flushing, config updates, and audio playback.
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
api_subscription_key : typing.Optional[str]
|
|
106
|
+
API subscription key for authentication
|
|
107
|
+
|
|
108
|
+
request_options : typing.Optional[RequestOptions]
|
|
109
|
+
Request-specific configuration.
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
-------
|
|
113
|
+
AsyncTextToSpeechStreamingSocketClient
|
|
114
|
+
"""
|
|
115
|
+
ws_url = self._raw_client._client_wrapper.get_environment().production + "/text-to-speech/ws"
|
|
116
|
+
headers = self._raw_client._client_wrapper.get_headers()
|
|
117
|
+
if api_subscription_key is not None:
|
|
118
|
+
headers["Api-Subscription-Key"] = str(api_subscription_key)
|
|
119
|
+
if request_options and "additional_headers" in request_options:
|
|
120
|
+
headers.update(request_options["additional_headers"])
|
|
121
|
+
try:
|
|
122
|
+
async with websockets.connect(ws_url, extra_headers=headers) as protocol:
|
|
123
|
+
yield AsyncTextToSpeechStreamingSocketClient(websocket=protocol)
|
|
124
|
+
except websockets.exceptions.InvalidStatusCode as exc:
|
|
125
|
+
status_code: int = exc.status_code
|
|
126
|
+
if status_code == 401:
|
|
127
|
+
raise ApiError(
|
|
128
|
+
status_code=status_code,
|
|
129
|
+
headers=dict(headers),
|
|
130
|
+
body="Websocket initialized with invalid credentials.",
|
|
131
|
+
)
|
|
132
|
+
raise ApiError(
|
|
133
|
+
status_code=status_code,
|
|
134
|
+
headers=dict(headers),
|
|
135
|
+
body="Unexpected error when initializing websocket connection.",
|
|
136
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
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 websockets
|
|
7
|
+
import websockets.sync.client as websockets_sync_client
|
|
8
|
+
from ..core.api_error import ApiError
|
|
9
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
10
|
+
from ..core.request_options import RequestOptions
|
|
11
|
+
from .socket_client import AsyncTextToSpeechStreamingSocketClient, TextToSpeechStreamingSocketClient
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RawTextToSpeechStreamingClient:
|
|
15
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
16
|
+
self._client_wrapper = client_wrapper
|
|
17
|
+
|
|
18
|
+
@contextmanager
|
|
19
|
+
def connect(
|
|
20
|
+
self,
|
|
21
|
+
*,
|
|
22
|
+
api_subscription_key: typing.Optional[str] = None,
|
|
23
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
24
|
+
) -> typing.Iterator[TextToSpeechStreamingSocketClient]:
|
|
25
|
+
"""
|
|
26
|
+
Bidirectional WebSocket channel for real-time TTS synthesis.
|
|
27
|
+
Supports streaming, flushing, config updates, and audio playback.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
api_subscription_key : typing.Optional[str]
|
|
32
|
+
API subscription key for authentication
|
|
33
|
+
|
|
34
|
+
request_options : typing.Optional[RequestOptions]
|
|
35
|
+
Request-specific configuration.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
TextToSpeechStreamingSocketClient
|
|
40
|
+
"""
|
|
41
|
+
ws_url = self._client_wrapper.get_environment().production + "/text-to-speech/ws"
|
|
42
|
+
headers = self._client_wrapper.get_headers()
|
|
43
|
+
if api_subscription_key is not None:
|
|
44
|
+
headers["Api-Subscription-Key"] = str(api_subscription_key)
|
|
45
|
+
if request_options and "additional_headers" in request_options:
|
|
46
|
+
headers.update(request_options["additional_headers"])
|
|
47
|
+
try:
|
|
48
|
+
with websockets_sync_client.connect(ws_url, additional_headers=headers) as protocol:
|
|
49
|
+
yield TextToSpeechStreamingSocketClient(websocket=protocol)
|
|
50
|
+
except websockets.exceptions.InvalidStatusCode as exc:
|
|
51
|
+
status_code: int = exc.status_code
|
|
52
|
+
if status_code == 401:
|
|
53
|
+
raise ApiError(
|
|
54
|
+
status_code=status_code,
|
|
55
|
+
headers=dict(headers),
|
|
56
|
+
body="Websocket initialized with invalid credentials.",
|
|
57
|
+
)
|
|
58
|
+
raise ApiError(
|
|
59
|
+
status_code=status_code,
|
|
60
|
+
headers=dict(headers),
|
|
61
|
+
body="Unexpected error when initializing websocket connection.",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class AsyncRawTextToSpeechStreamingClient:
|
|
66
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
67
|
+
self._client_wrapper = client_wrapper
|
|
68
|
+
|
|
69
|
+
@asynccontextmanager
|
|
70
|
+
async def connect(
|
|
71
|
+
self,
|
|
72
|
+
*,
|
|
73
|
+
api_subscription_key: typing.Optional[str] = None,
|
|
74
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
75
|
+
) -> typing.AsyncIterator[AsyncTextToSpeechStreamingSocketClient]:
|
|
76
|
+
"""
|
|
77
|
+
Bidirectional WebSocket channel for real-time TTS synthesis.
|
|
78
|
+
Supports streaming, flushing, config updates, and audio playback.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
api_subscription_key : typing.Optional[str]
|
|
83
|
+
API subscription key for authentication
|
|
84
|
+
|
|
85
|
+
request_options : typing.Optional[RequestOptions]
|
|
86
|
+
Request-specific configuration.
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
AsyncTextToSpeechStreamingSocketClient
|
|
91
|
+
"""
|
|
92
|
+
ws_url = self._client_wrapper.get_environment().production + "/text-to-speech/ws"
|
|
93
|
+
headers = self._client_wrapper.get_headers()
|
|
94
|
+
if api_subscription_key is not None:
|
|
95
|
+
headers["Api-Subscription-Key"] = str(api_subscription_key)
|
|
96
|
+
if request_options and "additional_headers" in request_options:
|
|
97
|
+
headers.update(request_options["additional_headers"])
|
|
98
|
+
try:
|
|
99
|
+
async with websockets.connect(ws_url, extra_headers=headers) as protocol:
|
|
100
|
+
yield AsyncTextToSpeechStreamingSocketClient(websocket=protocol)
|
|
101
|
+
except websockets.exceptions.InvalidStatusCode as exc:
|
|
102
|
+
status_code: int = exc.status_code
|
|
103
|
+
if status_code == 401:
|
|
104
|
+
raise ApiError(
|
|
105
|
+
status_code=status_code,
|
|
106
|
+
headers=dict(headers),
|
|
107
|
+
body="Websocket initialized with invalid credentials.",
|
|
108
|
+
)
|
|
109
|
+
raise ApiError(
|
|
110
|
+
status_code=status_code,
|
|
111
|
+
headers=dict(headers),
|
|
112
|
+
body="Unexpected error when initializing websocket connection.",
|
|
113
|
+
)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import typing
|
|
5
|
+
|
|
6
|
+
import websockets
|
|
7
|
+
import websockets.sync.connection as websockets_sync_connection
|
|
8
|
+
from ..core.events import EventEmitterMixin, EventType
|
|
9
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
10
|
+
from ..types.audio_output import AudioOutput
|
|
11
|
+
from ..types.close_connection import CloseConnection
|
|
12
|
+
from ..types.error_response import ErrorResponse
|
|
13
|
+
from ..types.initialize_connection import InitializeConnection
|
|
14
|
+
from ..types.ping_signal import PingSignal
|
|
15
|
+
from ..types.send_text import SendText
|
|
16
|
+
|
|
17
|
+
TextToSpeechStreamingSocketClientResponse = typing.Union[AudioOutput, ErrorResponse]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AsyncTextToSpeechStreamingSocketClient(EventEmitterMixin):
|
|
21
|
+
def __init__(self, *, websocket: websockets.WebSocketClientProtocol):
|
|
22
|
+
super().__init__()
|
|
23
|
+
self._websocket = websocket
|
|
24
|
+
|
|
25
|
+
async def __aiter__(self):
|
|
26
|
+
async for message in self._websocket:
|
|
27
|
+
yield parse_obj_as(TextToSpeechStreamingSocketClientResponse, message) # type: ignore
|
|
28
|
+
|
|
29
|
+
async def start_listening(self):
|
|
30
|
+
"""
|
|
31
|
+
Start listening for messages on the websocket connection.
|
|
32
|
+
|
|
33
|
+
Emits events in the following order:
|
|
34
|
+
- EventType.OPEN when connection is established
|
|
35
|
+
- EventType.MESSAGE for each message received
|
|
36
|
+
- EventType.ERROR if an error occurs
|
|
37
|
+
- EventType.CLOSE when connection is closed
|
|
38
|
+
"""
|
|
39
|
+
self._emit(EventType.OPEN, None)
|
|
40
|
+
try:
|
|
41
|
+
async for raw_message in self._websocket:
|
|
42
|
+
parsed = parse_obj_as(TextToSpeechStreamingSocketClientResponse, raw_message) # type: ignore
|
|
43
|
+
self._emit(EventType.MESSAGE, parsed)
|
|
44
|
+
except websockets.WebSocketException as exc:
|
|
45
|
+
self._emit(EventType.ERROR, exc)
|
|
46
|
+
finally:
|
|
47
|
+
self._emit(EventType.CLOSE, None)
|
|
48
|
+
|
|
49
|
+
async def send_initialize_connection(self, message: InitializeConnection) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Send a message to the websocket connection.
|
|
52
|
+
The message will be sent as a InitializeConnection.
|
|
53
|
+
"""
|
|
54
|
+
await self._send_model(message)
|
|
55
|
+
|
|
56
|
+
async def send_send_text(self, message: SendText) -> None:
|
|
57
|
+
"""
|
|
58
|
+
Send a message to the websocket connection.
|
|
59
|
+
The message will be sent as a SendText.
|
|
60
|
+
"""
|
|
61
|
+
await self._send_model(message)
|
|
62
|
+
|
|
63
|
+
async def send_close_connection(self, message: CloseConnection) -> None:
|
|
64
|
+
"""
|
|
65
|
+
Send a message to the websocket connection.
|
|
66
|
+
The message will be sent as a CloseConnection.
|
|
67
|
+
"""
|
|
68
|
+
await self._send_model(message)
|
|
69
|
+
|
|
70
|
+
async def send_ping_signal(self, message: PingSignal) -> None:
|
|
71
|
+
"""
|
|
72
|
+
Send a message to the websocket connection.
|
|
73
|
+
The message will be sent as a PingSignal.
|
|
74
|
+
"""
|
|
75
|
+
await self._send_model(message)
|
|
76
|
+
|
|
77
|
+
async def recv(self) -> TextToSpeechStreamingSocketClientResponse:
|
|
78
|
+
"""
|
|
79
|
+
Receive a message from the websocket connection.
|
|
80
|
+
"""
|
|
81
|
+
data = await self._websocket.recv()
|
|
82
|
+
data = json.loads(data) if isinstance(data, str) else data
|
|
83
|
+
return parse_obj_as(TextToSpeechStreamingSocketClientResponse, data) # type: ignore
|
|
84
|
+
|
|
85
|
+
async def _send(self, data: typing.Any) -> None:
|
|
86
|
+
"""
|
|
87
|
+
Send a message to the websocket connection.
|
|
88
|
+
"""
|
|
89
|
+
if isinstance(data, dict):
|
|
90
|
+
data = json.dumps(data)
|
|
91
|
+
await self._websocket.send(data)
|
|
92
|
+
|
|
93
|
+
async def _send_model(self, data: typing.Any) -> None:
|
|
94
|
+
"""
|
|
95
|
+
Send a Pydantic model to the websocket connection.
|
|
96
|
+
"""
|
|
97
|
+
await self._send(data.dict())
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class TextToSpeechStreamingSocketClient(EventEmitterMixin):
|
|
101
|
+
def __init__(self, *, websocket: websockets_sync_connection.Connection):
|
|
102
|
+
super().__init__()
|
|
103
|
+
self._websocket = websocket
|
|
104
|
+
|
|
105
|
+
def __iter__(self):
|
|
106
|
+
for message in self._websocket:
|
|
107
|
+
yield parse_obj_as(TextToSpeechStreamingSocketClientResponse, message) # type: ignore
|
|
108
|
+
|
|
109
|
+
def start_listening(self):
|
|
110
|
+
"""
|
|
111
|
+
Start listening for messages on the websocket connection.
|
|
112
|
+
|
|
113
|
+
Emits events in the following order:
|
|
114
|
+
- EventType.OPEN when connection is established
|
|
115
|
+
- EventType.MESSAGE for each message received
|
|
116
|
+
- EventType.ERROR if an error occurs
|
|
117
|
+
- EventType.CLOSE when connection is closed
|
|
118
|
+
"""
|
|
119
|
+
self._emit(EventType.OPEN, None)
|
|
120
|
+
try:
|
|
121
|
+
for raw_message in self._websocket:
|
|
122
|
+
parsed = parse_obj_as(TextToSpeechStreamingSocketClientResponse, raw_message) # type: ignore
|
|
123
|
+
self._emit(EventType.MESSAGE, parsed)
|
|
124
|
+
except websockets.WebSocketException as exc:
|
|
125
|
+
self._emit(EventType.ERROR, exc)
|
|
126
|
+
finally:
|
|
127
|
+
self._emit(EventType.CLOSE, None)
|
|
128
|
+
|
|
129
|
+
def send_initialize_connection(self, message: InitializeConnection) -> None:
|
|
130
|
+
"""
|
|
131
|
+
Send a message to the websocket connection.
|
|
132
|
+
The message will be sent as a InitializeConnection.
|
|
133
|
+
"""
|
|
134
|
+
self._send_model(message)
|
|
135
|
+
|
|
136
|
+
def send_send_text(self, message: SendText) -> None:
|
|
137
|
+
"""
|
|
138
|
+
Send a message to the websocket connection.
|
|
139
|
+
The message will be sent as a SendText.
|
|
140
|
+
"""
|
|
141
|
+
self._send_model(message)
|
|
142
|
+
|
|
143
|
+
def send_close_connection(self, message: CloseConnection) -> None:
|
|
144
|
+
"""
|
|
145
|
+
Send a message to the websocket connection.
|
|
146
|
+
The message will be sent as a CloseConnection.
|
|
147
|
+
"""
|
|
148
|
+
self._send_model(message)
|
|
149
|
+
|
|
150
|
+
def send_ping_signal(self, message: PingSignal) -> None:
|
|
151
|
+
"""
|
|
152
|
+
Send a message to the websocket connection.
|
|
153
|
+
The message will be sent as a PingSignal.
|
|
154
|
+
"""
|
|
155
|
+
self._send_model(message)
|
|
156
|
+
|
|
157
|
+
def recv(self) -> TextToSpeechStreamingSocketClientResponse:
|
|
158
|
+
"""
|
|
159
|
+
Receive a message from the websocket connection.
|
|
160
|
+
"""
|
|
161
|
+
data = self._websocket.recv()
|
|
162
|
+
data = json.loads(data) if isinstance(data, str) else data
|
|
163
|
+
return parse_obj_as(TextToSpeechStreamingSocketClientResponse, data) # type: ignore
|
|
164
|
+
|
|
165
|
+
def _send(self, data: typing.Any) -> None:
|
|
166
|
+
"""
|
|
167
|
+
Send a message to the websocket connection.
|
|
168
|
+
"""
|
|
169
|
+
if isinstance(data, dict):
|
|
170
|
+
data = json.dumps(data)
|
|
171
|
+
self._websocket.send(data)
|
|
172
|
+
|
|
173
|
+
def _send_model(self, data: typing.Any) -> None:
|
|
174
|
+
"""
|
|
175
|
+
Send a Pydantic model to the websocket connection.
|
|
176
|
+
"""
|
|
177
|
+
self._send(data.dict())
|
sarvamai/types/__init__.py
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
from .audio_data import AudioData
|
|
6
6
|
from .audio_message import AudioMessage
|
|
7
|
-
from .
|
|
8
|
-
from .
|
|
9
|
-
from .bulk_job_init_response_v_1 import BulkJobInitResponseV1
|
|
7
|
+
from .audio_output import AudioOutput
|
|
8
|
+
from .audio_output_data import AudioOutputData
|
|
10
9
|
from .chat_completion_request_assistant_message import ChatCompletionRequestAssistantMessage
|
|
11
10
|
from .chat_completion_request_message import (
|
|
12
11
|
ChatCompletionRequestMessage,
|
|
@@ -18,6 +17,7 @@ from .chat_completion_request_system_message import ChatCompletionRequestSystemM
|
|
|
18
17
|
from .chat_completion_request_user_message import ChatCompletionRequestUserMessage
|
|
19
18
|
from .chat_completion_response_message import ChatCompletionResponseMessage
|
|
20
19
|
from .choice import Choice
|
|
20
|
+
from .close_connection import CloseConnection
|
|
21
21
|
from .completion_usage import CompletionUsage
|
|
22
22
|
from .config_message import ConfigMessage
|
|
23
23
|
from .create_chat_completion_response import CreateChatCompletionResponse
|
|
@@ -27,23 +27,27 @@ from .error_code import ErrorCode
|
|
|
27
27
|
from .error_data import ErrorData
|
|
28
28
|
from .error_details import ErrorDetails
|
|
29
29
|
from .error_message import ErrorMessage
|
|
30
|
+
from .error_response import ErrorResponse
|
|
31
|
+
from .error_response_data import ErrorResponseData
|
|
30
32
|
from .events_data import EventsData
|
|
31
|
-
from .file_signed_url_details import FileSignedUrlDetails
|
|
32
|
-
from .files_download_response import FilesDownloadResponse
|
|
33
|
-
from .files_request import FilesRequest
|
|
34
|
-
from .files_upload_response import FilesUploadResponse
|
|
35
33
|
from .finish_reason import FinishReason
|
|
36
34
|
from .format import Format
|
|
37
|
-
from .
|
|
38
|
-
from .
|
|
35
|
+
from .initialize_connection import InitializeConnection
|
|
36
|
+
from .initialize_connection_data import InitializeConnectionData
|
|
37
|
+
from .initialize_connection_data_model import InitializeConnectionDataModel
|
|
38
|
+
from .initialize_connection_data_output_audio_bitrate import InitializeConnectionDataOutputAudioBitrate
|
|
39
|
+
from .initialize_connection_data_speaker import InitializeConnectionDataSpeaker
|
|
40
|
+
from .initialize_connection_data_target_language_code import InitializeConnectionDataTargetLanguageCode
|
|
39
41
|
from .language_identification_response import LanguageIdentificationResponse
|
|
40
42
|
from .numerals_format import NumeralsFormat
|
|
43
|
+
from .ping_signal import PingSignal
|
|
41
44
|
from .reasoning_effort import ReasoningEffort
|
|
42
45
|
from .response_type import ResponseType
|
|
43
46
|
from .role import Role
|
|
44
47
|
from .sarvam_model_ids import SarvamModelIds
|
|
48
|
+
from .send_text import SendText
|
|
49
|
+
from .send_text_data import SendTextData
|
|
45
50
|
from .speech_sample_rate import SpeechSampleRate
|
|
46
|
-
from .speech_to_text_job_parameters import SpeechToTextJobParameters
|
|
47
51
|
from .speech_to_text_language import SpeechToTextLanguage
|
|
48
52
|
from .speech_to_text_model import SpeechToTextModel
|
|
49
53
|
from .speech_to_text_response import SpeechToTextResponse
|
|
@@ -58,10 +62,6 @@ from .speech_to_text_translate_streaming_response import SpeechToTextTranslateSt
|
|
|
58
62
|
from .speech_to_text_translate_transcription_data import SpeechToTextTranslateTranscriptionData
|
|
59
63
|
from .spoken_form_numerals_format import SpokenFormNumeralsFormat
|
|
60
64
|
from .stop_configuration import StopConfiguration
|
|
61
|
-
from .storage_container_type import StorageContainerType
|
|
62
|
-
from .task_detail_v_1 import TaskDetailV1
|
|
63
|
-
from .task_file_details import TaskFileDetails
|
|
64
|
-
from .task_state import TaskState
|
|
65
65
|
from .text_to_speech_language import TextToSpeechLanguage
|
|
66
66
|
from .text_to_speech_model import TextToSpeechModel
|
|
67
67
|
from .text_to_speech_response import TextToSpeechResponse
|
|
@@ -82,9 +82,8 @@ from .transliteration_response import TransliterationResponse
|
|
|
82
82
|
__all__ = [
|
|
83
83
|
"AudioData",
|
|
84
84
|
"AudioMessage",
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"BulkJobInitResponseV1",
|
|
85
|
+
"AudioOutput",
|
|
86
|
+
"AudioOutputData",
|
|
88
87
|
"ChatCompletionRequestAssistantMessage",
|
|
89
88
|
"ChatCompletionRequestMessage",
|
|
90
89
|
"ChatCompletionRequestMessage_Assistant",
|
|
@@ -94,6 +93,7 @@ __all__ = [
|
|
|
94
93
|
"ChatCompletionRequestUserMessage",
|
|
95
94
|
"ChatCompletionResponseMessage",
|
|
96
95
|
"Choice",
|
|
96
|
+
"CloseConnection",
|
|
97
97
|
"CompletionUsage",
|
|
98
98
|
"ConfigMessage",
|
|
99
99
|
"CreateChatCompletionResponse",
|
|
@@ -103,23 +103,27 @@ __all__ = [
|
|
|
103
103
|
"ErrorData",
|
|
104
104
|
"ErrorDetails",
|
|
105
105
|
"ErrorMessage",
|
|
106
|
+
"ErrorResponse",
|
|
107
|
+
"ErrorResponseData",
|
|
106
108
|
"EventsData",
|
|
107
|
-
"FileSignedUrlDetails",
|
|
108
|
-
"FilesDownloadResponse",
|
|
109
|
-
"FilesRequest",
|
|
110
|
-
"FilesUploadResponse",
|
|
111
109
|
"FinishReason",
|
|
112
110
|
"Format",
|
|
113
|
-
"
|
|
114
|
-
"
|
|
111
|
+
"InitializeConnection",
|
|
112
|
+
"InitializeConnectionData",
|
|
113
|
+
"InitializeConnectionDataModel",
|
|
114
|
+
"InitializeConnectionDataOutputAudioBitrate",
|
|
115
|
+
"InitializeConnectionDataSpeaker",
|
|
116
|
+
"InitializeConnectionDataTargetLanguageCode",
|
|
115
117
|
"LanguageIdentificationResponse",
|
|
116
118
|
"NumeralsFormat",
|
|
119
|
+
"PingSignal",
|
|
117
120
|
"ReasoningEffort",
|
|
118
121
|
"ResponseType",
|
|
119
122
|
"Role",
|
|
120
123
|
"SarvamModelIds",
|
|
124
|
+
"SendText",
|
|
125
|
+
"SendTextData",
|
|
121
126
|
"SpeechSampleRate",
|
|
122
|
-
"SpeechToTextJobParameters",
|
|
123
127
|
"SpeechToTextLanguage",
|
|
124
128
|
"SpeechToTextModel",
|
|
125
129
|
"SpeechToTextResponse",
|
|
@@ -134,10 +138,6 @@ __all__ = [
|
|
|
134
138
|
"SpeechToTextTranslateTranscriptionData",
|
|
135
139
|
"SpokenFormNumeralsFormat",
|
|
136
140
|
"StopConfiguration",
|
|
137
|
-
"StorageContainerType",
|
|
138
|
-
"TaskDetailV1",
|
|
139
|
-
"TaskFileDetails",
|
|
140
|
-
"TaskState",
|
|
141
141
|
"TextToSpeechLanguage",
|
|
142
142
|
"TextToSpeechModel",
|
|
143
143
|
"TextToSpeechResponse",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
from .audio_output_data import AudioOutputData
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AudioOutput(UniversalBaseModel):
|
|
11
|
+
type: typing.Literal["audio"] = "audio"
|
|
12
|
+
data: AudioOutputData
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
16
|
+
else:
|
|
17
|
+
|
|
18
|
+
class Config:
|
|
19
|
+
frozen = True
|
|
20
|
+
smart_union = True
|
|
21
|
+
extra = pydantic.Extra.allow
|
|
@@ -6,15 +6,15 @@ import pydantic
|
|
|
6
6
|
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class
|
|
10
|
-
|
|
9
|
+
class AudioOutputData(UniversalBaseModel):
|
|
10
|
+
content_type: str = pydantic.Field()
|
|
11
11
|
"""
|
|
12
|
-
|
|
12
|
+
MIME type of the audio content (e.g., 'audio/mp3', 'audio/wav')
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
audio: str = pydantic.Field()
|
|
16
16
|
"""
|
|
17
|
-
|
|
17
|
+
Base64-encoded audio data ready for playback or download
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
20
|
if IS_PYDANTIC_V2:
|
|
@@ -6,9 +6,8 @@ import pydantic
|
|
|
6
6
|
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class
|
|
10
|
-
|
|
11
|
-
files: typing.List[str]
|
|
9
|
+
class CloseConnection(UniversalBaseModel):
|
|
10
|
+
type: typing.Literal["flush"] = "flush"
|
|
12
11
|
|
|
13
12
|
if IS_PYDANTIC_V2:
|
|
14
13
|
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
from .error_response_data import ErrorResponseData
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ErrorResponse(UniversalBaseModel):
|
|
11
|
+
type: typing.Literal["error"] = "error"
|
|
12
|
+
data: ErrorResponseData
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
16
|
+
else:
|
|
17
|
+
|
|
18
|
+
class Config:
|
|
19
|
+
frozen = True
|
|
20
|
+
smart_union = True
|
|
21
|
+
extra = pydantic.Extra.allow
|
|
@@ -4,16 +4,19 @@ import typing
|
|
|
4
4
|
|
|
5
5
|
import pydantic
|
|
6
6
|
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
-
from .file_signed_url_details import FileSignedUrlDetails
|
|
8
|
-
from .job_state import JobState
|
|
9
|
-
from .storage_container_type import StorageContainerType
|
|
10
7
|
|
|
11
8
|
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
class ErrorResponseData(UniversalBaseModel):
|
|
10
|
+
message: str
|
|
11
|
+
code: typing.Optional[int] = pydantic.Field(default=None)
|
|
12
|
+
"""
|
|
13
|
+
Optional error code for programmatic error handling
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
details: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(default=None)
|
|
17
|
+
"""
|
|
18
|
+
Additional error details and context information
|
|
19
|
+
"""
|
|
17
20
|
|
|
18
21
|
if IS_PYDANTIC_V2:
|
|
19
22
|
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import pydantic
|
|
6
|
+
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
from .initialize_connection_data import InitializeConnectionData
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class InitializeConnection(UniversalBaseModel):
|
|
11
|
+
type: typing.Literal["config"] = "config"
|
|
12
|
+
data: InitializeConnectionData
|
|
13
|
+
|
|
14
|
+
if IS_PYDANTIC_V2:
|
|
15
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
|
|
16
|
+
else:
|
|
17
|
+
|
|
18
|
+
class Config:
|
|
19
|
+
frozen = True
|
|
20
|
+
smart_union = True
|
|
21
|
+
extra = pydantic.Extra.allow
|