Skip to content

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 str | _Element

The SSML text to convert to speech. This will be contained within the body of a <voice> tag. See the Flowery SSML documentation for more information on SSML.

required
voice Voice

The voice to use for the speech.

required
audio_format AudioFormat

The audio format to return.

MP3

Raises:

Type Description
ValueError

Raised when the provided text is too long.

TooManyRequests

Raised when the Flowery API returns a 429 status code.

ClientError

Raised when the Flowery API returns a 4xx status code.

InternalServerError

Raised when the Flowery API returns a 5xx status code.

ResponseError

Raised when the Flowery API returns an empty response or a response with an unexpected format.

RetryLimitExceeded

Raised when the retry limit defined in the [FloweryAPIConfig][models.FloweryAPIConfig] class (default 3) is exceeded.

Returns:

Type Description
TTSResponse

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
TooManyRequests

Raised when the Flowery API returns a 429 status code.

ClientError

Raised when the Flowery API returns a 4xx status code.

InternalServerError

Raised when the Flowery API returns a 5xx status code.

ResponseError

Raised when the Flowery API returns an empty response or a response with an unexpected format.

RetryLimitExceeded

Raised when the retry limit defined in the FloweryAPIConfig class (default 3) is exceeded.

Returns:

Type Description
Mapping[str, Voice]

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 str

The ID of the voice to retrieve from the cache.

required

Returns:

Type Description
Voice | None

The matching [Voice][models.Voice] if found, otherwise None.

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 str | None

The name to filter results by.

None
gender str | None

The gender to filter results by.

None
source str | None

The source to filter results by.

None
languages list[Language] | Language | None

The languages to filter results by.

None

Returns:

Type Description
tuple[Voice, ...]

All voices when no filters are given.

tuple[Voice, ...] | None

Filtered voices (or None if no matches).