(3.0.0) cleaned up uv dependencies for pep 735, made a backwards incompatible change in the FloweryApiConfig model, and set up ruff formatting
Some checks failed
Actions / Build (push) Successful in 10s
Actions / Lint with Ruff & Pylint (push) Failing after 12s
Actions / Build Documentation (push) Failing after 6s

This commit is contained in:
cswimr 2024-11-15 00:10:38 -05:00
parent dcb5365fea
commit fde5dad155
Signed by: cswimr
GPG key ID: A9C162E867C851FA
11 changed files with 273 additions and 243 deletions

View file

@ -8,7 +8,7 @@ To create an API client, you need to first import the `pyflowery.pyflowery.Flowe
```python
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@gmail.com")
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@foobar.com")
api = FloweryAPI(config)
```
@ -21,7 +21,7 @@ So, whenever a `FloweryAPI` class is instantiated, it will automatically fetch a
```python
# Set up the API client
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@gmail.com")
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@foobar.com")
api = FloweryAPI(config) # This will fetch all of the voices from the API and cache them automatically, you don't need to do that manually
voices = api.get_voices(name="Alexander")
@ -36,7 +36,7 @@ In most use cases, it is not necessary to manually update the voice cache. But,
```python
import asyncio # This is required to run asynchronous code outside of async functions
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@gmail.com")
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@foobar.com")
api = FloweryAPI(config) # This will fetch all of the voices from the API and cache them automatically, you don't need to do that manually
asyncio.run(api._populate_voices_cache()) # This will update the voice cache. This is what `FloweryAPI` calls automatically when it is instantiated
@ -46,13 +46,15 @@ asyncio.run(api._populate_voices_cache()) # This will update the voice cache. Th
If necessary, you can call the `fetch_voices()` or `fetch_voice()` methods. These methods will fetch the voices from the API directly, skipping the cache. This isn't recommended, though, as it puts more strain on the Flowery API.
<!-- markdownlint-disable code-block-style -->
=== "`fetch_voices()`"
`fetch_voices()` returns an `AsyncContextManager`, so you need to iterate through it when you call it.
```python
import asyncio
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@gmail.com")
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@foobar.com")
api = FloweryAPI(config)
async def fetch_voices():
@ -69,7 +71,7 @@ If necessary, you can call the `fetch_voices()` or `fetch_voice()` methods. Thes
```python
import asyncio
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@gmail.com")
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@foobar.com")
api = FloweryAPI(config)
voice_id = "38f45366-68e8-5d39-b1ef-3fd4eeb61cdb"
@ -78,6 +80,8 @@ If necessary, you can call the `fetch_voices()` or `fetch_voice()` methods. Thes
print(voice) # Voice(id='38f45366-68e8-5d39-b1ef-3fd4eeb61cdb', name='Jacob', gender='Male', source='Microsoft Azure', language=Language(name='English (United States)', code='en-US'))
```
<!-- markdownlint-enable code-block-style -->
## Converting text to audio
Finally, let's convert some text into audio. To do this, you can call the `fetch_tts()` method. This will return the bytes of the audio file.
@ -85,7 +89,7 @@ Finally, let's convert some text into audio. To do this, you can call the `fetch
```python
import asyncio
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@gmail.com")
config = FloweryAPIConfig(user_agent="PyFlowery Documentation Example/example@foobar.com")
api = FloweryAPI(config)
voice = api.get_voices(name="Alexander")[0]