mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
[feat] add custom wake word logic
This commit is contained in:
parent
5af12dc168
commit
fa61faf395
10 changed files with 488 additions and 62 deletions
|
|
@ -0,0 +1,2 @@
|
|||
# (neural network type)_(model data version)_(lable1_detection windown length_threshold for 90%_threshold for 95%)_(lable2 ...)_...
|
||||
MN5Q8_v2_chinese_8_0.9_0.90
|
||||
BIN
main/manager-web/public/static/wakenet_model/mn5q8_cn/mn5q8_data
Normal file
BIN
main/manager-web/public/static/wakenet_model/mn5q8_cn/mn5q8_data
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -26,8 +26,10 @@
|
|||
<div class="tab-content-wrapper">
|
||||
<CustomThemeWakewordConfig
|
||||
v-if="currentTab === 'wakeword'"
|
||||
v-model="localValue.wakeword"
|
||||
:value="localValue.wakeword"
|
||||
:chip-model="chipModel"
|
||||
@input="handleWakewordInput"
|
||||
@custom-wakeword-change="handleCustomWakewordChange"
|
||||
/>
|
||||
<CustomThemeFontConfig
|
||||
v-if="currentTab === 'font'"
|
||||
|
|
@ -109,6 +111,9 @@ export default {
|
|||
return (tabId) => {
|
||||
switch (tabId) {
|
||||
case 'wakeword':
|
||||
if (this.localValue.wakeword === 'custom') {
|
||||
return !!(this.localValue.customWakeword && this.localValue.customWakeword.chinese && this.localValue.customWakeword.pinyin);
|
||||
}
|
||||
return !!this.localValue.wakeword;
|
||||
case 'font':
|
||||
return this.localValue.font.preset || this.localValue.font.custom.file;
|
||||
|
|
@ -143,6 +148,29 @@ export default {
|
|||
},
|
||||
handlePrev() {
|
||||
this.$emit('prev');
|
||||
},
|
||||
handleWakewordInput(value) {
|
||||
// 更新唤醒词值
|
||||
const newValue = {
|
||||
...this.localValue,
|
||||
wakeword: value
|
||||
};
|
||||
this.$emit('input', newValue);
|
||||
},
|
||||
handleCustomWakewordChange(data) {
|
||||
// 创建新的配置对象,确保响应式更新
|
||||
const newValue = {
|
||||
...this.localValue,
|
||||
wakeword: data.wakeword
|
||||
};
|
||||
// 保存自定义唤醒词数据
|
||||
if (data.customWakeword) {
|
||||
newValue.customWakeword = data.customWakeword;
|
||||
} else {
|
||||
delete newValue.customWakeword;
|
||||
}
|
||||
// 触发更新
|
||||
this.$emit('input', newValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -720,7 +720,8 @@ export default {
|
|||
for (const token of tokens) {
|
||||
const headerVariants = [
|
||||
{ Authorization: `Bearer ${token}` },
|
||||
{ Authorization: token }
|
||||
{ Authorization: token },
|
||||
{ token }
|
||||
];
|
||||
for (const headers of headerVariants) {
|
||||
const res = await fetch(`${base}/api/messages/publish`, {
|
||||
|
|
|
|||
|
|
@ -59,9 +59,10 @@
|
|||
|
||||
<div v-if="modelValue.light.backgroundType === 'image'" class="upload-center">
|
||||
<div class="upload-side">
|
||||
<el-upload
|
||||
class="dashed-upload"
|
||||
action=""
|
||||
<div v-if="!modelValue.light.backgroundImage" class="upload-wrapper">
|
||||
<el-upload
|
||||
class="dashed-upload"
|
||||
action=""
|
||||
:auto-upload="false"
|
||||
:on-change="(f)=>handleBgUpload(f, 'light')"
|
||||
accept=".png,.jpg,.jpeg"
|
||||
|
|
@ -71,10 +72,41 @@
|
|||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">{{ $t('device.customThemeBackgroundImageUpload') }}</div>
|
||||
</el-upload>
|
||||
<span class="file-name" v-if="modelValue.light.backgroundImage">{{ fileName(modelValue.light.backgroundImage) }}</span>
|
||||
<el-button v-if="modelValue.light.backgroundImage" size="mini" type="text" @click="clearBg('light')">
|
||||
{{ $t('device.customThemeRemoveImage') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<div v-else class="preview-wrapper">
|
||||
<img
|
||||
:src="modelValue.light.backgroundImage"
|
||||
alt="背景预览"
|
||||
class="preview-image"
|
||||
/>
|
||||
<div class="preview-overlay">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-refresh"
|
||||
@click="triggerReupload('light')"
|
||||
class="preview-btn"
|
||||
>
|
||||
{{ $t('device.customThemeBackgroundImageUpload') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="clearBg('light')"
|
||||
class="preview-btn"
|
||||
>
|
||||
{{ $t('device.customThemeRemoveImage') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<input
|
||||
ref="lightFileInput"
|
||||
type="file"
|
||||
accept=".png,.jpg,.jpeg"
|
||||
style="display: none"
|
||||
@change="(e) => handleFileInputChange(e, 'light')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -134,9 +166,10 @@
|
|||
|
||||
<div v-if="modelValue.dark.backgroundType === 'image'" class="upload-center">
|
||||
<div class="upload-side">
|
||||
<el-upload
|
||||
class="dashed-upload"
|
||||
action=""
|
||||
<div v-if="!modelValue.dark.backgroundImage" class="upload-wrapper">
|
||||
<el-upload
|
||||
class="dashed-upload"
|
||||
action=""
|
||||
:auto-upload="false"
|
||||
:on-change="(f)=>handleBgUpload(f, 'dark')"
|
||||
accept=".png,.jpg,.jpeg"
|
||||
|
|
@ -146,10 +179,41 @@
|
|||
<i class="el-icon-upload"></i>
|
||||
<div class="el-upload__text">{{ $t('device.customThemeBackgroundImageUpload') }}</div>
|
||||
</el-upload>
|
||||
<span class="file-name" v-if="modelValue.dark.backgroundImage">{{ fileName(modelValue.dark.backgroundImage) }}</span>
|
||||
<el-button v-if="modelValue.dark.backgroundImage" size="mini" type="text" @click="clearBg('dark')">
|
||||
{{ $t('device.customThemeRemoveImage') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<div v-else class="preview-wrapper">
|
||||
<img
|
||||
:src="modelValue.dark.backgroundImage"
|
||||
alt="背景预览"
|
||||
class="preview-image"
|
||||
/>
|
||||
<div class="preview-overlay">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-refresh"
|
||||
@click="triggerReupload('dark')"
|
||||
class="preview-btn"
|
||||
>
|
||||
{{ $t('device.customThemeBackgroundImageUpload') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="clearBg('dark')"
|
||||
class="preview-btn"
|
||||
>
|
||||
{{ $t('device.customThemeRemoveImage') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<input
|
||||
ref="darkFileInput"
|
||||
type="file"
|
||||
accept=".png,.jpg,.jpeg"
|
||||
style="display: none"
|
||||
@change="(e) => handleFileInputChange(e, 'dark')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -337,20 +401,105 @@ export default {
|
|||
return false;
|
||||
}
|
||||
const url = URL.createObjectURL(f);
|
||||
// 同时保存 File 对象和 URL,以便后续处理
|
||||
if (mode === 'light') {
|
||||
this.modelValue = { ...this.modelValue, light: { ...this.modelValue.light, backgroundImage: url, backgroundType: 'image' } };
|
||||
this.modelValue = {
|
||||
...this.modelValue,
|
||||
light: {
|
||||
...this.modelValue.light,
|
||||
backgroundImage: url,
|
||||
backgroundImageFile: f, // 保存原始 File 对象
|
||||
backgroundType: 'image'
|
||||
}
|
||||
};
|
||||
} else {
|
||||
this.modelValue = { ...this.modelValue, dark: { ...this.modelValue.dark, backgroundImage: url, backgroundType: 'image' } };
|
||||
this.modelValue = {
|
||||
...this.modelValue,
|
||||
dark: {
|
||||
...this.modelValue.dark,
|
||||
backgroundImage: url,
|
||||
backgroundImageFile: f, // 保存原始 File 对象
|
||||
backgroundType: 'image'
|
||||
}
|
||||
};
|
||||
}
|
||||
return false;
|
||||
},
|
||||
clearBg(mode) {
|
||||
if (mode === 'light') {
|
||||
this.modelValue = { ...this.modelValue, light: { ...this.modelValue.light, backgroundImage: '', backgroundType: 'color' } };
|
||||
// 释放 blob URL
|
||||
if (this.modelValue.light.backgroundImage && this.modelValue.light.backgroundImage.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(this.modelValue.light.backgroundImage)
|
||||
}
|
||||
this.modelValue = {
|
||||
...this.modelValue,
|
||||
light: {
|
||||
...this.modelValue.light,
|
||||
backgroundImage: '',
|
||||
backgroundImageFile: null, // 清除 File 对象
|
||||
backgroundType: 'color'
|
||||
}
|
||||
};
|
||||
} else {
|
||||
this.modelValue = { ...this.modelValue, dark: { ...this.modelValue.dark, backgroundImage: '', backgroundType: 'color' } };
|
||||
// 释放 blob URL
|
||||
if (this.modelValue.dark.backgroundImage && this.modelValue.dark.backgroundImage.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(this.modelValue.dark.backgroundImage)
|
||||
}
|
||||
this.modelValue = {
|
||||
...this.modelValue,
|
||||
dark: {
|
||||
...this.modelValue.dark,
|
||||
backgroundImage: '',
|
||||
backgroundImageFile: null, // 清除 File 对象
|
||||
backgroundType: 'color'
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
triggerReupload(mode) {
|
||||
// 触发文件选择
|
||||
const inputRef = mode === 'light' ? this.$refs.lightFileInput : this.$refs.darkFileInput
|
||||
if (inputRef) {
|
||||
inputRef.click()
|
||||
}
|
||||
},
|
||||
handleFileInputChange(event, mode) {
|
||||
const file = event.target.files?.[0]
|
||||
if (file && /\.(png|jpg|jpeg)$/i.test(file.name)) {
|
||||
// 释放旧的 blob URL
|
||||
if (mode === 'light' && this.modelValue.light.backgroundImage && this.modelValue.light.backgroundImage.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(this.modelValue.light.backgroundImage)
|
||||
} else if (mode === 'dark' && this.modelValue.dark.backgroundImage && this.modelValue.dark.backgroundImage.startsWith('blob:')) {
|
||||
URL.revokeObjectURL(this.modelValue.dark.backgroundImage)
|
||||
}
|
||||
|
||||
// 创建新的 blob URL 并保存 File 对象
|
||||
const url = URL.createObjectURL(file)
|
||||
if (mode === 'light') {
|
||||
this.modelValue = {
|
||||
...this.modelValue,
|
||||
light: {
|
||||
...this.modelValue.light,
|
||||
backgroundImage: url,
|
||||
backgroundImageFile: file,
|
||||
backgroundType: 'image'
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.modelValue = {
|
||||
...this.modelValue,
|
||||
dark: {
|
||||
...this.modelValue.dark,
|
||||
backgroundImage: url,
|
||||
backgroundImageFile: file,
|
||||
backgroundType: 'image'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 清空 input,以便可以再次选择同一文件
|
||||
event.target.value = ''
|
||||
},
|
||||
fileName(url) {
|
||||
if (!url) return '';
|
||||
const parts = url.split('/');
|
||||
|
|
@ -439,14 +588,15 @@ export default {
|
|||
}
|
||||
.upload-center {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex: 0 0 auto;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-width: 120px;
|
||||
max-width: 100%;
|
||||
width: 360px;
|
||||
min-width: 360px;
|
||||
max-width: 360px;
|
||||
overflow: visible;
|
||||
box-sizing: border-box;
|
||||
padding: 0 10px;
|
||||
padding: 0;
|
||||
}
|
||||
.color-item {
|
||||
display: flex;
|
||||
|
|
@ -487,14 +637,15 @@ export default {
|
|||
border: 2px dashed #909399;
|
||||
border-radius: 4px;
|
||||
padding: 2px 0;
|
||||
width: 100px;
|
||||
min-width: 100px;
|
||||
max-width: 100px;
|
||||
width: 360px;
|
||||
min-width: 360px;
|
||||
max-width: 360px;
|
||||
height: 180px;
|
||||
min-height: 180px;
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
|
@ -509,15 +660,62 @@ export default {
|
|||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
width: 120px;
|
||||
min-width: 120px;
|
||||
max-width: 120px;
|
||||
width: 360px;
|
||||
min-width: 360px;
|
||||
max-width: 360px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
overflow: visible;
|
||||
}
|
||||
.upload-wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
.preview-wrapper {
|
||||
position: relative;
|
||||
width: 360px !important;
|
||||
min-width: 360px !important;
|
||||
max-width: 360px !important;
|
||||
height: 180px !important;
|
||||
min-height: 180px !important;
|
||||
border: 2px dashed #909399;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.preview-image {
|
||||
width: 360px !important;
|
||||
height: 180px !important;
|
||||
min-width: 360px !important;
|
||||
min-height: 180px !important;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.preview-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
.preview-wrapper:hover .preview-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
.preview-btn {
|
||||
color: #fff !important;
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.dashed-upload .el-upload__text {
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
style="width: 100%"
|
||||
@change="selectWakeword"
|
||||
>
|
||||
<el-option
|
||||
label="自定义 (mn5q8_cn)"
|
||||
value="custom"
|
||||
/>
|
||||
<el-option
|
||||
v-for="wakeword in availableWakewords"
|
||||
:key="wakeword.id"
|
||||
|
|
@ -28,7 +32,29 @@
|
|||
</el-select>
|
||||
</div>
|
||||
|
||||
<div v-if="localValue" class="selected-info">
|
||||
<!-- 自定义唤醒词输入框 -->
|
||||
<div v-if="localValue === 'custom'" class="custom-wakeword-section">
|
||||
<div class="custom-input-row">
|
||||
<div class="custom-input-item">
|
||||
<label class="custom-input-label">Custom Wake Word</label>
|
||||
<el-input
|
||||
v-model="customWakeword.pinyin"
|
||||
placeholder="请输入拼音,用空格分隔,如:ni hao xiao zhi"
|
||||
@input="updateCustomWakeword"
|
||||
/>
|
||||
</div>
|
||||
<div class="custom-input-item">
|
||||
<label class="custom-input-label">Custom Wake Word Display</label>
|
||||
<el-input
|
||||
v-model="customWakeword.chinese"
|
||||
placeholder="请输入拼音,不用空格分隔,如:nihaoxiaozhi"
|
||||
@input="updateCustomWakeword"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="localValue && localValue !== 'custom'" class="selected-info">
|
||||
<div class="selected-content">
|
||||
<div class="selected-icon"><i class="el-icon-success"></i></div>
|
||||
<div class="selected-details">
|
||||
|
|
@ -39,6 +65,17 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="localValue === 'custom' && customWakeword.chinese && customWakeword.pinyin" class="selected-info">
|
||||
<div class="selected-content">
|
||||
<div class="selected-icon"><i class="el-icon-success"></i></div>
|
||||
<div class="selected-details">
|
||||
<div class="selected-title">自定义唤醒词: {{ customWakeword.chinese }}</div>
|
||||
<div class="selected-meta">拼音: {{ customWakeword.pinyin }}</div>
|
||||
<div class="selected-meta">模型: Multinet5Q8 (mn5q8_cn)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tips-card">
|
||||
<div class="tips-title">{{ $t('device.customThemeTips') }}</div>
|
||||
<ul class="tips-list">
|
||||
|
|
@ -72,7 +109,11 @@ export default {
|
|||
{ id: 'wn9s_hilexin', name: 'Hi,乐鑫', model: 'WakeNet9s' },
|
||||
{ id: 'wn9s_nihaoxiaozhi', name: '你好小智', model: 'WakeNet9s' },
|
||||
{ id: 'wn7_xiaoaitongxue', name: '小爱同学', model: 'WakeNet7' }
|
||||
]
|
||||
],
|
||||
customWakeword: {
|
||||
chinese: '',
|
||||
pinyin: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
|
@ -94,7 +135,29 @@ export default {
|
|||
methods: {
|
||||
selectWakeword(id) {
|
||||
console.log('[CustomThemeWakeword] select', id);
|
||||
this.localValue = id || '';
|
||||
const newValue = id || '';
|
||||
// 如果切换到非自定义选项,清空自定义唤醒词
|
||||
if (id !== 'custom') {
|
||||
this.customWakeword = { chinese: '', pinyin: '' };
|
||||
}
|
||||
// 更新 localValue,这会触发 input 事件
|
||||
this.$emit('input', newValue);
|
||||
// 通知父组件更新自定义唤醒词配置
|
||||
this.$nextTick(() => {
|
||||
this.$emit('custom-wakeword-change', {
|
||||
wakeword: newValue,
|
||||
customWakeword: newValue === 'custom' ? this.customWakeword : null
|
||||
});
|
||||
});
|
||||
},
|
||||
updateCustomWakeword() {
|
||||
// 通知父组件更新自定义唤醒词配置
|
||||
if (this.localValue === 'custom') {
|
||||
this.$emit('custom-wakeword-change', {
|
||||
wakeword: this.localValue,
|
||||
customWakeword: this.customWakeword
|
||||
});
|
||||
}
|
||||
},
|
||||
getSelectedWakewordName() {
|
||||
const selected = this.wakewordData.find(w => w.id === this.localValue);
|
||||
|
|
@ -182,5 +245,23 @@ export default {
|
|||
color: #1e3a8a;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.custom-wakeword-section {
|
||||
margin: 14px 0;
|
||||
}
|
||||
.custom-input-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.custom-input-item {
|
||||
flex: 1;
|
||||
}
|
||||
.custom-input-label {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 6px;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
|
|
|||
|
|
@ -249,6 +249,21 @@ class AssetsBuilder {
|
|||
|
||||
if (!wakeword) return null
|
||||
|
||||
// 处理自定义唤醒词(使用 multinet 模型)
|
||||
if (wakeword === 'custom') {
|
||||
const customWakeword = this.config.theme.customWakeword
|
||||
if (!customWakeword || !customWakeword.chinese || !customWakeword.pinyin) {
|
||||
throw new Error('自定义唤醒词配置不完整,请填写中文和拼音')
|
||||
}
|
||||
return {
|
||||
name: 'mn5q8_cn',
|
||||
type: 'Multinet5Q8',
|
||||
filename: 'srmodels.bin',
|
||||
isCustom: true,
|
||||
customWakeword: customWakeword
|
||||
}
|
||||
}
|
||||
|
||||
// 根据唤醒词模型名称确定类型(而不是根据芯片型号)
|
||||
// 因为实际文件目录中只有 WakeNet9s 和 WakeNet7 模型,没有 WakeNet9 模型
|
||||
let modelType = 'WakeNet9s' // 默认值
|
||||
|
|
@ -267,7 +282,8 @@ class AssetsBuilder {
|
|||
return {
|
||||
name: wakeword,
|
||||
type: modelType,
|
||||
filename: 'srmodels.bin'
|
||||
filename: 'srmodels.bin',
|
||||
isCustom: false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -451,6 +467,26 @@ class AssetsBuilder {
|
|||
}))
|
||||
}
|
||||
|
||||
// 添加自定义唤醒词配置(multinet_model_info)
|
||||
// wakewordInfo 已在上面声明,直接使用
|
||||
if (wakewordInfo && wakewordInfo.isCustom && wakewordInfo.customWakeword) {
|
||||
indexData.multinet_model_info = {
|
||||
language: 'cn',
|
||||
duration: 3000,
|
||||
threshold: 20, // 默认阈值
|
||||
commands: [
|
||||
{
|
||||
command: wakewordInfo.customWakeword.pinyin,
|
||||
text: wakewordInfo.customWakeword.chinese,
|
||||
action: 'wake'
|
||||
}
|
||||
]
|
||||
}
|
||||
// 添加 CONFIG 字段
|
||||
indexData.CONFIG_CUSTOM_WAKE_WORD = wakewordInfo.customWakeword.pinyin
|
||||
indexData.CONFIG_CUSTOM_WAKE_WORD_DISPLAY = wakewordInfo.customWakeword.chinese
|
||||
}
|
||||
|
||||
return indexData
|
||||
}
|
||||
|
||||
|
|
@ -472,7 +508,9 @@ class AssetsBuilder {
|
|||
type: 'wakeword',
|
||||
name: wakewordInfo.name,
|
||||
filename: wakewordInfo.filename,
|
||||
modelType: wakewordInfo.type
|
||||
modelType: wakewordInfo.type,
|
||||
isCustom: wakewordInfo.isCustom || false,
|
||||
customWakeword: wakewordInfo.customWakeword || null
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -501,21 +539,29 @@ class AssetsBuilder {
|
|||
|
||||
// 添加背景图片
|
||||
const skin = this.config?.theme?.skin
|
||||
if (skin?.light?.backgroundType === 'image' && skin.light.backgroundImage) {
|
||||
resources.files.push({
|
||||
type: 'background',
|
||||
filename: 'background_light.raw',
|
||||
source: skin.light.backgroundImage,
|
||||
mode: 'light'
|
||||
})
|
||||
if (skin?.light?.backgroundType === 'image') {
|
||||
// 优先使用保存的 File 对象,否则使用 URL
|
||||
const source = skin.light.backgroundImageFile || skin.light.backgroundImage
|
||||
if (source) {
|
||||
resources.files.push({
|
||||
type: 'background',
|
||||
filename: 'background_light.raw',
|
||||
source: source,
|
||||
mode: 'light'
|
||||
})
|
||||
}
|
||||
}
|
||||
if (skin?.dark?.backgroundType === 'image' && skin.dark.backgroundImage) {
|
||||
resources.files.push({
|
||||
type: 'background',
|
||||
filename: 'background_dark.raw',
|
||||
source: skin.dark.backgroundImage,
|
||||
mode: 'dark'
|
||||
})
|
||||
if (skin?.dark?.backgroundType === 'image') {
|
||||
// 优先使用保存的 File 对象,否则使用 URL
|
||||
const source = skin.dark.backgroundImageFile || skin.dark.backgroundImage
|
||||
if (source) {
|
||||
resources.files.push({
|
||||
type: 'background',
|
||||
filename: 'background_dark.raw',
|
||||
source: source,
|
||||
mode: 'dark'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return resources
|
||||
|
|
@ -918,7 +964,33 @@ class AssetsBuilder {
|
|||
* @param {Object} resource - 资源配置
|
||||
*/
|
||||
async processBackgroundFile(resource) {
|
||||
const imageData = await this.fileToArrayBuffer(resource.source)
|
||||
let imageData
|
||||
|
||||
// 如果 source 是 URL 字符串,需要先通过 fetch 获取
|
||||
if (typeof resource.source === 'string') {
|
||||
try {
|
||||
const response = await fetch(resource.source)
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
||||
}
|
||||
const blob = await response.blob()
|
||||
|
||||
// 验证 blob 类型
|
||||
if (!(blob instanceof Blob)) {
|
||||
throw new Error(`fetch 返回的不是 Blob 对象,类型: ${typeof blob}`)
|
||||
}
|
||||
|
||||
imageData = await this.fileToArrayBuffer(blob)
|
||||
} catch (error) {
|
||||
console.error('加载背景图片失败:', error)
|
||||
throw new Error(`加载背景图片失败: ${resource.filename} - ${error.message}`)
|
||||
}
|
||||
} else if (resource.source instanceof File || resource.source instanceof Blob) {
|
||||
// 如果是 File 或 Blob 对象,直接转换
|
||||
imageData = await this.fileToArrayBuffer(resource.source)
|
||||
} else {
|
||||
throw new Error(`不支持的背景图片格式: ${resource.filename},source 类型: ${typeof resource.source}`)
|
||||
}
|
||||
|
||||
// 将图片转换为RGB565格式的原始数据
|
||||
const rawData = await this.convertImageToRgb565(imageData)
|
||||
|
|
@ -970,14 +1042,36 @@ class AssetsBuilder {
|
|||
|
||||
/**
|
||||
* 将文件转换为ArrayBuffer
|
||||
* @param {File|Blob} file - 文件对象
|
||||
* @param {File|Blob|ArrayBuffer} file - 文件对象或 ArrayBuffer
|
||||
* @returns {Promise<ArrayBuffer>} 文件数据
|
||||
*/
|
||||
fileToArrayBuffer(file) {
|
||||
// 如果已经是 ArrayBuffer,直接返回
|
||||
if (file instanceof ArrayBuffer) {
|
||||
return Promise.resolve(file)
|
||||
}
|
||||
|
||||
// 验证类型
|
||||
if (!(file instanceof File) && !(file instanceof Blob)) {
|
||||
const errorMsg = `fileToArrayBuffer 需要 File 或 Blob 对象,但收到: ${typeof file}, 构造函数: ${file?.constructor?.name || 'unknown'}`
|
||||
console.error('fileToArrayBuffer 类型错误:', {
|
||||
file,
|
||||
type: typeof file,
|
||||
constructor: file?.constructor?.name,
|
||||
isFile: file instanceof File,
|
||||
isBlob: file instanceof Blob,
|
||||
isArrayBuffer: file instanceof ArrayBuffer
|
||||
})
|
||||
return Promise.reject(new Error(errorMsg))
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = () => resolve(reader.result)
|
||||
reader.onerror = () => reject(new Error('读取文件失败'))
|
||||
reader.onerror = (e) => {
|
||||
console.error('FileReader 错误:', e)
|
||||
reject(new Error('读取文件失败'))
|
||||
}
|
||||
reader.readAsArrayBuffer(file)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,17 +52,30 @@ class WakenetModelPacker {
|
|||
|
||||
/**
|
||||
* 从share/wakenet_model目录加载模型
|
||||
* @param {string} modelName - 模型名称 (例如: wn9s_nihaoxiaozhi)
|
||||
* @param {string} modelName - 模型名称 (例如: wn9s_nihaoxiaozhi 或 mn5q8_cn)
|
||||
* @returns {Promise<boolean>} 加载是否成功
|
||||
*/
|
||||
async loadModelFromShare(modelName) {
|
||||
try {
|
||||
// 所有wakenet模型都使用相同的文件名
|
||||
const modelFiles = [
|
||||
'_MODEL_INFO_',
|
||||
'wn9_data',
|
||||
'wn9_index'
|
||||
]
|
||||
// 根据模型类型确定文件列表
|
||||
let modelFiles = []
|
||||
if (modelName.startsWith('mn')) {
|
||||
// Multinet 模型 (例如: mn5q8_cn)
|
||||
// 根据模型名称提取前缀 (mn5q8)
|
||||
const prefix = modelName.split('_')[0]
|
||||
modelFiles = [
|
||||
'_MODEL_INFO_',
|
||||
`${prefix}_data`,
|
||||
`${prefix}_index`
|
||||
]
|
||||
} else {
|
||||
// Wakenet 模型 (例如: wn9s_nihaoxiaozhi)
|
||||
modelFiles = [
|
||||
'_MODEL_INFO_',
|
||||
'wn9_data',
|
||||
'wn9_index'
|
||||
]
|
||||
}
|
||||
|
||||
let loadedFiles = 0
|
||||
const failedFiles = []
|
||||
|
|
|
|||
|
|
@ -43,7 +43,12 @@
|
|||
</el-table-column>
|
||||
<el-table-column :label="$t('device.customTheme')" align="center" width="140">
|
||||
<template #default="{ row }">
|
||||
<el-button type="text" size="mini" @click="handleCustomThemeConfig(row)">
|
||||
<el-button
|
||||
type="text"
|
||||
size="mini"
|
||||
:disabled="row.deviceStatus !== 'online'"
|
||||
@click="handleCustomThemeConfig(row)"
|
||||
>
|
||||
{{ $t('device.customThemeConfig') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
|
@ -228,6 +233,10 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
handleCustomThemeConfig(row) {
|
||||
if (row.deviceStatus !== 'online') {
|
||||
this.$message.warning(this.$t('device.customThemeConfig') + ':设备不在线,无法配置');
|
||||
return;
|
||||
}
|
||||
this.selectedDeviceForTheme = row;
|
||||
this.customThemeDialogVisible = true;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue