speechify-api 0.0.145__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.
Files changed (73) hide show
  1. speechify_api-0.0.145.dist-info/METADATA +167 -0
  2. speechify_api-0.0.145.dist-info/RECORD +73 -0
  3. speechify_api-0.0.145.dist-info/WHEEL +4 -0
  4. speechifyinc/__init__.py +17 -0
  5. speechifyinc/api/__init__.py +5 -0
  6. speechifyinc/api/types/__init__.py +5 -0
  7. speechifyinc/api/types/audio_stream_request_accept.py +5 -0
  8. speechifyinc/client.py +150 -0
  9. speechifyinc/core/__init__.py +47 -0
  10. speechifyinc/core/api_error.py +15 -0
  11. speechifyinc/core/client_wrapper.py +76 -0
  12. speechifyinc/core/datetime_utils.py +28 -0
  13. speechifyinc/core/file.py +67 -0
  14. speechifyinc/core/http_client.py +499 -0
  15. speechifyinc/core/jsonable_encoder.py +101 -0
  16. speechifyinc/core/pydantic_utilities.py +296 -0
  17. speechifyinc/core/query_encoder.py +58 -0
  18. speechifyinc/core/remove_none_from_dict.py +11 -0
  19. speechifyinc/core/request_options.py +35 -0
  20. speechifyinc/core/serialization.py +272 -0
  21. speechifyinc/environment.py +7 -0
  22. speechifyinc/py.typed +0 -0
  23. speechifyinc/tts/__init__.py +78 -0
  24. speechifyinc/tts/audio/__init__.py +5 -0
  25. speechifyinc/tts/audio/client.py +544 -0
  26. speechifyinc/tts/audio/types/__init__.py +8 -0
  27. speechifyinc/tts/audio/types/audio_stream_request_accept.py +5 -0
  28. speechifyinc/tts/audio/types/get_speech_request_audio_format.py +5 -0
  29. speechifyinc/tts/audio/types/get_speech_request_model.py +7 -0
  30. speechifyinc/tts/audio/types/get_stream_request_model.py +7 -0
  31. speechifyinc/tts/auth/__init__.py +5 -0
  32. speechifyinc/tts/auth/client.py +171 -0
  33. speechifyinc/tts/auth/types/__init__.py +5 -0
  34. speechifyinc/tts/auth/types/create_access_token_request_scope.py +10 -0
  35. speechifyinc/tts/client.py +26 -0
  36. speechifyinc/tts/errors/__init__.py +9 -0
  37. speechifyinc/tts/errors/bad_request_error.py +9 -0
  38. speechifyinc/tts/errors/forbidden_error.py +9 -0
  39. speechifyinc/tts/errors/internal_server_error.py +9 -0
  40. speechifyinc/tts/errors/not_found_error.py +9 -0
  41. speechifyinc/tts/errors/payment_required_error.py +9 -0
  42. speechifyinc/tts/types/__init__.py +57 -0
  43. speechifyinc/tts/types/access_token.py +34 -0
  44. speechifyinc/tts/types/access_token_scope.py +10 -0
  45. speechifyinc/tts/types/api_key.py +47 -0
  46. speechifyinc/tts/types/create_voice_language.py +20 -0
  47. speechifyinc/tts/types/create_voice_model.py +22 -0
  48. speechifyinc/tts/types/create_voice_model_name.py +7 -0
  49. speechifyinc/tts/types/created_voice.py +28 -0
  50. speechifyinc/tts/types/created_voice_gender.py +5 -0
  51. speechifyinc/tts/types/created_voice_type.py +5 -0
  52. speechifyinc/tts/types/experimental_stream_request.py +49 -0
  53. speechifyinc/tts/types/experimental_stream_request_model.py +7 -0
  54. speechifyinc/tts/types/experimental_stream_response.py +33 -0
  55. speechifyinc/tts/types/get_speech_options_request.py +32 -0
  56. speechifyinc/tts/types/get_speech_response.py +36 -0
  57. speechifyinc/tts/types/get_speech_response_audio_format.py +5 -0
  58. speechifyinc/tts/types/get_stream_options_request.py +32 -0
  59. speechifyinc/tts/types/get_voice.py +30 -0
  60. speechifyinc/tts/types/get_voice_gender.py +5 -0
  61. speechifyinc/tts/types/get_voice_language.py +20 -0
  62. speechifyinc/tts/types/get_voice_type.py +5 -0
  63. speechifyinc/tts/types/get_voices_model.py +22 -0
  64. speechifyinc/tts/types/get_voices_model_name.py +7 -0
  65. speechifyinc/tts/types/nested_chunk.py +28 -0
  66. speechifyinc/tts/types/o_auth_error.py +21 -0
  67. speechifyinc/tts/types/o_auth_error_error.py +10 -0
  68. speechifyinc/tts/types/speech_marks.py +34 -0
  69. speechifyinc/tts/voices/__init__.py +5 -0
  70. speechifyinc/tts/voices/client.py +559 -0
  71. speechifyinc/tts/voices/types/__init__.py +5 -0
  72. speechifyinc/tts/voices/types/voices_create_request_gender.py +5 -0
  73. speechifyinc/version.py +3 -0
