FloweryAPI¶
FloweryAPI
¶
Main class for interacting with the Flowery API.
Example
from pyflowery import FloweryAPI, FloweryAPIConfig
config = FloweryAPIConfig(
user_agent = "PyFloweryDocumentation/1.0.0",
token = "hello world",
allow_truncation = False,
)
api = FloweryAPI(config=config)
adapter = rest_adapter.RestAdapter(config=config)
instance-attribute
¶
Rest Adapter used for making HTTP requests.
config = config
instance-attribute
¶
Object for configuring requests to the Flowery API.
logger = self.config.logger
instance-attribute
¶
The logger used internally.
close()
async
¶
Close the currently open client session.
fetch_tts(text, voice, audio_format=models.AudioFormat.MP3, speed=1.0)
async
¶
Fetch a TTS audio file from the Flowery API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
|
The SSML text to convert to speech. This will be contained within the body of a |
required |
voice
|
|
The voice to use for the speech. |
required |
audio_format
|
|
The audio format to return. |
|
Raises:
| Type | Description |
|---|---|
|
Raised when the provided text is too long. |
|
Raised when the Flowery API returns a 429 status code. |
|
Raised when the Flowery API returns a 4xx status code. |
|
Raised when the Flowery API returns a 5xx status code. |
|
Raised when the Flowery API returns an empty response or a response with an unexpected format. |
|
Raised when the retry limit defined in the [ |
Returns:
| Type | Description |
|---|---|
|
An object containing the parameters used to synthesize the text, as well as the raw tts data in bytes. |
fetch_voices()
async
¶
Fetch a mapping of voice IDs to voices from the Flowery API.
Calling this method will repopulate the built-in voices cache.
Raises:
| Type | Description |
|---|---|
|
Raised when the Flowery API returns a 429 status code. |
|
Raised when the Flowery API returns a 4xx status code. |
|
Raised when the Flowery API returns a 5xx status code. |
|
Raised when the Flowery API returns an empty response or a response with an unexpected format. |
|
Raised when the retry limit defined in the |
Returns:
| Type | Description |
|---|---|
|
A mapping of voice IDs to voices. |
get_voice(voice_id)
¶
Get a voice from the cache using its ID.
Example
from pyflowery import FloweryAPI, FloweryAPIConfig
api = FloweryAPI(config=FloweryAPIConfig(user_agent="PyFloweryDocumentation/1.0.0"))
voice = api.get_voice("372a5e97-1645-563a-9097-36bd83184ab4")
# Voice(
# id='372a5e97-1645-563a-9097-36bd83184ab4',
# name='Xiaoyi', gender='Female', source='Microsoft Azure',
# language=Language(name='Chinese (China)', code='zh-CN')
# )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voice_id
|
|
The ID of the voice to retrieve from the cache. |
required |
Returns:
| Type | Description |
|---|---|
|
The matching [ |
get_voices(*, name=None, gender=None, source=None, languages=None)
¶
get_voices() -> tuple[models.Voice, ...]
get_voices(*, name: str | None = None, gender: str | None = None, source: str | None = None, languages: list[models.Language] | models.Language | None = None) -> tuple[models.Voice, ...] | None
Get a filtered set of voices from the cache.
Example
from pyflowery import FloweryAPI, FloweryAPIConfig, Language
api = FloweryAPI(config=FloweryAPIConfig(user_agent="PyFloweryDocumentation/1.0.0"))
voices = api.get_voices(source="TikTok", languages=Language(name="English (United States)", code="en-US"))
# (
# Voice(
# id='fa3ea565-121f-5efd-b4e9-59895c77df23',
# name='Alexander', gender='Male', source='TikTok',
# language=Language(name='English (United States)', code='en-US')
# ),
# Voice(
# id='a55b0ad0-84c8-597d-832b-0bc4c8777054',
# name='Alto', gender='Female', source='TikTok',
# language=Language(name='English (United States)', code='en-US')
# ), ...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
|
The name to filter results by. |
None
|
gender
|
|
The gender to filter results by. |
None
|
source
|
|
The source to filter results by. |
None
|
languages
|
|
The languages to filter results by. |
None
|
Returns:
| Type | Description |
|---|---|
|
All voices when no filters are given. |
|
Filtered voices (or None if no matches). |