智能体编辑页支持选模型与语音 + 全量音色可搜索列表(界面部分)
需求 A、B 的界面部分做完了。
【A. 智能体编辑页】
新增两段:
- 模型:引擎胶囊(跟随全局 / 十家提供商)+ 模型输入框
- 语音:引擎胶囊(跟随全局 / 设备自带 / 豆包语音 / 火山 V1 / OpenAI)
+ 音色选择 + 手填 voice_type
界面上到处写明"留空 = 跟随全局"——这是这个功能的全部要点,
用户不写明就不会知道空着能用。
【B. 全量音色可搜索】
设置页和智能体页都能点「全部 90 个 ›」打开列表:
- 搜索**同时匹配名字和 voice_type**:用户可能记得"灿灿",
也可能手里攥着 `BV700_streaming` 要核对,两种都得能搜到
- 每条都显示名字 + id(要跟控制台核对,藏起来等于没给)
- 实测搜 "mars" → 匹配 53 个,列表正确过滤
【又一次栽在"加字段要改好几处"】
AgentEditDialog 原来是 4 个独立 var(name/avatar/prompt/greeting),
saveAgent 是 5 个形参。加 6 个新字段意味着签名、调用点、赋值全要改。
改成**整份 Agent 草稿**(`var draft by remember`)+ `saveAgent(id, draft)`:
以后往 Agent 里加字段,这两处都不用再动。
这个教训前面已经在 store.create_agent 的白名单上吃过一次了。
【踩的编译坑,记下来】
1. `ifBlank { "x" } == "x" ? a : b` —— Kotlin 把那个 `?` 当成**安全调用**开始解析,
报一堆"Expecting ')'"。拆成变量最稳。
2. 手写的 chunked(3) 等分换行不行:音色名长短差很多
("Vivi 2.0" vs "超自然音色-梓梓2.0"),等分行会把每行第三个挤成竖排
一个字一行(截图里"小何 2.0"竖着排)。改用 FlowRow 按实际宽度折行。
3. 补了 6 个 import(LazyColumn / items / heightIn / background / clip / Color)。
Kotlin 的报错会连锁,第一个"Unresolved reference"往往不是根因。
【验证(模拟器)】
- 智能体编辑页:模型段、语音段、引擎胶囊、音色胶囊、「全部 90 个」都正常
- 点音色胶囊会把 voice_type 填进输入框 ✓
- 全量列表:90 条、滚动正常、搜索 "mars" 匹配 53 个 ✓
- 字段往返:建一个带 provider/model/ttsEngine/ttsVoice 的智能体,
读回来四个字段完整 ✓
回归:语音验收两份内核各 41/41;Markdown 对拍 19/19。
【还剩】C 会议模式(节点+连线编排),下一轮开始。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.doubao.lynxclone.ui
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -13,12 +14,17 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
@@ -44,6 +50,8 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.doubao.lynxclone.data.Agent
|
||||
import com.doubao.lynxclone.data.ProviderPreset
|
||||
import com.doubao.lynxclone.data.VoiceOption
|
||||
|
||||
/**
|
||||
* 智能体页(对应旧版 Lynx 的 Agents.tsx)。
|
||||
@@ -125,9 +133,13 @@ fun AgentsScreen(vm: AppViewModel) {
|
||||
val target = editing
|
||||
AgentEditDialog(
|
||||
agent = target,
|
||||
providers = vm.state.providers.values.toList(),
|
||||
voices = vm.state.speechVoices,
|
||||
voicesAll = vm.state.speechVoicesAll,
|
||||
globalTtsEngine = vm.state.speech.ttsEngine,
|
||||
onDismiss = { creating = false; editing = null },
|
||||
onSave = { name, avatar, prompt, tagline ->
|
||||
vm.saveAgent(target?.id, name, avatar, prompt, tagline) {
|
||||
onSave = { draft ->
|
||||
vm.saveAgent(target?.id, draft) {
|
||||
creating = false
|
||||
editing = null
|
||||
}
|
||||
@@ -245,15 +257,26 @@ private fun ActiveBadge() {
|
||||
@Composable
|
||||
private fun AgentEditDialog(
|
||||
agent: Agent?,
|
||||
providers: List<ProviderPreset>,
|
||||
voices: Map<String, List<VoiceOption>>,
|
||||
voicesAll: Map<String, List<VoiceOption>>,
|
||||
/** 全局当前的朗读引擎:智能体没选引擎时,音色列表要按它来给 */
|
||||
globalTtsEngine: String,
|
||||
onDismiss: () -> Unit,
|
||||
onSave: (name: String, avatar: String, systemPrompt: String, greeting: String) -> Unit,
|
||||
onSave: (Agent) -> Unit,
|
||||
onDelete: (() -> Unit)?,
|
||||
) {
|
||||
var name by remember { mutableStateOf(agent?.name.orEmpty()) }
|
||||
var avatar by remember { mutableStateOf(agent?.avatar ?: "doubao") }
|
||||
var prompt by remember { mutableStateOf(agent?.systemPrompt.orEmpty()) }
|
||||
var greeting by remember { mutableStateOf(agent?.greeting.orEmpty()) }
|
||||
// 整份草稿:加字段时只要往 Agent 里加,不用再改一遍这里的所有 var
|
||||
var draft by remember {
|
||||
mutableStateOf(
|
||||
agent ?: Agent(avatar = "doubao"),
|
||||
)
|
||||
}
|
||||
var error by remember { mutableStateOf("") }
|
||||
val name = draft.name
|
||||
val avatar = draft.avatar
|
||||
val prompt = draft.systemPrompt
|
||||
val greeting = draft.greeting
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
@@ -267,7 +290,7 @@ private fun AgentEditDialog(
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
AvatarKeys.forEach { key ->
|
||||
Box(Modifier.clickable { avatar = key }) {
|
||||
Box(Modifier.clickable { draft = draft.copy(avatar = key) }) {
|
||||
// 选中态画在 AvatarCircle 的外圈上,不改变尺寸
|
||||
AvatarCircle(name = "", avatar = key, size = 34, selected = avatar == key)
|
||||
}
|
||||
@@ -278,7 +301,7 @@ private fun AgentEditDialog(
|
||||
FormLabel("名称")
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
onValueChange = { name = it },
|
||||
onValueChange = { draft = draft.copy(name = it) },
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 6.dp),
|
||||
placeholder = { Text("例如:翻译官", fontSize = 13.sp) },
|
||||
singleLine = true,
|
||||
@@ -289,7 +312,7 @@ private fun AgentEditDialog(
|
||||
FormLabel("问候语 / 一句话介绍")
|
||||
OutlinedTextField(
|
||||
value = greeting,
|
||||
onValueChange = { greeting = it },
|
||||
onValueChange = { draft = draft.copy(greeting = it) },
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 6.dp),
|
||||
placeholder = { Text("显示在列表里,也用作首屏问候", fontSize = 13.sp) },
|
||||
singleLine = true,
|
||||
@@ -305,7 +328,7 @@ private fun AgentEditDialog(
|
||||
FormLabel("系统提示词")
|
||||
OutlinedTextField(
|
||||
value = prompt,
|
||||
onValueChange = { prompt = it },
|
||||
onValueChange = { draft = draft.copy(systemPrompt = it) },
|
||||
modifier = Modifier.fillMaxWidth().height(150.dp).padding(top = 6.dp),
|
||||
placeholder = { Text("这个人设、规则、说话风格…", fontSize = 13.sp) },
|
||||
textStyle = TextStyle(fontSize = 13.sp),
|
||||
@@ -316,6 +339,67 @@ private fun AgentEditDialog(
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
/* ---------------- 模型(留空 = 跟随全局) ---------------- */
|
||||
Spacer(Modifier.height(14.dp))
|
||||
FormLabel("模型")
|
||||
Text(
|
||||
"不选就跟随「设置 → 连接与模型」里的全局配置。",
|
||||
fontSize = 11.sp,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
WrapChips(
|
||||
options = listOf("" to "跟随全局") +
|
||||
providers.map { it.key to it.label },
|
||||
active = draft.provider,
|
||||
) { draft = draft.copy(provider = it) }
|
||||
Spacer(Modifier.height(6.dp))
|
||||
// ★ 别把 `ifBlank{…} == "x" ? a : b` 写成一整行:Kotlin 会把那个 `?`
|
||||
// 当成安全调用开始解析,报一堆看不懂的语法错。拆成变量最稳。
|
||||
val followGlobalModel = draft.provider.isBlank()
|
||||
OutlinedTextField(
|
||||
value = draft.model,
|
||||
onValueChange = { draft = draft.copy(model = it) },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = {
|
||||
Text(
|
||||
if (followGlobalModel) "留空 = 用全局模型" else "留空 = 用这家的默认模型",
|
||||
fontSize = 13.sp,
|
||||
)
|
||||
},
|
||||
singleLine = true,
|
||||
textStyle = TextStyle(fontSize = 14.sp),
|
||||
)
|
||||
|
||||
/* ---------------- 语音(留空 = 跟随全局) ---------------- */
|
||||
Spacer(Modifier.height(14.dp))
|
||||
FormLabel("语音")
|
||||
Text(
|
||||
"多人会议里靠它区分谁在说话 —— 几个智能体一个嗓子的话根本听不出谁在讲。",
|
||||
fontSize = 11.sp,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
WrapChips(
|
||||
options = listOf("" to "跟随全局") + TtsEngineChoices,
|
||||
active = draft.ttsEngine,
|
||||
) { engine ->
|
||||
// 换引擎顺手清掉音色:音色是按引擎命名的(BVxxx / zh_xxx_bigtts),
|
||||
// 留着上一家的值一定会被判非法
|
||||
draft = draft.copy(ttsEngine = engine, ttsVoice = "")
|
||||
}
|
||||
val voiceEngine = draft.ttsEngine.ifBlank { globalTtsEngine }
|
||||
if (voiceEngine != "" && voiceEngine != "system") {
|
||||
Spacer(Modifier.height(6.dp))
|
||||
VoicePickerInline(
|
||||
engine = voiceEngine,
|
||||
voices = voices[voiceEngine].orEmpty(),
|
||||
voicesAll = voicesAll[voiceEngine].orEmpty(),
|
||||
value = draft.ttsVoice,
|
||||
onValue = { draft = draft.copy(ttsVoice = it) },
|
||||
)
|
||||
}
|
||||
|
||||
if (error.isNotBlank()) {
|
||||
Text(error, fontSize = 12.sp, color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
@@ -323,10 +407,10 @@ private fun AgentEditDialog(
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
if (name.isBlank()) {
|
||||
if (draft.name.isBlank()) {
|
||||
error = "名称不能为空"
|
||||
} else {
|
||||
onSave(name.trim(), avatar, prompt, greeting.trim())
|
||||
onSave(draft.copy(name = draft.name.trim(), greeting = draft.greeting.trim()))
|
||||
}
|
||||
}) { Text("保存") }
|
||||
},
|
||||
@@ -355,3 +439,157 @@ private fun agentSummary(agent: Agent): String = when {
|
||||
agent.systemPrompt.isNotBlank() -> agent.systemPrompt.lineSequence().firstOrNull { it.isNotBlank() } ?: "通用助手"
|
||||
else -> "通用助手"
|
||||
}
|
||||
|
||||
/** 朗读引擎选项(key 和内核 speech.ttsEngine 一致;空串留给"跟随全局") */
|
||||
private val TtsEngineChoices: List<Pair<String, String>> = listOf(
|
||||
"system" to "设备自带",
|
||||
"volcv3" to "豆包语音",
|
||||
"volc" to "火山 V1",
|
||||
"openai" to "OpenAI",
|
||||
)
|
||||
|
||||
/**
|
||||
* 一排可换行的选择胶囊。
|
||||
*
|
||||
* ★ 必须用 FlowRow,不能自己 chunked(3) 塞进 Row:
|
||||
* 音色名长短差很多("Vivi 2.0" vs "超自然音色-梓梓2.0"),等分行会让每行第三个
|
||||
* 被挤成竖排一个字一行(真出过,截图里"小何 2.0"竖着排)。
|
||||
* FlowRow 按实际宽度折行,长标签自己占一行。
|
||||
*/
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun WrapChips(
|
||||
options: List<Pair<String, String>>,
|
||||
active: String,
|
||||
onPick: (String) -> Unit,
|
||||
) {
|
||||
FlowRow(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
options.forEach { (key, label) ->
|
||||
val selected = key == active
|
||||
Box(
|
||||
Modifier
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(if (selected) Doubao.Blue else MaterialTheme.colorScheme.surfaceVariant)
|
||||
.clickable { onPick(key) }
|
||||
.padding(horizontal = 10.dp, vertical = 6.dp),
|
||||
) {
|
||||
Text(
|
||||
label,
|
||||
fontSize = 12.sp,
|
||||
color = if (selected) Color.White else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 智能体编辑页里的音色选择:常用几个 + 全部(可搜索)+ 手填。
|
||||
*
|
||||
* 和设置页那个 VoicePicker 是同款逻辑,但那个是设置页的私有函数(还带
|
||||
* 设置页的 FormLabel 样式)。这里单独写一份更省事,也不至于把设置页的东西
|
||||
* 拽进智能体页 —— 真要统一的话应该把它提成公共组件,那是另一件事。
|
||||
*/
|
||||
@Composable
|
||||
private fun VoicePickerInline(
|
||||
engine: String,
|
||||
voices: List<VoiceOption>,
|
||||
voicesAll: List<VoiceOption>,
|
||||
value: String,
|
||||
onValue: (String) -> Unit,
|
||||
) {
|
||||
var showAll by remember { mutableStateOf(false) }
|
||||
var query by remember { mutableStateOf("") }
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("音色", fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
if (voicesAll.size > voices.size) {
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(
|
||||
"全部 ${voicesAll.size} 个 ›",
|
||||
color = Doubao.Blue,
|
||||
fontSize = 12.sp,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.clickable { showAll = true }
|
||||
.padding(horizontal = 4.dp, vertical = 2.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(6.dp))
|
||||
if (voices.isNotEmpty()) {
|
||||
WrapChips(
|
||||
options = voices.map { it.value to it.label.ifBlank { it.value } },
|
||||
active = value,
|
||||
onPick = onValue,
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = value,
|
||||
onValueChange = onValue,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = { Text("留空 = 引擎默认音色;也可以直接填 voice_type", fontSize = 12.sp) },
|
||||
singleLine = true,
|
||||
textStyle = TextStyle(fontSize = 13.sp),
|
||||
)
|
||||
|
||||
if (showAll) {
|
||||
// 复用设置页那个可搜索列表:搜索同时匹配名字和 id
|
||||
val filtered = remember(query, voicesAll) {
|
||||
val q = query.trim().lowercase()
|
||||
if (q.isEmpty()) voicesAll
|
||||
else voicesAll.filter { it.label.lowercase().contains(q) || it.value.lowercase().contains(q) }
|
||||
}
|
||||
AlertDialog(
|
||||
onDismissRequest = { showAll = false },
|
||||
title = { Text("选择音色($engine · 共 ${voicesAll.size} 个)", fontSize = 16.sp) },
|
||||
text = {
|
||||
Column {
|
||||
OutlinedTextField(
|
||||
value = query,
|
||||
onValueChange = { query = it },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = { Text("搜名字或 voice_type", fontSize = 13.sp) },
|
||||
singleLine = true,
|
||||
textStyle = TextStyle(fontSize = 14.sp),
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Text(
|
||||
if (query.isBlank()) "共 ${voicesAll.size} 个" else "匹配 ${filtered.size} 个",
|
||||
fontSize = 11.sp,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
LazyColumn(Modifier.heightIn(max = 380.dp)) {
|
||||
items(filtered.size) { i ->
|
||||
val v = filtered[i]
|
||||
val selected = v.value == value
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.clickable { onValue(v.value); showAll = false }
|
||||
.background(if (selected) Doubao.Blue.copy(alpha = 0.10f) else Color.Transparent)
|
||||
.padding(horizontal = 8.dp, vertical = 8.dp),
|
||||
) {
|
||||
Text(
|
||||
v.label.ifBlank { v.value },
|
||||
fontSize = 14.sp,
|
||||
color = if (selected) Doubao.Blue else MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
// id 也显示:用户要拿它跟控制台核对
|
||||
Text(v.value, fontSize = 11.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = { showAll = false }) { Text("关闭") } },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,15 +255,33 @@ class AppViewModel(val client: KernelClient) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveAgent(id: String?, name: String, avatar: String, systemPrompt: String, greeting: String, onDone: () -> Unit) {
|
||||
/**
|
||||
* 保存智能体。
|
||||
*
|
||||
* 形参从一个 Agent 对象整体传,而不是一长串 String —— 之前每加一个字段
|
||||
* (问候语、模型、音色…)就要改一遍签名和所有调用点,漏一处就是
|
||||
* "界面上填了、保存后没了"。
|
||||
*
|
||||
* 模型/语音这些字段**空串表示继承全局**,所以原样发过去就行,
|
||||
* 内核那边(store.provider_info / speech.voice_for)也是这个规则。
|
||||
*/
|
||||
fun saveAgent(id: String?, draft: Agent, onDone: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val body = JSONObject()
|
||||
.put("name", name)
|
||||
.put("avatar", avatar)
|
||||
.put("systemPrompt", systemPrompt)
|
||||
.put("name", draft.name)
|
||||
.put("avatar", draft.avatar)
|
||||
.put("systemPrompt", draft.systemPrompt)
|
||||
// 内核字段叫 tagline;UI 上叫"一句话介绍"
|
||||
.put("tagline", greeting)
|
||||
.put("tagline", draft.greeting)
|
||||
// 智能体自己的模型与语音(留空 = 继承全局)
|
||||
.put("provider", draft.provider)
|
||||
.put("model", draft.model)
|
||||
.put("baseUrl", draft.baseUrl)
|
||||
.put("ttsEngine", draft.ttsEngine)
|
||||
.put("ttsVoice", draft.ttsVoice)
|
||||
// 0 = 跟随全局。语速合法范围是 0.5~2.0,0 不可能是有效值
|
||||
if (draft.ttsSpeed > 0) body.put("ttsSpeed", draft.ttsSpeed)
|
||||
withContext(Dispatchers.IO) {
|
||||
if (id.isNullOrBlank()) client.createAgent(body) else client.updateAgent(id, body)
|
||||
}
|
||||
|
||||
@@ -18,10 +18,13 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -40,6 +43,7 @@ import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
@@ -66,6 +70,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.doubao.lynxclone.data.Settings
|
||||
import com.doubao.lynxclone.data.SpeechSettings
|
||||
import com.doubao.lynxclone.data.VoiceOption
|
||||
@@ -227,6 +232,7 @@ fun SettingsScreen(vm: AppViewModel) {
|
||||
VoicePicker(
|
||||
title = "音色(speaker)",
|
||||
voices = vm.state.speechVoices["volcv3"].orEmpty(),
|
||||
voicesAll = vm.state.speechVoicesAll["volcv3"].orEmpty(),
|
||||
value = draft.speech.ttsVoice,
|
||||
placeholder = "留空 = zh_female_vv_uranus_bigtts(Vivi 2.0)",
|
||||
onValue = { draft = draft.copy(speech = draft.speech.copy(ttsVoice = it)) },
|
||||
@@ -267,6 +273,7 @@ fun SettingsScreen(vm: AppViewModel) {
|
||||
VoicePicker(
|
||||
title = "音色(voice_type)",
|
||||
voices = vm.state.speechVoices["volc"].orEmpty(),
|
||||
voicesAll = vm.state.speechVoicesAll["volc"].orEmpty(),
|
||||
value = draft.speech.ttsVoice,
|
||||
placeholder = "留空 = BV700_streaming(通用女声)",
|
||||
onValue = { draft = draft.copy(speech = draft.speech.copy(ttsVoice = it)) },
|
||||
@@ -614,8 +621,27 @@ private fun VoicePicker(
|
||||
value: String,
|
||||
placeholder: String,
|
||||
onValue: (String) -> Unit,
|
||||
/** 全量音色(V1 73 / V3 90)。给了才会出现「全部音色」按钮 */
|
||||
voicesAll: List<VoiceOption> = emptyList(),
|
||||
) {
|
||||
FormLabel(title)
|
||||
var showAll by remember { mutableStateOf(false) }
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
FormLabel(title)
|
||||
// 90 个音色铺成胶囊没法看,所以"常用几个"+"全部(可搜索)"两段式
|
||||
if (voicesAll.size > voices.size) {
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(
|
||||
"全部 ${voicesAll.size} 个 ›",
|
||||
color = Doubao.Blue,
|
||||
fontSize = 13.sp,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.clickable { showAll = true }
|
||||
.padding(horizontal = 4.dp, vertical = 2.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
if (voices.isNotEmpty()) {
|
||||
Spacer(Modifier.height(6.dp))
|
||||
// 每行 2 个:音色名后面带括号备注("通用女声(BV700)"),一行 3 个会挤到折字
|
||||
@@ -626,6 +652,109 @@ private fun VoicePicker(
|
||||
}
|
||||
}
|
||||
FormField(value = value, placeholder = placeholder, onValue = onValue)
|
||||
|
||||
if (showAll) {
|
||||
VoiceListDialog(
|
||||
voices = voicesAll,
|
||||
current = value,
|
||||
onPick = { onValue(it); showAll = false },
|
||||
onDismiss = { showAll = false },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量音色的可搜索列表。
|
||||
*
|
||||
* 163 个音色不可能靠翻 —— 必须能搜。搜索同时匹配**名字和 id**:
|
||||
* 用户可能记得"灿灿",也可能手里就攥着一串 `BV700_streaming` 要核对,
|
||||
* 两种都得能搜到。
|
||||
*/
|
||||
@Composable
|
||||
private fun VoiceListDialog(
|
||||
voices: List<VoiceOption>,
|
||||
current: String,
|
||||
onPick: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
var query by remember { mutableStateOf("") }
|
||||
val filtered = remember(query, voices) {
|
||||
val q = query.trim().lowercase()
|
||||
if (q.isEmpty()) voices
|
||||
else voices.filter {
|
||||
it.label.lowercase().contains(q) || it.value.lowercase().contains(q)
|
||||
}
|
||||
}
|
||||
// 一次别渲染 163 行 —— LazyColumn 按需组合
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
Dialog(onDismissRequest = onDismiss) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
color = doubaoSurface(),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(max = 560.dp),
|
||||
) {
|
||||
Column(Modifier.padding(16.dp)) {
|
||||
Text("选择音色", fontSize = 17.sp, fontWeight = FontWeight.SemiBold, color = doubaoText())
|
||||
Spacer(Modifier.height(10.dp))
|
||||
OutlinedTextField(
|
||||
value = query,
|
||||
onValueChange = { query = it },
|
||||
placeholder = { Text("搜名字或 voice_type,比如「灿灿」或 BV700", fontSize = 14.sp) },
|
||||
singleLine = true,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
if (query.isBlank()) "共 ${voices.size} 个" else "匹配 ${filtered.size} 个",
|
||||
fontSize = 12.sp,
|
||||
color = doubaoTextSecondary(),
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
if (filtered.isEmpty()) {
|
||||
Box(Modifier.fillMaxWidth().height(120.dp), contentAlignment = Alignment.Center) {
|
||||
Text("没搜到。换个词,或者直接在下面手填 voice_type。",
|
||||
fontSize = 13.sp, color = doubaoTextSecondary())
|
||||
}
|
||||
} else {
|
||||
LazyColumn(state = listState, modifier = Modifier.weight(1f, fill = false)) {
|
||||
items(filtered.size) { i ->
|
||||
val v = filtered[i]
|
||||
val active = v.value == current
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.clickable { onPick(v.value) }
|
||||
.background(if (active) Doubao.Blue.copy(alpha = 0.10f) else Color.Transparent)
|
||||
.padding(horizontal = 10.dp, vertical = 9.dp),
|
||||
) {
|
||||
Text(
|
||||
v.label.ifBlank { v.value },
|
||||
fontSize = 15.sp,
|
||||
color = if (active) Doubao.Blue else doubaoText(),
|
||||
fontWeight = if (active) FontWeight.Medium else FontWeight.Normal,
|
||||
)
|
||||
// id 也显示出来:用户要拿它跟控制台核对,藏起来等于没给
|
||||
Text(v.value, fontSize = 11.sp, color = doubaoTextSecondary())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
"取消",
|
||||
color = Doubao.Blue,
|
||||
fontSize = 15.sp,
|
||||
modifier = Modifier
|
||||
.align(Alignment.End)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.clickable(onClick = onDismiss)
|
||||
.padding(horizontal = 12.dp, vertical = 6.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 语速取值范围:内核允许 0.2~3.0,界面只放开常用的这段(再极端就不是"听"了) */
|
||||
|
||||
Reference in New Issue
Block a user