improve library exception

This commit is contained in:
wataru 2023-06-11 10:55:26 +09:00
parent 74d277714b
commit e6b58a8613
11 changed files with 1969 additions and 71 deletions

View File

@ -1 +1,10 @@
<!doctype html><html style="width:100%;height:100%;overflow:hidden"><head><meta charset="utf-8"/><title>Voice Changer Client Demo</title><script defer="defer" src="index.js"></script></head><body style="width:100%;height:100%;margin:0"><div id="app" style="width:100%;height:100%"></div></body></html> <!DOCTYPE html>
<html style="width: 100%; height: 100%; overflow: hidden">
<head>
<meta charset="utf-8" />
<title>Voice Changer Client Demo</title>
<script defer src="index.js"></script></head>
<body style="width: 100%; height: 100%; margin: 0px">
<div id="app" style="width: 100%; height: 100%"></div>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -1,31 +0,0 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

View File

@ -10,7 +10,6 @@ export type TitleProps = {
export const Title = (props: TitleProps) => { export const Title = (props: TitleProps) => {
const githubLink = useMemo(() => { const githubLink = useMemo(() => {
return isDesktopApp() ? return isDesktopApp() ?
( (

View File

@ -58,6 +58,13 @@ export const AppStateProvider = ({ children }: Props) => {
} }
}, [clientState.clientState.initialized]) }, [clientState.clientState.initialized])
useEffect(() => {
if (clientState.clientState.ioErrorCount > 100) {
alert("エラーが頻発しています。対象としているフレームワークのモデルがロードされているか確認してください。")
clientState.clientState.resetIoErrorCount()
}
}, [clientState.clientState.ioErrorCount])
const providerValue: AppStateValue = { const providerValue: AppStateValue = {

View File

@ -258,7 +258,11 @@ export const ModelSlotManagerDialog = () => {
sampleId: id, sampleId: id,
isSampleMode: true isSampleMode: true
} }
await serverSetting.loadModel(fromNetTargetIndex) try {
await serverSetting.loadModel(fromNetTargetIndex)
} catch (e) {
alert(e)
}
setMode("localFile") setMode("localFile")
} }
const options = ( const options = (

View File

@ -15,7 +15,12 @@ export const ModelUploadButtonRow2 = (_props: ModelUploadButtonRow2Props) => {
return <></> return <></>
} }
const onModelUploadClicked = async () => { const onModelUploadClicked = async () => {
appState.serverSetting.loadModel(slot) try {
await appState.serverSetting.loadModel(slot)
} catch (e) {
console.log(e)
alert(e)
}
} }
const buttonText = appState.serverSetting.fileUploadSettings[slot].isSampleMode ? "select" : "upload" const buttonText = appState.serverSetting.fileUploadSettings[slot].isSampleMode ? "select" : "upload"

View File

@ -0,0 +1,9 @@
export class ModelLoadException extends Error {
public causeFileType: string = ""
constructor(causeFileType: string) {
super(`Model Load Exception:${causeFileType}`);
this.causeFileType = causeFileType;
this.name = this.constructor.name;
Error.captureStackTrace(this);
}
}

View File

@ -34,6 +34,9 @@ export type ClientState = {
clearSetting: () => Promise<void> clearSetting: () => Promise<void>
// AudioOutputElement 設定 // AudioOutputElement 設定
setAudioOutputElementId: (elemId: string) => void setAudioOutputElementId: (elemId: string) => void
ioErrorCount: number
resetIoErrorCount: () => void
} }
export type PerformanceData = { export type PerformanceData = {
@ -77,6 +80,7 @@ export const useClient = (props: UseClientProps): ClientState => {
const [bufferingTime, setBufferingTime] = useState<number>(0) const [bufferingTime, setBufferingTime] = useState<number>(0)
const [performance, setPerformance] = useState<PerformanceData>(InitialPerformanceData) const [performance, setPerformance] = useState<PerformanceData>(InitialPerformanceData)
const [volume, setVolume] = useState<number>(0) const [volume, setVolume] = useState<number>(0)
const [ioErrorCount, setIoErrorCount] = useState<number>(0)
//// Server Audio Deviceを使うとき、モニタリングデータはpolling //// Server Audio Deviceを使うとき、モニタリングデータはpolling
const updatePerformance = useMemo(() => { const updatePerformance = useMemo(() => {
@ -105,7 +109,11 @@ export const useClient = (props: UseClientProps): ClientState => {
// (1-4) エラーステータス // (1-4) エラーステータス
const errorCountRef = useRef<number>(0) const ioErrorCountRef = useRef<number>(0)
const resetIoErrorCount = () => {
ioErrorCountRef.current = 0
setIoErrorCount(ioErrorCountRef.current)
}
// (2-1) 初期化処理 // (2-1) 初期化処理
useEffect(() => { useEffect(() => {
@ -127,11 +135,8 @@ export const useClient = (props: UseClientProps): ClientState => {
notifyException: (mes: string) => { notifyException: (mes: string) => {
if (mes.length > 0) { if (mes.length > 0) {
console.log(`error:${mes}`) console.log(`error:${mes}`)
errorCountRef.current += 1 ioErrorCountRef.current += 1
if (errorCountRef.current > 100) { setIoErrorCount(ioErrorCountRef.current)
alert("エラーが頻発しています。対象としているフレームワークのモデルがロードされているか確認してください。")
errorCountRef.current = 0
}
} }
}, },
notifyVolume: (vol: number) => { notifyVolume: (vol: number) => {
@ -207,5 +212,8 @@ export const useClient = (props: UseClientProps): ClientState => {
// AudioOutputElement 設定 // AudioOutputElement 設定
setAudioOutputElementId, setAudioOutputElementId,
ioErrorCount,
resetIoErrorCount
} }
} }

View File

@ -2,6 +2,7 @@ import { useState, useMemo, useEffect } from "react"
import { VoiceChangerServerSetting, ServerInfo, ServerSettingKey, INDEXEDDB_KEY_SERVER, INDEXEDDB_KEY_MODEL_DATA, ClientType, DefaultServerSetting_MMVCv13, DefaultServerSetting_MMVCv15, DefaultServerSetting_so_vits_svc_40v2, DefaultServerSetting_so_vits_svc_40, DefaultServerSetting_so_vits_svc_40_c, DefaultServerSetting_RVC, OnnxExporterInfo, DefaultServerSetting_DDSP_SVC, MAX_MODEL_SLOT_NUM, Framework, MergeModelRequest } from "../const" import { VoiceChangerServerSetting, ServerInfo, ServerSettingKey, INDEXEDDB_KEY_SERVER, INDEXEDDB_KEY_MODEL_DATA, ClientType, DefaultServerSetting_MMVCv13, DefaultServerSetting_MMVCv15, DefaultServerSetting_so_vits_svc_40v2, DefaultServerSetting_so_vits_svc_40, DefaultServerSetting_so_vits_svc_40_c, DefaultServerSetting_RVC, OnnxExporterInfo, DefaultServerSetting_DDSP_SVC, MAX_MODEL_SLOT_NUM, Framework, MergeModelRequest } from "../const"
import { VoiceChangerClient } from "../VoiceChangerClient" import { VoiceChangerClient } from "../VoiceChangerClient"
import { useIndexedDB } from "./useIndexedDB" import { useIndexedDB } from "./useIndexedDB"
import { ModelLoadException } from "../exceptions"
type ModelData = { type ModelData = {
@ -265,68 +266,54 @@ export const useServerSetting = (props: UseServerSettingProps): ServerSettingSta
if (fileUploadSetting.isSampleMode == false) { if (fileUploadSetting.isSampleMode == false) {
if (props.clientType == "MMVCv13") { if (props.clientType == "MMVCv13") {
if (!fileUploadSetting.mmvcv13Config) { if (!fileUploadSetting.mmvcv13Config) {
alert("Configファイルを指定する必要があります。") throw new ModelLoadException("Config")
return
} }
if (!fileUploadSetting.mmvcv13Model) { if (!fileUploadSetting.mmvcv13Model) {
alert("モデルファイルを指定する必要があります。") throw new ModelLoadException("Model")
return
} }
} else if (props.clientType == "MMVCv15") { } else if (props.clientType == "MMVCv15") {
if (!fileUploadSetting.mmvcv15Config) { if (!fileUploadSetting.mmvcv15Config) {
alert("Configファイルを指定する必要があります。") throw new ModelLoadException("Config")
return
} }
if (!fileUploadSetting.mmvcv15Model) { if (!fileUploadSetting.mmvcv15Model) {
alert("モデルファイルを指定する必要があります。") throw new ModelLoadException("Model")
return
} }
} else if (props.clientType == "so-vits-svc-40") { } else if (props.clientType == "so-vits-svc-40") {
if (!fileUploadSetting.soVitsSvc40Config) { if (!fileUploadSetting.soVitsSvc40Config) {
alert("Configファイルを指定する必要があります。") throw new ModelLoadException("Config")
return
} }
if (!fileUploadSetting.soVitsSvc40Model) { if (!fileUploadSetting.soVitsSvc40Model) {
alert("モデルファイルを指定する必要があります。") throw new ModelLoadException("Model")
return
} }
} else if (props.clientType == "so-vits-svc-40v2") { } else if (props.clientType == "so-vits-svc-40v2") {
if (!fileUploadSetting.soVitsSvc40v2Config) { if (!fileUploadSetting.soVitsSvc40v2Config) {
alert("Configファイルを指定する必要があります。") throw new ModelLoadException("Config")
return
} }
if (!fileUploadSetting.soVitsSvc40v2Model) { if (!fileUploadSetting.soVitsSvc40v2Model) {
alert("モデルファイルを指定する必要があります。") throw new ModelLoadException("Model")
return
} }
} else if (props.clientType == "RVC") { } else if (props.clientType == "RVC") {
if (!fileUploadSetting.rvcModel) { if (!fileUploadSetting.rvcModel) {
alert("モデルファイルを指定する必要があります。") throw new ModelLoadException("Model")
return
} }
} else if (props.clientType == "DDSP-SVC") { } else if (props.clientType == "DDSP-SVC") {
if (!fileUploadSetting.ddspSvcModel) { if (!fileUploadSetting.ddspSvcModel) {
alert("DDSPモデルを指定する必要があります。") throw new ModelLoadException("DDSP-Model")
return
} }
if (!fileUploadSetting.ddspSvcModelConfig) { if (!fileUploadSetting.ddspSvcModelConfig) {
alert("DDSP Configファイルを指定する必要があります。") throw new ModelLoadException("DDSP-Config")
return
} }
if (!fileUploadSetting.ddspSvcDiffusion) { if (!fileUploadSetting.ddspSvcDiffusion) {
alert("Diffusionモデルを指定する必要があります。") throw new ModelLoadException("Diff-Model")
return
} }
if (!fileUploadSetting.ddspSvcDiffusionConfig) { if (!fileUploadSetting.ddspSvcDiffusionConfig) {
alert("Diffusion Configファイルを指定する必要があります。") throw new ModelLoadException("Diff-Config")
return
} }
} else { } else {
} }
} else {//Sampleモード } else {//Sampleモード
if (!fileUploadSetting.sampleId) { if (!fileUploadSetting.sampleId) {
alert("Sample IDを指定する必要があります。") throw new ModelLoadException("SampleId")
return
} }
} }

View File

@ -1,4 +1,5 @@
export * from "./const" export * from "./const"
export * from "./exceptions"
export * from "./VoiceChangerClient" export * from "./VoiceChangerClient"
export * from "./util" export * from "./util"
export * from "./hooks/useClient" export * from "./hooks/useClient"