sarvamai 0.1.7__py3-none-any.whl → 0.1.8a0__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 +58 -1
- sarvamai/client.py +3 -0
- sarvamai/core/client_wrapper.py +2 -2
- sarvamai/requests/__init__.py +20 -0
- sarvamai/requests/audio_output.py +11 -0
- sarvamai/requests/audio_output_data.py +15 -0
- sarvamai/requests/close_connection.py +9 -0
- 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/send_text_data.py +7 -0
- sarvamai/text_to_speech_streaming/__init__.py +4 -0
- 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 +175 -0
- sarvamai/types/__init__.py +28 -0
- sarvamai/types/audio_output.py +21 -0
- sarvamai/types/audio_output_data.py +27 -0
- sarvamai/types/close_connection.py +19 -0
- sarvamai/types/error_response.py +21 -0
- sarvamai/types/error_response_data.py +28 -0
- 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/ping_signal.py +19 -0
- sarvamai/types/send_text.py +21 -0
- sarvamai/types/send_text_data.py +19 -0
- {sarvamai-0.1.7.dist-info → sarvamai-0.1.8a0.dist-info}/METADATA +2 -2
- {sarvamai-0.1.7.dist-info → sarvamai-0.1.8a0.dist-info}/RECORD +36 -8
- {sarvamai-0.1.7.dist-info → sarvamai-0.1.8a0.dist-info}/WHEEL +0 -0
sarvamai/__init__.py
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
from .types import (
|
|
6
6
|
AudioData,
|
|
7
7
|
AudioMessage,
|
|
8
|
+
AudioOutput,
|
|
9
|
+
AudioOutputData,
|
|
8
10
|
ChatCompletionRequestAssistantMessage,
|
|
9
11
|
ChatCompletionRequestMessage,
|
|
10
12
|
ChatCompletionRequestMessage_Assistant,
|
|
@@ -14,6 +16,7 @@ from .types import (
|
|
|
14
16
|
ChatCompletionRequestUserMessage,
|
|
15
17
|
ChatCompletionResponseMessage,
|
|
16
18
|
Choice,
|
|
19
|
+
CloseConnection,
|
|
17
20
|
CompletionUsage,
|
|
18
21
|
ConfigMessage,
|
|
19
22
|
CreateChatCompletionResponse,
|
|
@@ -23,15 +26,26 @@ from .types import (
|
|
|
23
26
|
ErrorData,
|
|
24
27
|
ErrorDetails,
|
|
25
28
|
ErrorMessage,
|
|
29
|
+
ErrorResponse,
|
|
30
|
+
ErrorResponseData,
|
|
26
31
|
EventsData,
|
|
27
32
|
FinishReason,
|
|
28
33
|
Format,
|
|
34
|
+
InitializeConnection,
|
|
35
|
+
InitializeConnectionData,
|
|
36
|
+
InitializeConnectionDataModel,
|
|
37
|
+
InitializeConnectionDataOutputAudioBitrate,
|
|
38
|
+
InitializeConnectionDataSpeaker,
|
|
39
|
+
InitializeConnectionDataTargetLanguageCode,
|
|
29
40
|
LanguageIdentificationResponse,
|
|
30
41
|
NumeralsFormat,
|
|
42
|
+
PingSignal,
|
|
31
43
|
ReasoningEffort,
|
|
32
44
|
ResponseType,
|
|
33
45
|
Role,
|
|
34
46
|
SarvamModelIds,
|
|
47
|
+
SendText,
|
|
48
|
+
SendTextData,
|
|
35
49
|
SpeechSampleRate,
|
|
36
50
|
SpeechToTextLanguage,
|
|
37
51
|
SpeechToTextModel,
|
|
@@ -72,12 +86,22 @@ from .errors import (
|
|
|
72
86
|
TooManyRequestsError,
|
|
73
87
|
UnprocessableEntityError,
|
|
74
88
|
)
|
|
75
|
-
from . import
|
|
89
|
+
from . import (
|
|
90
|
+
chat,
|
|
91
|
+
speech_to_text,
|
|
92
|
+
speech_to_text_streaming,
|
|
93
|
+
speech_to_text_translate_streaming,
|
|
94
|
+
text,
|
|
95
|
+
text_to_speech,
|
|
96
|
+
text_to_speech_streaming,
|
|
97
|
+
)
|
|
76
98
|
from .client import AsyncSarvamAI, SarvamAI
|
|
77
99
|
from .environment import SarvamAIEnvironment
|
|
78
100
|
from .requests import (
|
|
79
101
|
AudioDataParams,
|
|
80
102
|
AudioMessageParams,
|
|
103
|
+
AudioOutputDataParams,
|
|
104
|
+
AudioOutputParams,
|
|
81
105
|
ChatCompletionRequestAssistantMessageParams,
|
|
82
106
|
ChatCompletionRequestMessageParams,
|
|
83
107
|
ChatCompletionRequestMessage_AssistantParams,
|
|
@@ -87,6 +111,7 @@ from .requests import (
|
|
|
87
111
|
ChatCompletionRequestUserMessageParams,
|
|
88
112
|
ChatCompletionResponseMessageParams,
|
|
89
113
|
ChoiceParams,
|
|
114
|
+
CloseConnectionParams,
|
|
90
115
|
CompletionUsageParams,
|
|
91
116
|
ConfigMessageParams,
|
|
92
117
|
CreateChatCompletionResponseParams,
|
|
@@ -95,8 +120,15 @@ from .requests import (
|
|
|
95
120
|
ErrorDataParams,
|
|
96
121
|
ErrorDetailsParams,
|
|
97
122
|
ErrorMessageParams,
|
|
123
|
+
ErrorResponseDataParams,
|
|
124
|
+
ErrorResponseParams,
|
|
98
125
|
EventsDataParams,
|
|
126
|
+
InitializeConnectionDataParams,
|
|
127
|
+
InitializeConnectionParams,
|
|
99
128
|
LanguageIdentificationResponseParams,
|
|
129
|
+
PingSignalParams,
|
|
130
|
+
SendTextDataParams,
|
|
131
|
+
SendTextParams,
|
|
100
132
|
SpeechToTextResponseDataParams,
|
|
101
133
|
SpeechToTextResponseParams,
|
|
102
134
|
SpeechToTextStreamingResponseParams,
|
|
@@ -131,6 +163,10 @@ __all__ = [
|
|
|
131
163
|
"AudioDataParams",
|
|
132
164
|
"AudioMessage",
|
|
133
165
|
"AudioMessageParams",
|
|
166
|
+
"AudioOutput",
|
|
167
|
+
"AudioOutputData",
|
|
168
|
+
"AudioOutputDataParams",
|
|
169
|
+
"AudioOutputParams",
|
|
134
170
|
"BadRequestError",
|
|
135
171
|
"ChatCompletionRequestAssistantMessage",
|
|
136
172
|
"ChatCompletionRequestAssistantMessageParams",
|
|
@@ -150,6 +186,8 @@ __all__ = [
|
|
|
150
186
|
"ChatCompletionResponseMessageParams",
|
|
151
187
|
"Choice",
|
|
152
188
|
"ChoiceParams",
|
|
189
|
+
"CloseConnection",
|
|
190
|
+
"CloseConnectionParams",
|
|
153
191
|
"CompletionUsage",
|
|
154
192
|
"CompletionUsageParams",
|
|
155
193
|
"ConfigMessage",
|
|
@@ -167,21 +205,39 @@ __all__ = [
|
|
|
167
205
|
"ErrorDetailsParams",
|
|
168
206
|
"ErrorMessage",
|
|
169
207
|
"ErrorMessageParams",
|
|
208
|
+
"ErrorResponse",
|
|
209
|
+
"ErrorResponseData",
|
|
210
|
+
"ErrorResponseDataParams",
|
|
211
|
+
"ErrorResponseParams",
|
|
170
212
|
"EventsData",
|
|
171
213
|
"EventsDataParams",
|
|
172
214
|
"FinishReason",
|
|
173
215
|
"ForbiddenError",
|
|
174
216
|
"Format",
|
|
217
|
+
"InitializeConnection",
|
|
218
|
+
"InitializeConnectionData",
|
|
219
|
+
"InitializeConnectionDataModel",
|
|
220
|
+
"InitializeConnectionDataOutputAudioBitrate",
|
|
221
|
+
"InitializeConnectionDataParams",
|
|
222
|
+
"InitializeConnectionDataSpeaker",
|
|
223
|
+
"InitializeConnectionDataTargetLanguageCode",
|
|
224
|
+
"InitializeConnectionParams",
|
|
175
225
|
"InternalServerError",
|
|
176
226
|
"LanguageIdentificationResponse",
|
|
177
227
|
"LanguageIdentificationResponseParams",
|
|
178
228
|
"NumeralsFormat",
|
|
229
|
+
"PingSignal",
|
|
230
|
+
"PingSignalParams",
|
|
179
231
|
"ReasoningEffort",
|
|
180
232
|
"ResponseType",
|
|
181
233
|
"Role",
|
|
182
234
|
"SarvamAI",
|
|
183
235
|
"SarvamAIEnvironment",
|
|
184
236
|
"SarvamModelIds",
|
|
237
|
+
"SendText",
|
|
238
|
+
"SendTextData",
|
|
239
|
+
"SendTextDataParams",
|
|
240
|
+
"SendTextParams",
|
|
185
241
|
"ServiceUnavailableError",
|
|
186
242
|
"SpeechSampleRate",
|
|
187
243
|
"SpeechToTextLanguage",
|
|
@@ -244,4 +300,5 @@ __all__ = [
|
|
|
244
300
|
"speech_to_text_translate_streaming",
|
|
245
301
|
"text",
|
|
246
302
|
"text_to_speech",
|
|
303
|
+
"text_to_speech_streaming",
|
|
247
304
|
]
|
sarvamai/client.py
CHANGED
|
@@ -16,6 +16,7 @@ from .speech_to_text_translate_streaming.client import (
|
|
|
16
16
|
)
|
|
17
17
|
from .text.client import AsyncTextClient, TextClient
|
|
18
18
|
from .text_to_speech.client import AsyncTextToSpeechClient, TextToSpeechClient
|
|
19
|
+
from .text_to_speech_streaming.client import AsyncTextToSpeechStreamingClient, TextToSpeechStreamingClient
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
class SarvamAI:
|
|
@@ -86,6 +87,7 @@ class SarvamAI:
|
|
|
86
87
|
self.speech_to_text_translate_streaming = SpeechToTextTranslateStreamingClient(
|
|
87
88
|
client_wrapper=self._client_wrapper
|
|
88
89
|
)
|
|
90
|
+
self.text_to_speech_streaming = TextToSpeechStreamingClient(client_wrapper=self._client_wrapper)
|
|
89
91
|
|
|
90
92
|
|
|
91
93
|
class AsyncSarvamAI:
|
|
@@ -156,3 +158,4 @@ class AsyncSarvamAI:
|
|
|
156
158
|
self.speech_to_text_translate_streaming = AsyncSpeechToTextTranslateStreamingClient(
|
|
157
159
|
client_wrapper=self._client_wrapper
|
|
158
160
|
)
|
|
161
|
+
self.text_to_speech_streaming = AsyncTextToSpeechStreamingClient(client_wrapper=self._client_wrapper)
|
sarvamai/core/client_wrapper.py
CHANGED
|
@@ -17,10 +17,10 @@ class BaseClientWrapper:
|
|
|
17
17
|
|
|
18
18
|
def get_headers(self) -> typing.Dict[str, str]:
|
|
19
19
|
headers: typing.Dict[str, str] = {
|
|
20
|
-
"User-Agent": "sarvamai/0.1.
|
|
20
|
+
"User-Agent": "sarvamai/0.1.8a0",
|
|
21
21
|
"X-Fern-Language": "Python",
|
|
22
22
|
"X-Fern-SDK-Name": "sarvamai",
|
|
23
|
-
"X-Fern-SDK-Version": "0.1.
|
|
23
|
+
"X-Fern-SDK-Version": "0.1.8a0",
|
|
24
24
|
}
|
|
25
25
|
headers["api-subscription-key"] = self.api_subscription_key
|
|
26
26
|
return headers
|
sarvamai/requests/__init__.py
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
from .audio_data import AudioDataParams
|
|
6
6
|
from .audio_message import AudioMessageParams
|
|
7
|
+
from .audio_output import AudioOutputParams
|
|
8
|
+
from .audio_output_data import AudioOutputDataParams
|
|
7
9
|
from .chat_completion_request_assistant_message import ChatCompletionRequestAssistantMessageParams
|
|
8
10
|
from .chat_completion_request_message import (
|
|
9
11
|
ChatCompletionRequestMessageParams,
|
|
@@ -15,6 +17,7 @@ from .chat_completion_request_system_message import ChatCompletionRequestSystemM
|
|
|
15
17
|
from .chat_completion_request_user_message import ChatCompletionRequestUserMessageParams
|
|
16
18
|
from .chat_completion_response_message import ChatCompletionResponseMessageParams
|
|
17
19
|
from .choice import ChoiceParams
|
|
20
|
+
from .close_connection import CloseConnectionParams
|
|
18
21
|
from .completion_usage import CompletionUsageParams
|
|
19
22
|
from .config_message import ConfigMessageParams
|
|
20
23
|
from .create_chat_completion_response import CreateChatCompletionResponseParams
|
|
@@ -23,8 +26,15 @@ from .diarized_transcript import DiarizedTranscriptParams
|
|
|
23
26
|
from .error_data import ErrorDataParams
|
|
24
27
|
from .error_details import ErrorDetailsParams
|
|
25
28
|
from .error_message import ErrorMessageParams
|
|
29
|
+
from .error_response import ErrorResponseParams
|
|
30
|
+
from .error_response_data import ErrorResponseDataParams
|
|
26
31
|
from .events_data import EventsDataParams
|
|
32
|
+
from .initialize_connection import InitializeConnectionParams
|
|
33
|
+
from .initialize_connection_data import InitializeConnectionDataParams
|
|
27
34
|
from .language_identification_response import LanguageIdentificationResponseParams
|
|
35
|
+
from .ping_signal import PingSignalParams
|
|
36
|
+
from .send_text import SendTextParams
|
|
37
|
+
from .send_text_data import SendTextDataParams
|
|
28
38
|
from .speech_to_text_response import SpeechToTextResponseParams
|
|
29
39
|
from .speech_to_text_response_data import SpeechToTextResponseDataParams
|
|
30
40
|
from .speech_to_text_streaming_response import SpeechToTextStreamingResponseParams
|
|
@@ -43,6 +53,8 @@ from .transliteration_response import TransliterationResponseParams
|
|
|
43
53
|
__all__ = [
|
|
44
54
|
"AudioDataParams",
|
|
45
55
|
"AudioMessageParams",
|
|
56
|
+
"AudioOutputDataParams",
|
|
57
|
+
"AudioOutputParams",
|
|
46
58
|
"ChatCompletionRequestAssistantMessageParams",
|
|
47
59
|
"ChatCompletionRequestMessageParams",
|
|
48
60
|
"ChatCompletionRequestMessage_AssistantParams",
|
|
@@ -52,6 +64,7 @@ __all__ = [
|
|
|
52
64
|
"ChatCompletionRequestUserMessageParams",
|
|
53
65
|
"ChatCompletionResponseMessageParams",
|
|
54
66
|
"ChoiceParams",
|
|
67
|
+
"CloseConnectionParams",
|
|
55
68
|
"CompletionUsageParams",
|
|
56
69
|
"ConfigMessageParams",
|
|
57
70
|
"CreateChatCompletionResponseParams",
|
|
@@ -60,8 +73,15 @@ __all__ = [
|
|
|
60
73
|
"ErrorDataParams",
|
|
61
74
|
"ErrorDetailsParams",
|
|
62
75
|
"ErrorMessageParams",
|
|
76
|
+
"ErrorResponseDataParams",
|
|
77
|
+
"ErrorResponseParams",
|
|
63
78
|
"EventsDataParams",
|
|
79
|
+
"InitializeConnectionDataParams",
|
|
80
|
+
"InitializeConnectionParams",
|
|
64
81
|
"LanguageIdentificationResponseParams",
|
|
82
|
+
"PingSignalParams",
|
|
83
|
+
"SendTextDataParams",
|
|
84
|
+
"SendTextParams",
|
|
65
85
|
"SpeechToTextResponseDataParams",
|
|
66
86
|
"SpeechToTextResponseParams",
|
|
67
87
|
"SpeechToTextStreamingResponseParams",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import typing_extensions
|
|
6
|
+
from .audio_output_data import AudioOutputDataParams
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AudioOutputParams(typing_extensions.TypedDict):
|
|
10
|
+
type: typing.Literal["audio"]
|
|
11
|
+
data: AudioOutputDataParams
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing_extensions
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AudioOutputDataParams(typing_extensions.TypedDict):
|
|
7
|
+
content_type: str
|
|
8
|
+
"""
|
|
9
|
+
MIME type of the audio content (e.g., 'audio/mp3', 'audio/wav')
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
audio: str
|
|
13
|
+
"""
|
|
14
|
+
Base64-encoded audio data ready for playback or download
|
|
15
|
+
"""
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import typing_extensions
|
|
6
|
+
from .error_response_data import ErrorResponseDataParams
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ErrorResponseParams(typing_extensions.TypedDict):
|
|
10
|
+
type: typing.Literal["error"]
|
|
11
|
+
data: ErrorResponseDataParams
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import typing_extensions
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ErrorResponseDataParams(typing_extensions.TypedDict):
|
|
9
|
+
message: str
|
|
10
|
+
code: typing_extensions.NotRequired[int]
|
|
11
|
+
"""
|
|
12
|
+
Optional error code for programmatic error handling
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
details: typing_extensions.NotRequired[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
16
|
+
"""
|
|
17
|
+
Additional error details and context information
|
|
18
|
+
"""
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import typing_extensions
|
|
6
|
+
from .initialize_connection_data import InitializeConnectionDataParams
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class InitializeConnectionParams(typing_extensions.TypedDict):
|
|
10
|
+
type: typing.Literal["config"]
|
|
11
|
+
data: InitializeConnectionDataParams
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import typing_extensions
|
|
6
|
+
from ..types.initialize_connection_data_model import InitializeConnectionDataModel
|
|
7
|
+
from ..types.initialize_connection_data_output_audio_bitrate import InitializeConnectionDataOutputAudioBitrate
|
|
8
|
+
from ..types.initialize_connection_data_speaker import InitializeConnectionDataSpeaker
|
|
9
|
+
from ..types.initialize_connection_data_target_language_code import InitializeConnectionDataTargetLanguageCode
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class InitializeConnectionDataParams(typing_extensions.TypedDict):
|
|
13
|
+
target_language_code: InitializeConnectionDataTargetLanguageCode
|
|
14
|
+
speaker: InitializeConnectionDataSpeaker
|
|
15
|
+
pitch: typing_extensions.NotRequired[float]
|
|
16
|
+
pace: typing_extensions.NotRequired[float]
|
|
17
|
+
loudness: typing_extensions.NotRequired[float]
|
|
18
|
+
speech_sample_rate: typing_extensions.NotRequired[int]
|
|
19
|
+
enable_preprocessing: typing_extensions.NotRequired[bool]
|
|
20
|
+
model: InitializeConnectionDataModel
|
|
21
|
+
output_audio_codec: typing_extensions.NotRequired[typing.Literal["mp3"]]
|
|
22
|
+
output_audio_bitrate: typing_extensions.NotRequired[InitializeConnectionDataOutputAudioBitrate]
|
|
23
|
+
min_buffer_size: typing_extensions.NotRequired[int]
|
|
24
|
+
max_chunk_length: typing_extensions.NotRequired[int]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import typing_extensions
|
|
6
|
+
from .send_text_data import SendTextDataParams
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SendTextParams(typing_extensions.TypedDict):
|
|
10
|
+
type: typing.Literal["text"]
|
|
11
|
+
data: SendTextDataParams
|
|
@@ -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
|
+
)
|