.speak()
显示角色对话,支持富文本样式。
函数签名
// 普通文字,不支持富文本样式
speak(text: string): Figure
// 模板字符串
speak(strings: TemplateStringsArray, ...values: WideTemplateValue[]): Figure
// 带选项的模板调用
speak(options: SpeakOptions): (strings, ...values) => Figure基础用法
// 简单对话
figure.speak("你好!");
figure.speak(`你好!`);
figure.speak`你好!`;
// 使用变量
const name = "玩家";
figure.speak(`你好,${name}!`);
figure.speak`你好,${name}!`;富文本样式
使用内置的样式函数创建富文本:
import { b, i, c } from "@core/figure/speak";
// 加粗
figure.speak`这是${b("加粗")}文本`;
// 斜体
figure.speak`这是${i("斜体")}文本`;
// 颜色
figure.speak`这是${c("红色", "red")}和${c("蓝色", "blue")}文本`;样式函数
| 函数 | 描述 | 示例 |
|---|---|---|
b(text) | 加粗 | b("加粗") |
i(text) | 斜体 | i("斜体") |
c(text, color) | 颜色 | c("红色", "red") |
自定义样式
使用 CSS 对象或 Tailwind 类名:
// 内联 CSS
figure.speak`自定义样式 ${{
text: "绿色下划线",
style: {
color: "green",
fontSize: "20px",
textDecorationLine: "underline",
},
}}`;
// Tailwind 类名
figure.speak`${{ text: "红色文本", className: "text-red-500" }}`;SpeakOptions
覆盖默认的对话参数:
figure.speak({
name: "自定义名称", // 覆盖角色名
avatar: "/custom.webp", // 覆盖头像
charsPerSecond: 10, // 打字速度
speechUrl: "/vocal.wav" // 语音文件
})`对话内容`;链式调用
// 表情 + 动作 + 对话
anon.motion("smile")
.expression("happy")
.speak`你好!`;
// 动画 + 对话
figure.bounce().speak`我在跳!`;Last updated on