Skip to main content

chat

Signature:

Speech.chat(
*,
config: ChatConfig | None = None,
**kwargs: Any,
) -> TaskHandle[None]

Description:

Start a voice conversation task.

Parameters:

Parameter

Type

Default

Description

config

ChatConfig | None

None

Speech chat configuration; uses default configuration when None.

**kwargs

Any

-

Optional configuration parameters.

ChatConfig field descriptions:

Field

Type

Default

Description

voice

str

"default"

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

system_prompt

str | None

None

Role prompt; uses default prompt when None.

welcome_msg

str | None

None

Welcome message at the start of the conversation; no welcome message is set when None.

volume

float | None

None

Conversation playback volume, range 0.0 to 1.0; system volume is not modified when None.

Optional configuration parameters:

Parameter

Type

Default

Description

interrupt_speech_duration

int

800

Interruption detection duration in ms.

interrupt_keywords

Sequence[str] | str

["停一下", "先别说", "stop"]

Keywords that trigger interruption.

enable_face_tracking

bool

False

Whether to enable face tracking during conversation.

enable_subtitle_log

bool

False

Whether to log conversation subtitles.

Returns:

TaskHandle[None], see Section "Tasks and Subscriptions / TaskHandle"

Raises:

ValueError: Invalid configuration parameters.

RuntimeError: Failed to start speech chat task.

Example:

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

robot = BoosterRobot()
speech = Speech(robot)
handle = speech.chat(
config=ChatConfig(
system_prompt="You are a weather forecast assistant who can query weather forecasts across the country with reliable information sources.",
welcome_msg="Hello, I am a weather forecast assistant. Which city's weather would you like to query?",
volume=0.1,
),
enable_subtitle_log=True,
)
try:
print("Speech chat started, press Ctrl+C to exit")
status = handle.wait()
except KeyboardInterrupt:
print("\nStopping speech chat...")
handle.cancel()
handle.wait(timeout=5.0)