Upgrade TTS to qwen3-tts-instruct-flash with instruction control

Adds an optional instructions parameter to sendVoiceMessage so the model
can describe tone, pace and emotion in natural language. Defaults the
TTS model to qwen3-tts-instruct-flash; Chelsie voice is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-22 15:57:15 +08:00
parent 39b49bb302
commit 92acbb2310
3 changed files with 14 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ import kotlin.time.measureTime
class SendVoiceMessage : BaseAgent(
tool = Tool.function(
name = "sendVoiceMessage",
description = "发送一条文本转语音消息。",
description = "发送一条文本转语音消息。可选传入 instructions 用自然语言指令控制语气、语速、情感等表达方式,让语音更贴合当前对话氛围。",
parameters = Parameters.buildJsonObject {
put("type", "object")
putJsonObject("properties") {
@@ -29,6 +29,10 @@ class SendVoiceMessage : BaseAgent(
put("type", "string")
put("description", "语音消息文本内容")
}
putJsonObject("instructions") {
put("type", "string")
put("description", "可选。自然语言描述本句话的表达方式,例如\"语速较快,带有明显的上扬语调\"\"温柔知性,语调平和\"。仅支持中英文。")
}
}
putJsonArray("required") {
add("content")
@@ -52,6 +56,7 @@ class SendVoiceMessage : BaseAgent(
if (event.subject !is AudioSupported) return "当前聊天环境不支持发送语音!"
val content = args.getValue("content").jsonPrimitive.content
val instructions = args["instructions"]?.jsonPrimitive?.content?.takeIf { it.isNotBlank() }
// https://help.aliyun.com/zh/model-studio/qwen-tts
val response = httpClient.post(API_URL) {
@@ -62,6 +67,10 @@ class SendVoiceMessage : BaseAgent(
putJsonObject("input") {
put("text", content)
put("voice", "Chelsie") // Chelsie Cherry Ethan Serena
if (instructions != null) {
put("instructions", instructions)
put("optimize_instructions", true)
}
}
}.toString())
}