Commit 0aff8cf0 authored by ali's avatar ali

fix: 处理 vosk_asr 打包后无法加载模型问题

parent 3351ca7a
...@@ -55,9 +55,9 @@ export default class IPCs { ...@@ -55,9 +55,9 @@ export default class IPCs {
}) })
win.webContents.on('did-frame-finish-load', (): void => { win.webContents.on('did-frame-finish-load', (): void => {
if (Constants.IS_DEV_ENV) { // if (Constants.IS_DEV_ENV) {
win.webContents.openDevTools() win.webContents.openDevTools()
} // }
}) })
await win.loadURL(url) await win.loadURL(url)
......
...@@ -51,6 +51,15 @@ async function changeSource() { ...@@ -51,6 +51,15 @@ async function changeSource() {
console.log(res) console.log(res)
} }
const voskModelLoading = ref(false);
async function changeVoskModel(){
voskModelLoading.value = true;
await settings.downLoadVoskModel();
voskModelLoading.value = false;
}
changeVoskModel();
</script> </script>
<template> <template>
<v-app-bar color="#d71b1b" density="compact" class="header"> <v-app-bar color="#d71b1b" density="compact" class="header">
...@@ -98,6 +107,9 @@ async function changeSource() { ...@@ -98,6 +107,9 @@ async function changeSource() {
:items="setting.voskModels.value" :items="setting.voskModels.value"
label="vosk_asr 模型" label="vosk_asr 模型"
required required
:loading="voskModelLoading"
:disabled="voskModelLoading"
@update:model-value="changeVoskModel"
></v-select> ></v-select>
</template> </template>
......
This diff is collapsed.
The Developer of the ASR models is Alpha Cephei Inc (https://alphacephei.com/e).
Copyright 2019 Alpha Cephei Inc. All Rights Reserved.
\ No newline at end of file
...@@ -7,16 +7,19 @@ import { storeToRefs } from 'pinia' ...@@ -7,16 +7,19 @@ import { storeToRefs } from 'pinia'
const { photo: usePhoto, settings } = useStore() const { photo: usePhoto, settings } = useStore()
const photo = storeToRefs(usePhoto) const photo = storeToRefs(usePhoto)
onMounted((): void => { onMounted((): void => {})
})
async function handleOpen(event: Event, url: string) { async function handleOpen(event: Event, url: string) {
const img = event.target as HTMLImageElement; const img = event.target as HTMLImageElement
await window.mainApi.send('openWindow', `${location.origin + location.pathname}#show?url=${url}`, { await window.mainApi.send(
'openWindow',
`${location.origin + location.pathname}#show?url=${url}`,
{
width: img.naturalWidth / 2, width: img.naturalWidth / 2,
height: img.naturalHeight / 2, height: img.naturalHeight / 2,
fullscreen: settings.isFullscreen === 'yes' fullscreen: settings.isFullscreen === 'yes'
}) }
)
} }
const validateURL = (url: string) => { const validateURL = (url: string) => {
......
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { Vosk } from '@/renderer/plugins/asr/index'
import type { import type {
ServerMessagePartialResult, ServerMessagePartialResult,
ServerMessageResult, ServerMessageResult,
...@@ -16,7 +15,7 @@ const { settings } = useStore() ...@@ -16,7 +15,7 @@ const { settings } = useStore()
const sampleRate = 48000 const sampleRate = 48000
const recordVolume = ref(0) const recordVolume = ref(0)
const url = route.query.url as string; const url = route.query.url as string
router.beforeEach((g) => { router.beforeEach((g) => {
if (!g.query.url) return router.push('/error') if (!g.query.url) return router.push('/error')
...@@ -34,7 +33,7 @@ async function initVosk({ ...@@ -34,7 +33,7 @@ async function initVosk({
partialResult?: (string) => void partialResult?: (string) => void
}) { }) {
const channel = new MessageChannel() const channel = new MessageChannel()
const model = await Vosk.createModel(modelPath) const model = await settings.downLoadVoskModel();
const recognizer = new model.KaldiRecognizer(sampleRate) const recognizer = new model.KaldiRecognizer(sampleRate)
model.registerPort(channel.port1) model.registerPort(channel.port1)
...@@ -103,7 +102,7 @@ async function startAudioInput() { ...@@ -103,7 +102,7 @@ async function startAudioInput() {
microphoneState.value = 'loading' microphoneState.value = 'loading'
const { recognizer, channel } = await initVosk({ const { recognizer, channel } = await initVosk({
modelPath: new URL('/vosk/models/' + settings.voskSelectModel, import.meta.url).href, modelPath: `https://resources.laihua.com/2023-11-29/${settings.voskSelectModel}`,
result: async (text) => { result: async (text) => {
console.log('----------------> text:', text) console.log('----------------> text:', text)
const tone = settings.source.find(({ sourceId }) => settings.selectSource === sourceId) const tone = settings.source.find(({ sourceId }) => settings.selectSource === sourceId)
...@@ -167,12 +166,12 @@ function endAudioInput() { ...@@ -167,12 +166,12 @@ function endAudioInput() {
</script> </script>
<template> <template>
<div style="width: 100%; height: 100%" class="d-flex justify-center align-center" :style="{ background: '#000' }"> <div
<v-img style="width: 100%; height: 100%"
v-if="url" class="d-flex justify-center align-center"
aspect-ratio="9/16" :style="{ background: '#000' }"
:src="url" >
></v-img> <v-img v-if="url" aspect-ratio="9/16" :src="url"></v-img>
</div> </div>
<div class="voice"> <div class="voice">
......
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { Vosk } from '@/renderer/plugins/asr/index'
import type {
Model
} from '@/renderer/plugins/asr/index'
const voskModelMap: Map<string, Model | null> = new Map();
export type ISettings = { export type ISettings = {
asr: 'vosk_asr' | 'xf_asr' asr: 'vosk_asr' | 'xf_asr'
...@@ -13,7 +19,7 @@ export type ISettings = { ...@@ -13,7 +19,7 @@ export type ISettings = {
description: string description: string
sex: 1 | 0 sex: 1 | 0
}[] }[]
selectSource: string, selectSource: string
isFullscreen: 'yes' | 'no' isFullscreen: 'yes' | 'no'
} }
...@@ -55,6 +61,16 @@ const useSettingsStore = defineStore('settings', { ...@@ -55,6 +61,16 @@ const useSettingsStore = defineStore('settings', {
if (res.code !== 200) return if (res.code !== 200) return
this.source = res.data this.source = res.data
},
async downLoadVoskModel() {
if (voskModelMap.has(this.$state.voskSelectModel)){
return voskModelMap.get(this.$state.voskSelectModel) as Model
}
const model = await Vosk.createModel(`https://resources.laihua.com/2023-11-29/${this.$state.voskSelectModel}`);
voskModelMap.set(this.$state.voskSelectModel, model);
return model;
} }
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment