feat: 支持音色切换
This commit is contained in:
@@ -9,7 +9,7 @@ import markdown from "@/components/markdown.vue";
|
||||
import { useAsrStore, useChatStore, useLayoutStore } from "@/stores";
|
||||
|
||||
const chatStore = useChatStore();
|
||||
const { historyMessages, completing, modelList, modelInfo, thinking } =
|
||||
const { historyMessages, completing, speakerList, speakerInfo, thinking } =
|
||||
storeToRefs(chatStore);
|
||||
const asrStore = useAsrStore();
|
||||
const { isRecording } = storeToRefs(asrStore);
|
||||
@@ -58,39 +58,43 @@ const handleItemHeaderClick = (name: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 处理选中模型的 ID
|
||||
const selectedModelId = computed({
|
||||
get: () => modelInfo.value?.model_id ?? null,
|
||||
// 处理选中speaker的 ID
|
||||
const selectedSpeakerId = computed({
|
||||
get: () => speakerInfo.value?.speaker_id ?? null,
|
||||
set: (id: string | null) => {
|
||||
for (const vendor of modelList.value) {
|
||||
const found = vendor.models.find((model) => model.model_id === id);
|
||||
for (const category of speakerList.value) {
|
||||
const found = category.speakers.find(
|
||||
(speaker) => speaker.speaker_id === id
|
||||
);
|
||||
if (found) {
|
||||
modelInfo.value = found;
|
||||
speakerInfo.value = found;
|
||||
return;
|
||||
}
|
||||
}
|
||||
modelInfo.value = null;
|
||||
speakerInfo.value = null;
|
||||
}
|
||||
});
|
||||
|
||||
// 监听模型列表变化,更新选项
|
||||
// 监听speaker列表变化,更新选项
|
||||
watch(
|
||||
() => modelList.value,
|
||||
() => speakerList.value,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
options.value = newVal.map((vendor) => ({
|
||||
options.value = newVal.map((category) => ({
|
||||
type: "group",
|
||||
label: vendor.vendor,
|
||||
key: vendor.vendor,
|
||||
children: vendor.models.map((model) => ({
|
||||
label: model.model_name,
|
||||
value: model.model_id,
|
||||
type: model.model_type
|
||||
label: category.category,
|
||||
key: category.category,
|
||||
children: category.speakers.map((speaker) => ({
|
||||
label: speaker.speaker_name,
|
||||
value: speaker.speaker_id,
|
||||
language: speaker.language,
|
||||
platforms: speaker.platforms
|
||||
}))
|
||||
}));
|
||||
|
||||
if (newVal.length > 0 && newVal[0].models.length > 0) {
|
||||
modelInfo.value = newVal[0].models[0];
|
||||
// 默认选择第一个speaker
|
||||
if (newVal.length > 0 && newVal[0].speakers.length > 0) {
|
||||
speakerInfo.value = newVal[0].speakers[0];
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -115,7 +119,7 @@ watch(completing, (newVal) => {
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
chatStore.getModelList();
|
||||
chatStore.getSpeakerList();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -207,7 +211,7 @@ onMounted(() => {
|
||||
<div class="flex justify-between items-center gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<NSelect
|
||||
v-model:value="selectedModelId"
|
||||
v-model:value="selectedSpeakerId"
|
||||
label-field="label"
|
||||
value-field="value"
|
||||
children-field="children"
|
||||
|
||||
Reference in New Issue
Block a user