@@ -0,0 +1,78 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .types import (
4
+ AccessToken,
5
+ AccessTokenScope,
6
+ ApiKey,
7
+ CreateVoiceLanguage,
8
+ CreateVoiceModel,
9
+ CreateVoiceModelName,
10
+ CreatedVoice,
11
+ CreatedVoiceGender,
12
+ CreatedVoiceType,
13
+ ExperimentalStreamRequest,
14
+ ExperimentalStreamRequestModel,
15
+ ExperimentalStreamResponse,
16
+ GetSpeechOptionsRequest,
17
+ GetSpeechResponse,
18
+ GetSpeechResponseAudioFormat,
19
+ GetStreamOptionsRequest,
20
+ GetVoice,
21
+ GetVoiceGender,
22
+ GetVoiceLanguage,
23
+ GetVoiceType,
24
+ GetVoicesModel,
25
+ GetVoicesModelName,
26
+ NestedChunk,
27
+ OAuthError,
28
+ OAuthErrorError,
29
+ SpeechMarks,
30
+ )
31
+ from .errors import BadRequestError, ForbiddenError, InternalServerError, NotFoundError, PaymentRequiredError
32
+ from . import audio, auth, voices
33
+ from .audio import AudioStreamRequestAccept, GetSpeechRequestAudioFormat, GetSpeechRequestModel, GetStreamRequestModel
34
+ from .auth import CreateAccessTokenRequestScope
35
+ from .voices import VoicesCreateRequestGender
36
+
37
+ __all__ = [
38
+ "AccessToken",
39
+ "AccessTokenScope",
40
+ "ApiKey",
41
+ "AudioStreamRequestAccept",
42
+ "BadRequestError",
43
+ "CreateAccessTokenRequestScope",
44
+ "CreateVoiceLanguage",
45
+ "CreateVoiceModel",
46
+ "CreateVoiceModelName",
47
+ "CreatedVoice",
48
+ "CreatedVoiceGender",
49
+ "CreatedVoiceType",
50
+ "ExperimentalStreamRequest",
51
+ "ExperimentalStreamRequestModel",
52
+ "ExperimentalStreamResponse",
53
+ "ForbiddenError",
54
+ "GetSpeechOptionsRequest",
55
+ "GetSpeechRequestAudioFormat",
56
+ "GetSpeechRequestModel",
57
+ "GetSpeechResponse",
58
+ "GetSpeechResponseAudioFormat",
59
+ "GetStreamOptionsRequest",
60
+ "GetStreamRequestModel",
61
+ "GetVoice",
62
+ "GetVoiceGender",
63
+ "GetVoiceLanguage",
64
+ "GetVoiceType",
65
+ "GetVoicesModel",
66
+ "GetVoicesModelName",
67
+ "InternalServerError",
68
+ "NestedChunk",
69
+ "NotFoundError",
70
+ "OAuthError",
71
+ "OAuthErrorError",
72
+ "PaymentRequiredError",
73
+ "SpeechMarks",
74
+ "VoicesCreateRequestGender",
75
+ "audio",
76
+ "auth",
77
+ "voices",
78
+ ]
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .types import AudioStreamRequestAccept, GetSpeechRequestAudioFormat, GetSpeechRequestModel, GetStreamRequestModel
4
+
5
+ __all__ = ["AudioStreamRequestAccept", "GetSpeechRequestAudioFormat", "GetSpeechRequestModel", "GetStreamRequestModel"]
@@ -0,0 +1,544 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from ...core.client_wrapper import SyncClientWrapper
5
+ from .types.get_speech_request_audio_format import GetSpeechRequestAudioFormat
6
+ from .types.get_speech_request_model import GetSpeechRequestModel
7
+ from ..types.get_speech_options_request import GetSpeechOptionsRequest
8
+ from ...core.request_options import RequestOptions
9
+ from ..types.get_speech_response import GetSpeechResponse
10
+ from ...core.serialization import convert_and_respect_annotation_metadata
11
+ from ...core.pydantic_utilities import parse_obj_as
12
+ from ..errors.bad_request_error import BadRequestError
13
+ from ..errors.payment_required_error import PaymentRequiredError
14
+ from ..errors.forbidden_error import ForbiddenError
15
+ from ..errors.internal_server_error import InternalServerError
16
+ from json.decoder import JSONDecodeError
17
+ from ...core.api_error import ApiError
18
+ from .types.audio_stream_request_accept import AudioStreamRequestAccept
19
+ from .types.get_stream_request_model import GetStreamRequestModel
20
+ from ..types.get_stream_options_request import GetStreamOptionsRequest
21
+ from ...core.client_wrapper import AsyncClientWrapper
22
+
23
+ # this is used as the default value for optional parameters
24
+ OMIT = typing.cast(typing.Any, ...)
25
+
26
+
27
+ class AudioClient:
28
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
29
+ self._client_wrapper = client_wrapper
30
+
31
+ def speech(
32
+ self,
33
+ *,
34
+ input: str,
35
+ voice_id: str,
36
+ audio_format: typing.Optional[GetSpeechRequestAudioFormat] = OMIT,
37
+ language: typing.Optional[str] = OMIT,
38
+ model: typing.Optional[GetSpeechRequestModel] = OMIT,
39
+ options: typing.Optional[GetSpeechOptionsRequest] = OMIT,
40
+ request_options: typing.Optional[RequestOptions] = None,
41
+ ) -> GetSpeechResponse:
42
+ """
43
+ Gets the speech data for the given input
44
+
45
+ Parameters
46
+ ----------
47
+ input : str
48
+ Plain text or SSML to be synthesized to speech.
49
+ Refer to https://docs.sws.speechify.com/docs/api-limits for the input size limits.
50
+ Emotion, Pitch and Speed Rate are configured in the ssml input, please refer to the ssml documentation for more information: https://docs.sws.speechify.com/docs/ssml#prosody
51
+
52
+ voice_id : str
53
+ Id of the voice to be used for synthesizing speech. Refer to /v1/voices endpoint for available voices
54
+
55
+ audio_format : typing.Optional[GetSpeechRequestAudioFormat]
56
+ The format for the output audio. Note, that the current default is "wav", but there's no guarantee it will not change in the future. We recommend always passing the specific param you expect.
57
+
58
+ language : typing.Optional[str]
59
+ Language of the input. Follow the format of an ISO 639-1 language code and an ISO 3166-1 region code, separated by a hyphen, e.g. en-US.
60
+ Please refer to the list of the supported languages and recommendations regarding this parameter: https://docs.sws.speechify.com/docs/language-support.
61
+
62
+ model : typing.Optional[GetSpeechRequestModel]
63
+ Model used for audio synthesis
64
+ simba-base ModelBase ModelBase is deprecated. Use simba-english or simba-multilingual instead. @deprecated
65
+ simba-english ModelEnglish
66
+ simba-multilingual ModelMultilingual
67
+ simba-turbo ModelTurbo
68
+
69
+ options : typing.Optional[GetSpeechOptionsRequest]
70
+
71
+ request_options : typing.Optional[RequestOptions]
72
+ Request-specific configuration.
73
+
74
+ Returns
75
+ -------
76
+ GetSpeechResponse
77
+
78
+
79
+ Examples
80
+ --------
81
+ from speechifyinc import Speechify
82
+
83
+ client = Speechify(
84
+ token="YOUR_TOKEN",
85
+ )
86
+ client.tts.audio.speech(
87
+ input="input",
88
+ voice_id="voice_id",
89
+ )
90
+ """
91
+ _response = self._client_wrapper.httpx_client.request(
92
+ "v1/audio/speech",
93
+ method="POST",
94
+ json={
95
+ "audio_format": audio_format,
96
+ "input": input,
97
+ "language": language,
98
+ "model": model,
99
+ "options": convert_and_respect_annotation_metadata(
100
+ object_=options, annotation=GetSpeechOptionsRequest, direction="write"
101
+ ),
102
+ "voice_id": voice_id,
103
+ },
104
+ headers={
105
+ "content-type": "application/json",
106
+ },
107
+ request_options=request_options,
108
+ omit=OMIT,
109
+ )
110
+ try:
111
+ if 200 <= _response.status_code < 300:
112
+ return typing.cast(
113
+ GetSpeechResponse,
114
+ parse_obj_as(
115
+ type_=GetSpeechResponse, # type: ignore
116
+ object_=_response.json(),
117
+ ),
118
+ )
119
+ if _response.status_code == 400:
120
+ raise BadRequestError(
121
+ typing.cast(
122
+ typing.Optional[typing.Any],
123
+ parse_obj_as(
124
+ type_=typing.Optional[typing.Any], # type: ignore
125
+ object_=_response.json(),
126
+ ),
127
+ )
128
+ )
129
+ if _response.status_code == 402:
130
+ raise PaymentRequiredError(
131
+ typing.cast(
132
+ typing.Optional[typing.Any],
133
+ parse_obj_as(
134
+ type_=typing.Optional[typing.Any], # type: ignore
135
+ object_=_response.json(),
136
+ ),
137
+ )
138
+ )
139
+ if _response.status_code == 403:
140
+ raise ForbiddenError(
141
+ typing.cast(
142
+ typing.Optional[typing.Any],
143
+ parse_obj_as(
144
+ type_=typing.Optional[typing.Any], # type: ignore
145
+ object_=_response.json(),
146
+ ),
147
+ )
148
+ )
149
+ if _response.status_code == 500:
150
+ raise InternalServerError(
151
+ typing.cast(
152
+ typing.Optional[typing.Any],
153
+ parse_obj_as(
154
+ type_=typing.Optional[typing.Any], # type: ignore
155
+ object_=_response.json(),
156
+ ),
157
+ )
158
+ )
159
+ _response_json = _response.json()
160
+ except JSONDecodeError:
161
+ raise ApiError(status_code=_response.status_code, body=_response.text)
162
+ raise ApiError(status_code=_response.status_code, body=_response_json)
163
+
164
+ def stream(
165
+ self,
166
+ *,
167
+ accept: AudioStreamRequestAccept,
168
+ input: str,
169
+ voice_id: str,
170
+ language: typing.Optional[str] = OMIT,
171
+ model: typing.Optional[GetStreamRequestModel] = OMIT,
172
+ options: typing.Optional[GetStreamOptionsRequest] = OMIT,
173
+ request_options: typing.Optional[RequestOptions] = None,
174
+ ) -> typing.Iterator[bytes]:
175
+ """
176
+ Gets the stream speech for the given input
177
+
178
+ Parameters
179
+ ----------
180
+ accept : AudioStreamRequestAccept
181
+
182
+ input : str
183
+ Plain text or SSML to be synthesized to speech.
184
+ Refer to https://docs.sws.speechify.com/docs/api-limits for the input size limits.
185
+ Emotion, Pitch and Speed Rate are configured in the ssml input, please refer to the ssml documentation for more information: https://docs.sws.speechify.com/docs/ssml#prosody
186
+
187
+ voice_id : str
188
+ Id of the voice to be used for synthesizing speech. Refer to /v1/voices endpoint for available voices
189
+
190
+ language : typing.Optional[str]
191
+ Language of the input. Follow the format of an ISO 639-1 language code and an ISO 3166-1 region code, separated by a hyphen, e.g. en-US.
192
+ Please refer to the list of the supported languages and recommendations regarding this parameter: https://docs.sws.speechify.com/docs/language-support.
193
+
194
+ model : typing.Optional[GetStreamRequestModel]
195
+ Model used for audio synthesis
196
+ simba-base ModelBase ModelBase is deprecated. Use simba-english or simba-multilingual instead. @deprecated
197
+ simba-english ModelEnglish
198
+ simba-multilingual ModelMultilingual
199
+ simba-turbo ModelTurbo
200
+
201
+ options : typing.Optional[GetStreamOptionsRequest]
202
+
203
+ request_options : typing.Optional[RequestOptions]
204
+ Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
205
+
206
+ Yields
207
+ ------
208
+ typing.Iterator[bytes]
209
+
210
+ """
211
+ with self._client_wrapper.httpx_client.stream(
212
+ "v1/audio/stream",
213
+ method="POST",
214
+ json={
215
+ "input": input,
216
+ "language": language,
217
+ "model": model,
218
+ "options": convert_and_respect_annotation_metadata(
219
+ object_=options, annotation=GetStreamOptionsRequest, direction="write"
220
+ ),
221
+ "voice_id": voice_id,
222
+ },
223
+ headers={
224
+ "content-type": "application/json",
225
+ "Accept": str(accept) if accept is not None else None,
226
+ },
227
+ request_options=request_options,
228
+ omit=OMIT,
229
+ ) as _response:
230
+ try:
231
+ if 200 <= _response.status_code < 300:
232
+ _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
233
+ for _chunk in _response.iter_bytes(chunk_size=_chunk_size):
234
+ yield _chunk
235
+ return
236
+ _response.read()
237
+ if _response.status_code == 400:
238
+ raise BadRequestError(
239
+ typing.cast(
240
+ typing.Optional[typing.Any],
241
+ parse_obj_as(
242
+ type_=typing.Optional[typing.Any], # type: ignore
243
+ object_=_response.json(),
244
+ ),
245
+ )
246
+ )
247
+ if _response.status_code == 402:
248
+ raise PaymentRequiredError(
249
+ typing.cast(
250
+ typing.Optional[typing.Any],
251
+ parse_obj_as(
252
+ type_=typing.Optional[typing.Any], # type: ignore
253
+ object_=_response.json(),
254
+ ),
255
+ )
256
+ )
257
+ if _response.status_code == 403:
258
+ raise ForbiddenError(
259
+ typing.cast(
260
+ typing.Optional[typing.Any],
261
+ parse_obj_as(
262
+ type_=typing.Optional[typing.Any], # type: ignore
263
+ object_=_response.json(),
264
+ ),
265
+ )
266
+ )
267
+ if _response.status_code == 500:
268
+ raise InternalServerError(
269
+ typing.cast(
270
+ typing.Optional[typing.Any],
271
+ parse_obj_as(
272
+ type_=typing.Optional[typing.Any], # type: ignore
273
+ object_=_response.json(),
274
+ ),
275
+ )
276
+ )
277
+ _response_json = _response.json()
278
+ except JSONDecodeError:
279
+ raise ApiError(status_code=_response.status_code, body=_response.text)
280
+ raise ApiError(status_code=_response.status_code, body=_response_json)
281
+
282
+
283
+ class AsyncAudioClient:
284
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
285
+ self._client_wrapper = client_wrapper
286
+
287
+ async def speech(
288
+ self,
289
+ *,
290
+ input: str,
291
+ voice_id: str,
292
+ audio_format: typing.Optional[GetSpeechRequestAudioFormat] = OMIT,
293
+ language: typing.Optional[str] = OMIT,
294
+ model: typing.Optional[GetSpeechRequestModel] = OMIT,
295
+ options: typing.Optional[GetSpeechOptionsRequest] = OMIT,
296
+ request_options: typing.Optional[RequestOptions] = None,
297
+ ) -> GetSpeechResponse:
298
+ """
299
+ Gets the speech data for the given input
300
+
301
+ Parameters
302
+ ----------
303
+ input : str
304
+ Plain text or SSML to be synthesized to speech.
305
+ Refer to https://docs.sws.speechify.com/docs/api-limits for the input size limits.
306
+ Emotion, Pitch and Speed Rate are configured in the ssml input, please refer to the ssml documentation for more information: https://docs.sws.speechify.com/docs/ssml#prosody
307
+
308
+ voice_id : str
309
+ Id of the voice to be used for synthesizing speech. Refer to /v1/voices endpoint for available voices
310
+
311
+ audio_format : typing.Optional[GetSpeechRequestAudioFormat]
312
+ The format for the output audio. Note, that the current default is "wav", but there's no guarantee it will not change in the future. We recommend always passing the specific param you expect.
313
+
314
+ language : typing.Optional[str]
315
+ Language of the input. Follow the format of an ISO 639-1 language code and an ISO 3166-1 region code, separated by a hyphen, e.g. en-US.
316
+ Please refer to the list of the supported languages and recommendations regarding this parameter: https://docs.sws.speechify.com/docs/language-support.
317
+
318
+ model : typing.Optional[GetSpeechRequestModel]
319
+ Model used for audio synthesis
320
+ simba-base ModelBase ModelBase is deprecated. Use simba-english or simba-multilingual instead. @deprecated
321
+ simba-english ModelEnglish
322
+ simba-multilingual ModelMultilingual
323
+ simba-turbo ModelTurbo
324
+
325
+ options : typing.Optional[GetSpeechOptionsRequest]
326
+
327
+ request_options : typing.Optional[RequestOptions]
328
+ Request-specific configuration.
329
+
330
+ Returns
331
+ -------
332
+ GetSpeechResponse
333
+
334
+
335
+ Examples
336
+ --------
337
+ import asyncio
338
+
339
+ from speechifyinc import AsyncSpeechify
340
+
341
+ client = AsyncSpeechify(
342
+ token="YOUR_TOKEN",
343
+ )
344
+
345
+
346
+ async def main() -> None:
347
+ await client.tts.audio.speech(
348
+ input="input",
349
+ voice_id="voice_id",
350
+ )
351
+
352
+
353
+ asyncio.run(main())
354
+ """
355
+ _response = await self._client_wrapper.httpx_client.request(
356
+ "v1/audio/speech",
357
+ method="POST",
358
+ json={
359
+ "audio_format": audio_format,
360
+ "input": input,
361
+ "language": language,
362
+ "model": model,
363
+ "options": convert_and_respect_annotation_metadata(
364
+ object_=options, annotation=GetSpeechOptionsRequest, direction="write"
365
+ ),
366
+ "voice_id": voice_id,
367
+ },
368
+ headers={
369
+ "content-type": "application/json",
370
+ },
371
+ request_options=request_options,
372
+ omit=OMIT,
373
+ )
374
+ try:
375
+ if 200 <= _response.status_code < 300:
376
+ return typing.cast(
377
+ GetSpeechResponse,
378
+ parse_obj_as(
379
+ type_=GetSpeechResponse, # type: ignore
380
+ object_=_response.json(),
381
+ ),
382
+ )
383
+ if _response.status_code == 400:
384
+ raise BadRequestError(
385
+ typing.cast(
386
+ typing.Optional[typing.Any],
387
+ parse_obj_as(
388
+ type_=typing.Optional[typing.Any], # type: ignore
389
+ object_=_response.json(),
390
+ ),
391
+ )
392
+ )
393
+ if _response.status_code == 402:
394
+ raise PaymentRequiredError(
395
+ typing.cast(
396
+ typing.Optional[typing.Any],
397
+ parse_obj_as(
398
+ type_=typing.Optional[typing.Any], # type: ignore
399
+ object_=_response.json(),
400
+ ),
401
+ )
402
+ )
403
+ if _response.status_code == 403:
404
+ raise ForbiddenError(
405
+ typing.cast(
406
+ typing.Optional[typing.Any],
407
+ parse_obj_as(
408
+ type_=typing.Optional[typing.Any], # type: ignore
409
+ object_=_response.json(),
410
+ ),
411
+ )
412
+ )
413
+ if _response.status_code == 500:
414
+ raise InternalServerError(
415
+ typing.cast(
416
+ typing.Optional[typing.Any],
417
+ parse_obj_as(
418
+ type_=typing.Optional[typing.Any], # type: ignore
419
+ object_=_response.json(),
420
+ ),
421
+ )
422
+ )
423
+ _response_json = _response.json()
424
+ except JSONDecodeError:
425
+ raise ApiError(status_code=_response.status_code, body=_response.text)
426
+ raise ApiError(status_code=_response.status_code, body=_response_json)
427
+
428
+ async def stream(
429
+ self,
430
+ *,
431
+ accept: AudioStreamRequestAccept,
432
+ input: str,
433
+ voice_id: str,
434
+ language: typing.Optional[str] = OMIT,
435
+ model: typing.Optional[GetStreamRequestModel] = OMIT,
436
+ options: typing.Optional[GetStreamOptionsRequest] = OMIT,
437
+ request_options: typing.Optional[RequestOptions] = None,
438
+ ) -> typing.AsyncIterator[bytes]:
439
+ """
440
+ Gets the stream speech for the given input
441
+
442
+ Parameters
443
+ ----------
444
+ accept : AudioStreamRequestAccept
445
+
446
+ input : str
447
+ Plain text or SSML to be synthesized to speech.
448
+ Refer to https://docs.sws.speechify.com/docs/api-limits for the input size limits.
449
+ Emotion, Pitch and Speed Rate are configured in the ssml input, please refer to the ssml documentation for more information: https://docs.sws.speechify.com/docs/ssml#prosody
450
+
451
+ voice_id : str
452
+ Id of the voice to be used for synthesizing speech. Refer to /v1/voices endpoint for available voices
453
+
454
+ language : typing.Optional[str]
455
+ Language of the input. Follow the format of an ISO 639-1 language code and an ISO 3166-1 region code, separated by a hyphen, e.g. en-US.
456
+ Please refer to the list of the supported languages and recommendations regarding this parameter: https://docs.sws.speechify.com/docs/language-support.
457
+
458
+ model : typing.Optional[GetStreamRequestModel]
459
+ Model used for audio synthesis
460
+ simba-base ModelBase ModelBase is deprecated. Use simba-english or simba-multilingual instead. @deprecated
461
+ simba-english ModelEnglish
462
+ simba-multilingual ModelMultilingual
463
+ simba-turbo ModelTurbo
464
+
465
+ options : typing.Optional[GetStreamOptionsRequest]
466
+
467
+ request_options : typing.Optional[RequestOptions]
468
+ Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
469
+
470
+ Yields
471
+ ------
472
+ typing.AsyncIterator[bytes]
473
+
474
+ """
475
+ async with self._client_wrapper.httpx_client.stream(
476
+ "v1/audio/stream",
477
+ method="POST",
478
+ json={
479
+ "input": input,
480
+ "language": language,
481
+ "model": model,
482
+ "options": convert_and_respect_annotation_metadata(
483
+ object_=options, annotation=GetStreamOptionsRequest, direction="write"
484
+ ),
485
+ "voice_id": voice_id,
486
+ },
487
+ headers={
488
+ "content-type": "application/json",
489
+ "Accept": str(accept) if accept is not None else None,
490
+ },
491
+ request_options=request_options,
492
+ omit=OMIT,
493
+ ) as _response:
494
+ try:
495
+ if 200 <= _response.status_code < 300:
496
+ _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
497
+ async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size):
498
+ yield _chunk
499
+ return
500
+ await _response.aread()
501
+ if _response.status_code == 400:
502
+ raise BadRequestError(
503
+ typing.cast(
504
+ typing.Optional[typing.Any],
505
+ parse_obj_as(
506
+ type_=typing.Optional[typing.Any], # type: ignore
507
+ object_=_response.json(),
508
+ ),
509
+ )
510
+ )
511
+ if _response.status_code == 402:
512
+ raise PaymentRequiredError(
513
+ typing.cast(
514
+ typing.Optional[typing.Any],
515
+ parse_obj_as(
516
+ type_=typing.Optional[typing.Any], # type: ignore
517
+ object_=_response.json(),
518
+ ),
519
+ )
520
+ )
521
+ if _response.status_code == 403:
522
+ raise ForbiddenError(
523
+ typing.cast(
524
+ typing.Optional[typing.Any],
525
+ parse_obj_as(
526
+ type_=typing.Optional[typing.Any], # type: ignore
527
+ object_=_response.json(),
528
+ ),
529
+ )
530
+ )
531
+ if _response.status_code == 500:
532
+ raise InternalServerError(
533
+ typing.cast(
534
+ typing.Optional[typing.Any],
535
+ parse_obj_as(
536
+ type_=typing.Optional[typing.Any], # type: ignore
537
+ object_=_response.json(),
538
+ ),
539
+ )
540
+ )
541
+ _response_json = _response.json()
542
+ except JSONDecodeError:
543
+ raise ApiError(status_code=_response.status_code, body=_response.text)
544
+ raise ApiError(status_code=_response.status_code, body=_response_json)
@@ -0,0 +1,8 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .audio_stream_request_accept import AudioStreamRequestAccept
4
+ from .get_speech_request_audio_format import GetSpeechRequestAudioFormat
5
+ from .get_speech_request_model import GetSpeechRequestModel
6
+ from .get_stream_request_model import GetStreamRequestModel
7
+
8
+ __all__ = ["AudioStreamRequestAccept", "GetSpeechRequestAudioFormat", "GetSpeechRequestModel", "GetStreamRequestModel"]
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ AudioStreamRequestAccept = typing.Union[typing.Literal["audio/mpeg", "audio/ogg", "audio/aac"], typing.Any]
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ GetSpeechRequestAudioFormat = typing.Union[typing.Literal["wav", "mp3", "ogg", "aac"], typing.Any]
@@ -0,0 +1,7 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ GetSpeechRequestModel = typing.Union[
6
+ typing.Literal["simba-base", "simba-english", "simba-multilingual", "simba-turbo"], typing.Any
7
+ ]
@@ -0,0 +1,7 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ GetStreamRequestModel = typing.Union[
6
+ typing.Literal["simba-base", "simba-english", "simba-multilingual", "simba-turbo"], typing.Any
7
+ ]
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .types import CreateAccessTokenRequestScope
4
+
5
+ __all__ = ["CreateAccessTokenRequestScope"]