speechify-api 0.0.145__tar.gz

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/PKG-INFO +167 -0
  2. speechify_api-0.0.145/README.md +140 -0
  3. speechify_api-0.0.145/pyproject.toml +64 -0
  4. speechify_api-0.0.145/src/speechifyinc/__init__.py +17 -0
  5. speechify_api-0.0.145/src/speechifyinc/api/__init__.py +5 -0
  6. speechify_api-0.0.145/src/speechifyinc/api/types/__init__.py +5 -0
  7. speechify_api-0.0.145/src/speechifyinc/api/types/audio_stream_request_accept.py +5 -0
  8. speechify_api-0.0.145/src/speechifyinc/client.py +150 -0
  9. speechify_api-0.0.145/src/speechifyinc/core/__init__.py +47 -0
  10. speechify_api-0.0.145/src/speechifyinc/core/api_error.py +15 -0
  11. speechify_api-0.0.145/src/speechifyinc/core/client_wrapper.py +76 -0
  12. speechify_api-0.0.145/src/speechifyinc/core/datetime_utils.py +28 -0
  13. speechify_api-0.0.145/src/speechifyinc/core/file.py +67 -0
  14. speechify_api-0.0.145/src/speechifyinc/core/http_client.py +499 -0
  15. speechify_api-0.0.145/src/speechifyinc/core/jsonable_encoder.py +101 -0
  16. speechify_api-0.0.145/src/speechifyinc/core/pydantic_utilities.py +296 -0
  17. speechify_api-0.0.145/src/speechifyinc/core/query_encoder.py +58 -0
  18. speechify_api-0.0.145/src/speechifyinc/core/remove_none_from_dict.py +11 -0
  19. speechify_api-0.0.145/src/speechifyinc/core/request_options.py +35 -0
  20. speechify_api-0.0.145/src/speechifyinc/core/serialization.py +272 -0
  21. speechify_api-0.0.145/src/speechifyinc/environment.py +7 -0
  22. speechify_api-0.0.145/src/speechifyinc/py.typed +0 -0
  23. speechify_api-0.0.145/src/speechifyinc/tts/__init__.py +78 -0
  24. speechify_api-0.0.145/src/speechifyinc/tts/audio/__init__.py +5 -0
  25. speechify_api-0.0.145/src/speechifyinc/tts/audio/client.py +544 -0
  26. speechify_api-0.0.145/src/speechifyinc/tts/audio/types/__init__.py +8 -0
  27. speechify_api-0.0.145/src/speechifyinc/tts/audio/types/audio_stream_request_accept.py +5 -0
  28. speechify_api-0.0.145/src/speechifyinc/tts/audio/types/get_speech_request_audio_format.py +5 -0
  29. speechify_api-0.0.145/src/speechifyinc/tts/audio/types/get_speech_request_model.py +7 -0
  30. speechify_api-0.0.145/src/speechifyinc/tts/audio/types/get_stream_request_model.py +7 -0
  31. speechify_api-0.0.145/src/speechifyinc/tts/auth/__init__.py +5 -0
  32. speechify_api-0.0.145/src/speechifyinc/tts/auth/client.py +171 -0
  33. speechify_api-0.0.145/src/speechifyinc/tts/auth/types/__init__.py +5 -0
  34. speechify_api-0.0.145/src/speechifyinc/tts/auth/types/create_access_token_request_scope.py +10 -0
  35. speechify_api-0.0.145/src/speechifyinc/tts/client.py +26 -0
  36. speechify_api-0.0.145/src/speechifyinc/tts/errors/__init__.py +9 -0
  37. speechify_api-0.0.145/src/speechifyinc/tts/errors/bad_request_error.py +9 -0
  38. speechify_api-0.0.145/src/speechifyinc/tts/errors/forbidden_error.py +9 -0
  39. speechify_api-0.0.145/src/speechifyinc/tts/errors/internal_server_error.py +9 -0
  40. speechify_api-0.0.145/src/speechifyinc/tts/errors/not_found_error.py +9 -0
  41. speechify_api-0.0.145/src/speechifyinc/tts/errors/payment_required_error.py +9 -0
  42. speechify_api-0.0.145/src/speechifyinc/tts/types/__init__.py +57 -0
  43. speechify_api-0.0.145/src/speechifyinc/tts/types/access_token.py +34 -0
  44. speechify_api-0.0.145/src/speechifyinc/tts/types/access_token_scope.py +10 -0
  45. speechify_api-0.0.145/src/speechifyinc/tts/types/api_key.py +47 -0
  46. speechify_api-0.0.145/src/speechifyinc/tts/types/create_voice_language.py +20 -0
  47. speechify_api-0.0.145/src/speechifyinc/tts/types/create_voice_model.py +22 -0
  48. speechify_api-0.0.145/src/speechifyinc/tts/types/create_voice_model_name.py +7 -0
  49. speechify_api-0.0.145/src/speechifyinc/tts/types/created_voice.py +28 -0
  50. speechify_api-0.0.145/src/speechifyinc/tts/types/created_voice_gender.py +5 -0
  51. speechify_api-0.0.145/src/speechifyinc/tts/types/created_voice_type.py +5 -0
  52. speechify_api-0.0.145/src/speechifyinc/tts/types/experimental_stream_request.py +49 -0
  53. speechify_api-0.0.145/src/speechifyinc/tts/types/experimental_stream_request_model.py +7 -0
  54. speechify_api-0.0.145/src/speechifyinc/tts/types/experimental_stream_response.py +33 -0
  55. speechify_api-0.0.145/src/speechifyinc/tts/types/get_speech_options_request.py +32 -0
  56. speechify_api-0.0.145/src/speechifyinc/tts/types/get_speech_response.py +36 -0
  57. speechify_api-0.0.145/src/speechifyinc/tts/types/get_speech_response_audio_format.py +5 -0
  58. speechify_api-0.0.145/src/speechifyinc/tts/types/get_stream_options_request.py +32 -0
  59. speechify_api-0.0.145/src/speechifyinc/tts/types/get_voice.py +30 -0
  60. speechify_api-0.0.145/src/speechifyinc/tts/types/get_voice_gender.py +5 -0
  61. speechify_api-0.0.145/src/speechifyinc/tts/types/get_voice_language.py +20 -0
  62. speechify_api-0.0.145/src/speechifyinc/tts/types/get_voice_type.py +5 -0
  63. speechify_api-0.0.145/src/speechifyinc/tts/types/get_voices_model.py +22 -0
  64. speechify_api-0.0.145/src/speechifyinc/tts/types/get_voices_model_name.py +7 -0
  65. speechify_api-0.0.145/src/speechifyinc/tts/types/nested_chunk.py +28 -0
  66. speechify_api-0.0.145/src/speechifyinc/tts/types/o_auth_error.py +21 -0
  67. speechify_api-0.0.145/src/speechifyinc/tts/types/o_auth_error_error.py +10 -0
  68. speechify_api-0.0.145/src/speechifyinc/tts/types/speech_marks.py +34 -0
  69. speechify_api-0.0.145/src/speechifyinc/tts/voices/__init__.py +5 -0
  70. speechify_api-0.0.145/src/speechifyinc/tts/voices/client.py +559 -0
  71. speechify_api-0.0.145/src/speechifyinc/tts/voices/types/__init__.py +5 -0
  72. speechify_api-0.0.145/src/speechifyinc/tts/voices/types/voices_create_request_gender.py +5 -0
  73. speechify_api-0.0.145/src/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,140 @@
