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,167 @@
1
+ Metadata-Version: 2.1
2
+ Name: speechify-api
3
+ Version: 0.0.145
4
+ Summary:
5
+ Requires-Python: >=3.8,<4.0
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: Microsoft :: Windows
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: httpx (>=0.21.2)
22
+ Requires-Dist: pydantic (>=1.9.2)
23
+ Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
24
+ Requires-Dist: typing_extensions (>=4.0.0)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Speechifyinc Python Library
28
+
29
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fspeechifyinc%2Fspeechify-api-sdk-python)
30
+ [![pypi](https://img.shields.io/pypi/v/speechify-api)](https://pypi.python.org/pypi/speechify-api)
31
+
32
+ The Speechifyinc Python library provides convenient access to the Speechifyinc API from Python.
33
+
34
+ ## Installation
35
+
36
+ ```sh
37
+ pip install speechify-api
38
+ ```
39
+
40
+ ## Reference
41
+
42
+ A full reference for this library is available [here](./reference.md).
43
+
44
+ ## Usage
45
+
46
+ Instantiate and use the client with the following:
47
+
48
+ ```python
49
+ from speechifyinc import Speechify
50
+
51
+ client = Speechify(
52
+ token="YOUR_TOKEN",
53
+ )
54
+ client.tts.audio.speech(
55
+ input="input",
56
+ voice_id="voice_id",
57
+ )
58
+ ```
59
+
60
+ ## Async Client
61
+
62
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
63
+
64
+ ```python
65
+ import asyncio
66
+
67
+ from speechifyinc import AsyncSpeechify
68
+
69
+ client = AsyncSpeechify(
70
+ token="YOUR_TOKEN",
71
+ )
72
+
73
+
74
+ async def main() -> None:
75
+ await client.tts.audio.speech(
76
+ input="input",
77
+ voice_id="voice_id",
78
+ )
79
+
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ ## Exception Handling
85
+
86
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
87
+ will be thrown.
88
+
89
+ ```python
90
+ from speechifyinc.core.api_error import ApiError
91
+
92
+ try:
93
+ client.tts.audio.speech(...)
94
+ except ApiError as e:
95
+ print(e.status_code)
96
+ print(e.body)
97
+ ```
98
+
99
+ ## Advanced
100
+
101
+ ### Retries
102
+
103
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
104
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
105
+ retry limit (default: 2).
106
+
107
+ A request is deemed retryable when any of the following HTTP status codes is returned:
108
+
109
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
110
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
111
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
112
+
113
+ Use the `max_retries` request option to configure this behavior.
114
+
115
+ ```python
116
+ client.tts.audio.speech(..., request_options={
117
+ "max_retries": 1
118
+ })
119
+ ```
120
+
121
+ ### Timeouts
122
+
123
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
124
+
125
+ ```python
126
+
127
+ from speechifyinc import Speechify
128
+
129
+ client = Speechify(
130
+ ...,
131
+ timeout=20.0,
132
+ )
133
+
134
+
135
+ # Override timeout for a specific method
136
+ client.tts.audio.speech(..., request_options={
137
+ "timeout_in_seconds": 1
138
+ })
139
+ ```
140
+
141
+ ### Custom Client
142
+
143
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
144
+ and transports.
145
+ ```python
146
+ import httpx
147
+ from speechifyinc import Speechify
148
+
149
+ client = Speechify(
150
+ ...,
151
+ httpx_client=httpx.Client(
152
+ proxies="http://my.test.proxy.example.com",
153
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
154
+ ),
155
+ )
156
+ ```
157
+
158
+ ## Contributing
159
+
160
+ While we value open-source contributions to this SDK, this library is generated programmatically.
161
+ Additions made directly to this library would have to be moved over to our generation code,
162
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
163
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
164
+ an issue first to discuss with us!
165
+
166
+ On the other hand, contributions to the README are always very welcome!
167
+
@@ -0,0 +1,73 @@
1
+ speechifyinc/__init__.py,sha256=EedSzzJHmmUD_bXE8pG99LqL32uJpBYeenDsVNAx2k4,410
2
+ speechifyinc/api/__init__.py,sha256=C0xxZI72p0flQdd4xOiwN3v1M_UN-EIid4gmdkyCS8E,149
3
+ speechifyinc/api/types/__init__.py,sha256=Vq9DC2Cr_SY57kHFfHphWYAIgnvee_yPkeaFOM9X9_o,171
4
+ speechifyinc/api/types/audio_stream_request_accept.py,sha256=HDOLzmqo_yyY65jRPmlCQ5-4Fgx0kgkjXbhvs1slEJU,188
5
+ speechifyinc/client.py,sha256=5FFXmtU6t3QJcWFEtIF-u7R1k-o_SwRoAHUru2hIkNs,5986
6
+ speechifyinc/core/__init__.py,sha256=SQ85PF84B9MuKnBwHNHWemSGuy-g_515gFYNFhvEE0I,1438
7
+ speechifyinc/core/api_error.py,sha256=RE8LELok2QCjABadECTvtDp7qejA1VmINCh6TbqPwSE,426
8
+ speechifyinc/core/client_wrapper.py,sha256=vJu7gTItqsD0L55Q_pSSKWV5VeE07YkVB2hxQw2Q8gY,2216
9
+ speechifyinc/core/datetime_utils.py,sha256=nBys2IsYrhPdszxGKCNRPSOCwa-5DWOHG95FB8G9PKo,1047
10
+ speechifyinc/core/file.py,sha256=d4NNbX8XvXP32z8KpK2Xovv33nFfruIrpz0QWxlgpZk,2663
11
+ speechifyinc/core/http_client.py,sha256=Z77OIxIbL4OAB2IDqjRq_sYa5yNYAWfmdhdCSSvh6Y4,19552
12
+ speechifyinc/core/jsonable_encoder.py,sha256=qaF1gtgH-kQZb4kJskETwcCsOPUof-NnYVdszHkb-dM,3656
13
+ speechifyinc/core/pydantic_utilities.py,sha256=UibVGGYmBDsV834x8CtckRDrTIL4lYJPMrcq9yvf7RM,11973
14
+ speechifyinc/core/query_encoder.py,sha256=ekulqNd0j8TgD7ox-Qbz7liqX8-KP9blvT9DsRCenYM,2144
15
+ speechifyinc/core/remove_none_from_dict.py,sha256=EU9SGgYidWq7SexuJbNs4-PZ-5Bl3Vppd864mS6vQZw,342
16
+ speechifyinc/core/request_options.py,sha256=h0QUNCFVdCW_7GclVySCAY2w4NhtXVBUCmHgmzaxpcg,1681
17
+ speechifyinc/core/serialization.py,sha256=D9h_t-RQON3-CHWs1C4ESY9B-Yd5d-l5lnTLb_X896g,9601
18
+ speechifyinc/environment.py,sha256=jRa_dQDOuOnVHReOB8kGDISDLD50Y3f8cVG7JdmK6Wg,164
19
+ speechifyinc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ speechifyinc/tts/__init__.py,sha256=tw-kjIo9Ffe_rd8WOZ4MqDJXR2Hoh1sFDYzlBH3z4_0,2049
21
+ speechifyinc/tts/audio/__init__.py,sha256=BsW7OW98ubKXgOTLzxH67WXVW0V5Ah9MKqY6m7rQe9Y,305
22
+ speechifyinc/tts/audio/client.py,sha256=U9qoALBihuuVHQ_VctVfHRzUMTMUeQXaP6B3j4_s4yo,22882
23
+ speechifyinc/tts/audio/types/__init__.py,sha256=HPuOMsBURXSNbSAew2b8gL6vFEfCtJEbJ0uuRpDnOYk,445
24
+ speechifyinc/tts/audio/types/audio_stream_request_accept.py,sha256=HDOLzmqo_yyY65jRPmlCQ5-4Fgx0kgkjXbhvs1slEJU,188
25
+ speechifyinc/tts/audio/types/get_speech_request_audio_format.py,sha256=lSHtWHabnFC8AI2HPzQIGbp3VV_VLz_cSK7YUFuqUms,179
26
+ speechifyinc/tts/audio/types/get_speech_request_model.py,sha256=tNDb1FzZDqd2Fox7TIzWABB9tfDA_Zwye84gIZkznCs,219
27
+ speechifyinc/tts/audio/types/get_stream_request_model.py,sha256=7Z-qDNDhw5RlruU-A4rb0nU5YGQ-zvypSNuxj7izAqc,219
28
+ speechifyinc/tts/auth/__init__.py,sha256=WoiqzgtGyA8g071yJV1FL6jfevAUGItIUUtZyOaN_uQ,159
29
+ speechifyinc/tts/auth/client.py,sha256=nAOLDyDFpU44AJ7DZgFeJDw8nhai5_hSRwsbKq0P8-U,5659
30
+ speechifyinc/tts/auth/types/__init__.py,sha256=MzmzfnoBLAEwkFRNyHwQhrAvqkhsFlhE5SFVqC4pbOE,187
31
+ speechifyinc/tts/auth/types/create_access_token_request_scope.py,sha256=tpuFuxe8yQRLsf94YTo8pHLPQ-jFaVLoWthHmJ10yOA,286
32
+ speechifyinc/tts/client.py,sha256=LPXz8gdmXGmj2Q91oRXVn6ARHKYPHPl315_g3gcg9Ss,1108
33
+ speechifyinc/tts/errors/__init__.py,sha256=cr9FJZSOHUzK34sbmAmmvvTJVUcruamph34IfoqxTm0,424
34
+ speechifyinc/tts/errors/bad_request_error.py,sha256=1yxRb4yUzd82wSYTpszXKnpeuTOvZvU4hAefdJS-0lo,265
35
+ speechifyinc/tts/errors/forbidden_error.py,sha256=zaxq0qB25teyzIYFwP1BRZHfo3uVcSqGWpR2Z2-EOY4,264
36
+ speechifyinc/tts/errors/internal_server_error.py,sha256=FwPy_UNuabD-_sLqWVrep4M6WWpdaWNKr1k1eVC--fU,269
37
+ speechifyinc/tts/errors/not_found_error.py,sha256=hwgDNocpyz-qCNNceMvrd_Ur9mIW33mywvigTf-Ut50,263
38
+ speechifyinc/tts/errors/payment_required_error.py,sha256=5PmK4gLHu4AWL1yT7rLYgWO748hhmjmaGzN06GFEsFo,270
39
+ speechifyinc/tts/types/__init__.py,sha256=AjldD4NVrRXi6zBb-McbxF09L3ORrLCv6S1bVjKQ4GY,2037
40
+ speechifyinc/tts/types/access_token.py,sha256=QUNvT-6Gicp6X4kd3_RQiMhepXe62BmZw3J1lRqbDtU,1062
41
+ speechifyinc/tts/types/access_token_scope.py,sha256=wBqQllKfI1Au4LFc0EVoYaSOSJ_lCdOHb0yikKTJaUw,273
42
+ speechifyinc/tts/types/api_key.py,sha256=1CK1XzED5RIHkINhm-HLTVMczampvmsf_RiK4yM4yaY,1174
43
+ speechifyinc/tts/types/create_voice_language.py,sha256=nyzkXzCkItecZpwvsxq3e4xKj4fdSpLKD8YOz2VYM2M,637
44
+ speechifyinc/tts/types/create_voice_model.py,sha256=4zzvjq38GBHApF6amrYDwGHeytZsfoJ0sGsOejq8390,787
45
+ speechifyinc/tts/types/create_voice_model_name.py,sha256=78kNppQ6d2810yPNOfJVls8RKMwJyDAtAlxa7aWknc0,218
46
+ speechifyinc/tts/types/created_voice.py,sha256=zmIKs2mpuRhkC9FCoWhhwUs9PzFQpljj3w7GIsYHo4g,1034
47
+ speechifyinc/tts/types/created_voice_gender.py,sha256=eHrMSijaEph97HqYimYfPVt_sFC1KOylESbDAPonRwQ,176
48
+ speechifyinc/tts/types/created_voice_type.py,sha256=JR4LHEWL6H7OkQmfRQiTK0ixIm40PBmDQZXuxXj7Cuo,162
49
+ speechifyinc/tts/types/experimental_stream_request.py,sha256=-cscS3i4lx67nGFnenXMTsF2VDlu8cqYrXsXGrEL3ug,1994
50
+ speechifyinc/tts/types/experimental_stream_request_model.py,sha256=uFa8uXIsjPMeuoId5XqUV671IOfzlRAynukQXcg3FTU,228
51
+ speechifyinc/tts/types/experimental_stream_response.py,sha256=MTZS6BCYTM9oI349jL9YTcMDXMAbViJhu4qD-YASOjQ,1141
52
+ speechifyinc/tts/types/get_speech_options_request.py,sha256=LVlvkUSq2ybCii5W4xVKRb4kto2Xh_6DC55zwp2cgnc,1281
53
+ speechifyinc/tts/types/get_speech_response.py,sha256=IUqKfBNiU2wqyjC0r6JWrevfispRkOuI-_2bvUutY5Q,1154
54
+ speechifyinc/tts/types/get_speech_response_audio_format.py,sha256=xgsLWwf5lBTnVc5-AUWfz7q650cnVN4M17O9QBoKZ2Y,180
55
+ speechifyinc/tts/types/get_stream_options_request.py,sha256=_NE4XlPTdrGktW6Zc9ffwRT8unZmO_md0d0H9Gjh6aY,1281
56
+ speechifyinc/tts/types/get_voice.py,sha256=zr14XZ1NhtyKNVjht8TxzxIlYFomIKy3PwI5ecHChlM,1098
57
+ speechifyinc/tts/types/get_voice_gender.py,sha256=O0NKnxSSk5SHFC76UC8F9VayrOuFUgTXaGP8HCo71xo,172
58
+ speechifyinc/tts/types/get_voice_language.py,sha256=FZjU7DhCDoDDFQoAfVzFppLyjIgzE_C_HyHRLl3DOAE,634
59
+ speechifyinc/tts/types/get_voice_type.py,sha256=GQd21YK3eb0bMa8rxAu8wR6FkahmDAR4UggspSKHh_Q,158
60
+ speechifyinc/tts/types/get_voices_model.py,sha256=n3vUiF2zPK3YGeDHHKVzZaxLCRYFEQaEauTHK5NIaKc,770
61
+ speechifyinc/tts/types/get_voices_model_name.py,sha256=rkmUFKqeXMUOcm5Xc3Asm3HYzJy0BmiXFeEZKtisG1g,216
62
+ speechifyinc/tts/types/nested_chunk.py,sha256=FsmmCdge2kScPqwzoTacsHNl7U_-XwUNpFcqg0U7Sjk,937
63
+ speechifyinc/tts/types/o_auth_error.py,sha256=JUPs7LmYig5EiPn8-Rr8AzXL9NgNbgmMiIHm-2wJjlg,691
64
+ speechifyinc/tts/types/o_auth_error_error.py,sha256=V78TUAKTRWTLkVqp9l5m2E32E0B1pWhkY7bVRI8jqKE,267
65
+ speechifyinc/tts/types/speech_marks.py,sha256=anTVm0UMXPYNgv18fUvsRq6qd2Kcdw99zWKjPwiRgdY,1165
66
+ speechifyinc/tts/voices/__init__.py,sha256=cGdU6zcw-vZ27IlcmXZmB9u87gGEviHd8olULv1uc0E,151
67
+ speechifyinc/tts/voices/client.py,sha256=9bUn7Q_hTKbQGhxEfpgazG4-pyxw4KjZ4TQh4KBArFY,18653
68
+ speechifyinc/tts/voices/types/__init__.py,sha256=NEZ6JsxnYHh9W5QOdYozYtPwUznZosjX-uhCzsz0s_M,174
69
+ speechifyinc/tts/voices/types/voices_create_request_gender.py,sha256=IiBWYWgdIqerMFJoZpe1YMlb1JNZa7G4DNsLQ2GVp80,183
70
+ speechifyinc/version.py,sha256=JmouCWsm_CfSkSnqdFMx5y8CzRfIzJLs4K_5t2vw6JA,80
71
+ speechify_api-0.0.145.dist-info/METADATA,sha256=ZpmQMrimt0zo6UcWqZGSJaMUe4WZx00_N1Gshk6fVdI,4582
72
+ speechify_api-0.0.145.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
73
+ speechify_api-0.0.145.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.6.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,17 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from . import api, tts
4
+ from .api import AudioStreamRequestAccept
5
+ from .client import AsyncSpeechify, Speechify
6
+ from .environment import SpeechifyEnvironment
7
+ from .version import __version__
8
+
9
+ __all__ = [
10
+ "AsyncSpeechify",
11
+ "AudioStreamRequestAccept",
12
+ "Speechify",
13
+ "SpeechifyEnvironment",
14
+ "__version__",
15
+ "api",
16
+ "tts",
17
+ ]
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .types import AudioStreamRequestAccept
4
+
5
+ __all__ = ["AudioStreamRequestAccept"]
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .audio_stream_request_accept import AudioStreamRequestAccept
4
+
5
+ __all__ = ["AudioStreamRequestAccept"]
@@ -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]
speechifyinc/client.py ADDED
@@ -0,0 +1,150 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from .environment import SpeechifyEnvironment
5
+ import os
6
+ import httpx
7
+ from .core.api_error import ApiError
8
+ from .core.client_wrapper import SyncClientWrapper
9
+ from .tts.client import TtsClient
10
+ from .core.client_wrapper import AsyncClientWrapper
11
+ from .tts.client import AsyncTtsClient
12
+
13
+
14
+ class Speechify:
15
+ """
16
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
17
+
18
+ Parameters
19
+ ----------
20
+ base_url : typing.Optional[str]
21
+ The base url to use for requests from the client.
22
+
23
+ environment : SpeechifyEnvironment
24
+ The environment to use for requests from the client. from .environment import SpeechifyEnvironment
25
+
26
+
27
+
28
+ Defaults to SpeechifyEnvironment.DEFAULT
29
+
30
+
31
+
32
+ token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
33
+ timeout : typing.Optional[float]
34
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
35
+
36
+ follow_redirects : typing.Optional[bool]
37
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
38
+
39
+ httpx_client : typing.Optional[httpx.Client]
40
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
41
+
42
+ Examples
43
+ --------
44
+ from speechifyinc import Speechify
45
+
46
+ client = Speechify(
47
+ token="YOUR_TOKEN",
48
+ )
49
+ """
50
+
51
+ def __init__(
52
+ self,
53
+ *,
54
+ base_url: typing.Optional[str] = None,
55
+ environment: SpeechifyEnvironment = SpeechifyEnvironment.DEFAULT,
56
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("SPEECHIFY_API_KEY"),
57
+ timeout: typing.Optional[float] = None,
58
+ follow_redirects: typing.Optional[bool] = True,
59
+ httpx_client: typing.Optional[httpx.Client] = None,
60
+ ):
61
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
62
+ if token is None:
63
+ raise ApiError(
64
+ body="The client must be instantiated be either passing in token or setting SPEECHIFY_API_KEY"
65
+ )
66
+ self._client_wrapper = SyncClientWrapper(
67
+ base_url=_get_base_url(base_url=base_url, environment=environment),
68
+ token=token,
69
+ httpx_client=httpx_client
70
+ if httpx_client is not None
71
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
72
+ if follow_redirects is not None
73
+ else httpx.Client(timeout=_defaulted_timeout),
74
+ timeout=_defaulted_timeout,
75
+ )
76
+ self.tts = TtsClient(client_wrapper=self._client_wrapper)
77
+
78
+
79
+ class AsyncSpeechify:
80
+ """
81
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
82
+
83
+ Parameters
84
+ ----------
85
+ base_url : typing.Optional[str]
86
+ The base url to use for requests from the client.
87
+
88
+ environment : SpeechifyEnvironment
89
+ The environment to use for requests from the client. from .environment import SpeechifyEnvironment
90
+
91
+
92
+
93
+ Defaults to SpeechifyEnvironment.DEFAULT
94
+
95
+
96
+
97
+ token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
98
+ timeout : typing.Optional[float]
99
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
100
+
101
+ follow_redirects : typing.Optional[bool]
102
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
103
+
104
+ httpx_client : typing.Optional[httpx.AsyncClient]
105
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
106
+
107
+ Examples
108
+ --------
109
+ from speechifyinc import AsyncSpeechify
110
+
111
+ client = AsyncSpeechify(
112
+ token="YOUR_TOKEN",
113
+ )
114
+ """
115
+
116
+ def __init__(
117
+ self,
118
+ *,
119
+ base_url: typing.Optional[str] = None,
120
+ environment: SpeechifyEnvironment = SpeechifyEnvironment.DEFAULT,
121
+ token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("SPEECHIFY_API_KEY"),
122
+ timeout: typing.Optional[float] = None,
123
+ follow_redirects: typing.Optional[bool] = True,
124
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
125
+ ):
126
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
127
+ if token is None:
128
+ raise ApiError(
129
+ body="The client must be instantiated be either passing in token or setting SPEECHIFY_API_KEY"
130
+ )
131
+ self._client_wrapper = AsyncClientWrapper(
132
+ base_url=_get_base_url(base_url=base_url, environment=environment),
133
+ token=token,
134
+ httpx_client=httpx_client
135
+ if httpx_client is not None
136
+ else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
137
+ if follow_redirects is not None
138
+ else httpx.AsyncClient(timeout=_defaulted_timeout),
139
+ timeout=_defaulted_timeout,
140
+ )
141
+ self.tts = AsyncTtsClient(client_wrapper=self._client_wrapper)
142
+
143
+
144
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: SpeechifyEnvironment) -> str:
145
+ if base_url is not None:
146
+ return base_url
147
+ elif environment is not None:
148
+ return environment.value
149
+ else:
150
+ raise Exception("Please pass in either base_url or environment to construct the client")
@@ -0,0 +1,47 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .api_error import ApiError
4
+ from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
5
+ from .datetime_utils import serialize_datetime
6
+ from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
7
+ from .http_client import AsyncHttpClient, HttpClient
8
+ from .jsonable_encoder import jsonable_encoder
9
+ from .pydantic_utilities import (
10
+ IS_PYDANTIC_V2,
11
+ UniversalBaseModel,
12
+ UniversalRootModel,
13
+ parse_obj_as,
14
+ universal_field_validator,
15
+ universal_root_validator,
16
+ update_forward_refs,
17
+ )
18
+ from .query_encoder import encode_query
19
+ from .remove_none_from_dict import remove_none_from_dict
20
+ from .request_options import RequestOptions
21
+ from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
22
+
23
+ __all__ = [
24
+ "ApiError",
25
+ "AsyncClientWrapper",
26
+ "AsyncHttpClient",
27
+ "BaseClientWrapper",
28
+ "FieldMetadata",
29
+ "File",
30
+ "HttpClient",
31
+ "IS_PYDANTIC_V2",
32
+ "RequestOptions",
33
+ "SyncClientWrapper",
34
+ "UniversalBaseModel",
35
+ "UniversalRootModel",
36
+ "convert_and_respect_annotation_metadata",
37
+ "convert_file_dict_to_httpx_tuples",
38
+ "encode_query",
39
+ "jsonable_encoder",
40
+ "parse_obj_as",
41
+ "remove_none_from_dict",
42
+ "serialize_datetime",
43
+ "universal_field_validator",
44
+ "universal_root_validator",
45
+ "update_forward_refs",
46
+ "with_content_type",
47
+ ]
@@ -0,0 +1,15 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+
6
+ class ApiError(Exception):
7
+ status_code: typing.Optional[int]
8
+ body: typing.Any
9
+
10
+ def __init__(self, *, status_code: typing.Optional[int] = None, body: typing.Any = None):
11
+ self.status_code = status_code
12
+ self.body = body
13
+
14
+ def __str__(self) -> str:
15
+ return f"status_code: {self.status_code}, body: {self.body}"
@@ -0,0 +1,76 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ import httpx
5
+ from .http_client import HttpClient
6
+ from .http_client import AsyncHttpClient
7
+
8
+
9
+ class BaseClientWrapper:
10
+ def __init__(
11
+ self,
12
+ *,
13
+ token: typing.Union[str, typing.Callable[[], str]],
14
+ base_url: str,
15
+ timeout: typing.Optional[float] = None,
16
+ ):
17
+ self._token = token
18
+ self._base_url = base_url
19
+ self._timeout = timeout
20
+
21
+ def get_headers(self) -> typing.Dict[str, str]:
22
+ headers: typing.Dict[str, str] = {
23
+ "X-Fern-Language": "Python",
24
+ "X-Fern-SDK-Name": "speechify-api",
25
+ "X-Fern-SDK-Version": "0.0.145",
26
+ }
27
+ headers["Authorization"] = f"Bearer {self._get_token()}"
28
+ return headers
29
+
30
+ def _get_token(self) -> str:
31
+ if isinstance(self._token, str):
32
+ return self._token
33
+ else:
34
+ return self._token()
35
+
36
+ def get_base_url(self) -> str:
37
+ return self._base_url
38
+
39
+ def get_timeout(self) -> typing.Optional[float]:
40
+ return self._timeout
41
+
42
+
43
+ class SyncClientWrapper(BaseClientWrapper):
44
+ def __init__(
45
+ self,
46
+ *,
47
+ token: typing.Union[str, typing.Callable[[], str]],
48
+ base_url: str,
49
+ timeout: typing.Optional[float] = None,
50
+ httpx_client: httpx.Client,
51
+ ):
52
+ super().__init__(token=token, base_url=base_url, timeout=timeout)
53
+ self.httpx_client = HttpClient(
54
+ httpx_client=httpx_client,
55
+ base_headers=self.get_headers,
56
+ base_timeout=self.get_timeout,
57
+ base_url=self.get_base_url,
58
+ )
59
+
60
+
61
+ class AsyncClientWrapper(BaseClientWrapper):
62
+ def __init__(
63
+ self,
64
+ *,
65
+ token: typing.Union[str, typing.Callable[[], str]],
66
+ base_url: str,
67
+ timeout: typing.Optional[float] = None,
68
+ httpx_client: httpx.AsyncClient,
69
+ ):
70
+ super().__init__(token=token, base_url=base_url, timeout=timeout)
71
+ self.httpx_client = AsyncHttpClient(
72
+ httpx_client=httpx_client,
73
+ base_headers=self.get_headers,
74
+ base_timeout=self.get_timeout,
75
+ base_url=self.get_base_url,
76
+ )
@@ -0,0 +1,28 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import datetime as dt
4
+
5
+
6
+ def serialize_datetime(v: dt.datetime) -> str:
7
+ """
8
+ Serialize a datetime including timezone info.
9
+
10
+ Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
11
+
12
+ UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
13
+ """
14
+
15
+ def _serialize_zoned_datetime(v: dt.datetime) -> str:
16
+ if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
17
+ # UTC is a special case where we use "Z" at the end instead of "+00:00"
18
+ return v.isoformat().replace("+00:00", "Z")
19
+ else:
20
+ # Delegate to the typical +/- offset format
21
+ return v.isoformat()
22
+
23
+ if v.tzinfo is not None:
24
+ return _serialize_zoned_datetime(v)
25
+ else:
26
+ local_tz = dt.datetime.now().astimezone().tzinfo
27
+ localized_dt = v.replace(tzinfo=local_tz)
28
+ return _serialize_zoned_datetime(localized_dt)
@@ -0,0 +1,67 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
4
+
5
+ # File typing inspired by the flexibility of types within the httpx library
6
+ # https://github.com/encode/httpx/blob/master/httpx/_types.py
7
+ FileContent = Union[IO[bytes], bytes, str]
8
+ File = Union[
9
+ # file (or bytes)
10
+ FileContent,
11
+ # (filename, file (or bytes))
12
+ Tuple[Optional[str], FileContent],
13
+ # (filename, file (or bytes), content_type)
14
+ Tuple[Optional[str], FileContent, Optional[str]],
15
+ # (filename, file (or bytes), content_type, headers)
16
+ Tuple[
17
+ Optional[str],
18
+ FileContent,
19
+ Optional[str],
20
+ Mapping[str, str],
21
+ ],
22
+ ]
23
+
24
+
25
+ def convert_file_dict_to_httpx_tuples(
26
+ d: Dict[str, Union[File, List[File]]],
27
+ ) -> List[Tuple[str, File]]:
28
+ """
29
+ The format we use is a list of tuples, where the first element is the
30
+ name of the file and the second is the file object. Typically HTTPX wants
31
+ a dict, but to be able to send lists of files, you have to use the list
32
+ approach (which also works for non-lists)
33
+ https://github.com/encode/httpx/pull/1032
34
+ """
35
+
36
+ httpx_tuples = []
37
+ for key, file_like in d.items():
38
+ if isinstance(file_like, list):
39
+ for file_like_item in file_like:
40
+ httpx_tuples.append((key, file_like_item))
41
+ else:
42
+ httpx_tuples.append((key, file_like))
43
+ return httpx_tuples
44
+
45
+
46
+ def with_content_type(*, file: File, default_content_type: str) -> File:
47
+ """
48
+ This function resolves to the file's content type, if provided, and defaults
49
+ to the default_content_type value if not.
50
+ """
51
+ if isinstance(file, tuple):
52
+ if len(file) == 2:
53
+ filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
54
+ return (filename, content, default_content_type)
55
+ elif len(file) == 3:
56
+ filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
57
+ out_content_type = file_content_type or default_content_type
58
+ return (filename, content, out_content_type)
59
+ elif len(file) == 4:
60
+ filename, content, file_content_type, headers = cast( # type: ignore
61
+ Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
62
+ )
63
+ out_content_type = file_content_type or default_content_type
64
+ return (filename, content, out_content_type, headers)
65
+ else:
66
+ raise ValueError(f"Unexpected tuple length: {len(file)}")
67
+ return (None, file, default_content_type)