Skip to main content

synthesize

Available since v1.2.0

Signature:

Speech.synthesize(
text: str,
voice: str = "default",
speed: float = 1.0,
) -> TaskHandle[AudioData]

Description:

Asynchronously synthesize text into speech, return a TaskHandle immediately, and the actual synthesis is performed on a background thread.

Parameters:

Parameters

Type

default value

Description

text

str

-

Text to be synthesized, maximum 300 characters.

voice

str

"default"

Synthesized voice ID; available voices can be obtained via list_voices ().

speed

float

1.0

Speech synthesis speed multiplier.

Returns:

TaskHandle[AudioData], see "Tasks and Subscriptions / TaskHandle"

Call handle. result () to wait for the synthesis to complete and obtain the audio data (AudioData, see "Sensor and Status Data / AudioData").

Raises:

ValueError: Thrown in the following cases:

  • voice is not a valid voice ID
  • The text length exceeds the limit

RuntimeError: Speech synthesis call failed (thrown via handle. result ()).

Example:

from boosteros.brain import Speech
from boosteros.robots.booster import BoosterRobot

robot = BoosterRobot()
speech = Speech(robot)

handle = speech.synthesize("The weather is really nice today. Welcome to use the Booster bot.")
audio = handle.result()
print(f"complete: {audio.duration.seconds:.2f}s")
# Example output: complete: 3.45s
audio.save("/tmp/booster_synthesize.wav")