1
+ # Speechifyinc Python Library
2
+
3
+ [![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)
4
+ [![pypi](https://img.shields.io/pypi/v/speechify-api)](https://pypi.python.org/pypi/speechify-api)
5
+
6
+ The Speechifyinc Python library provides convenient access to the Speechifyinc API from Python.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ pip install speechify-api
12
+ ```
13
+
14
+ ## Reference
15
+
16
+ A full reference for this library is available [here](./reference.md).
17
+
18
+ ## Usage
19
+
20
+ Instantiate and use the client with the following:
21
+
22
+ ```python
23
+ from speechifyinc import Speechify
24
+
25
+ client = Speechify(
26
+ token="YOUR_TOKEN",
27
+ )
28
+ client.tts.audio.speech(
29
+ input="input",
30
+ voice_id="voice_id",
31
+ )
32
+ ```
33
+
34
+ ## Async Client
35
+
36
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
37
+
38
+ ```python
39
+ import asyncio
40
+
41
+ from speechifyinc import AsyncSpeechify
42
+
43
+ client = AsyncSpeechify(
44
+ token="YOUR_TOKEN",
45
+ )
46
+
47
+
48
+ async def main() -> None:
49
+ await client.tts.audio.speech(
50
+ input="input",
51
+ voice_id="voice_id",
52
+ )
53
+
54
+
55
+ asyncio.run(main())
56
+ ```
57
+
58
+ ## Exception Handling
59
+
60
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
61
+ will be thrown.
62
+
63
+ ```python
64
+ from speechifyinc.core.api_error import ApiError
65
+
66
+ try:
67
+ client.tts.audio.speech(...)
68
+ except ApiError as e:
69
+ print(e.status_code)
70
+ print(e.body)
71
+ ```
72
+
73
+ ## Advanced
74
+
75
+ ### Retries
76
+
77
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
78
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
79
+ retry limit (default: 2).
80
+
81
+ A request is deemed retryable when any of the following HTTP status codes is returned:
82
+
83
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
84
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
85
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
86
+
87
+ Use the `max_retries` request option to configure this behavior.
88
+
89
+ ```python
90
+ client.tts.audio.speech(..., request_options={
91
+ "max_retries": 1
92
+ })
93
+ ```
94
+
95
+ ### Timeouts
96
+
97
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
98
+
99
+ ```python
100
+
101
+ from speechifyinc import Speechify
102
+
103
+ client = Speechify(
104
+ ...,
105
+ timeout=20.0,
106
+ )
107
+
108
+
109
+ # Override timeout for a specific method
110
+ client.tts.audio.speech(..., request_options={
111
+ "timeout_in_seconds": 1
112
+ })
113
+ ```
114
+
115
+ ### Custom Client
116
+
117
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
118
+ and transports.
119
+ ```python
120
+ import httpx
121
+ from speechifyinc import Speechify
122
+
123
+ client = Speechify(
124
+ ...,
125
+ httpx_client=httpx.Client(
126
+ proxies="http://my.test.proxy.example.com",
127
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
128
+ ),
129
+ )
130
+ ```
131
+
132
+ ## Contributing
133
+
134
+ While we value open-source contributions to this SDK, this library is generated programmatically.
135
+ Additions made directly to this library would have to be moved over to our generation code,
136
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
137
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
138
+ an issue first to discuss with us!
139
+
140
+ On the other hand, contributions to the README are always very welcome!
@@ -0,0 +1,64 @@
1
+ [project]
2
+ name = "speechify-api"
3
+
4
+ [tool.poetry]
5
+ name = "speechify-api"
6
+ version = "0.0.145"
7
+ description = ""
8
+ readme = "README.md"
9
+ authors = []
10
+ keywords = []
11
+
12
+ classifiers = [
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.8",
17
+ "Programming Language :: Python :: 3.9",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Operating System :: OS Independent",
22
+ "Operating System :: POSIX",
23
+ "Operating System :: MacOS",
24
+ "Operating System :: POSIX :: Linux",
25
+ "Operating System :: Microsoft :: Windows",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ "Typing :: Typed"
28
+ ]
29
+ packages = [
30
+ { include = "speechifyinc", from = "src"}
31
+ ]
32
+
33
+ [project.urls]
34
+ Repository = 'https://github.com/speechifyinc/speechify-api-sdk-python'
35
+
36
+ [tool.poetry.dependencies]
37
+ python = "^3.8"
38
+ httpx = ">=0.21.2"
39
+ pydantic = ">= 1.9.2"
40
+ pydantic-core = "^2.18.2"
41
+ typing_extensions = ">= 4.0.0"
42
+
43
+ [tool.poetry.dev-dependencies]
44
+ mypy = "1.0.1"
45
+ pytest = "^7.4.0"
46
+ pytest-asyncio = "^0.23.5"
47
+ python-dateutil = "^2.9.0"
48
+ types-python-dateutil = "^2.9.0.20240316"
49
+ ruff = "^0.5.6"
50
+
51
+ [tool.pytest.ini_options]
52
+ testpaths = [ "tests" ]
53
+ asyncio_mode = "auto"
54
+
55
+ [tool.mypy]
56
+ plugins = ["pydantic.mypy"]
57
+
58
+ [tool.ruff]
59
+ line-length = 120
60
+
61
+
62
+ [build-system]
63
+ requires = ["poetry-core"]
64
+ build-backend = "poetry.core.masonry.api"
@@ -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]
@@ -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
+ )