2023-02-19 10:12:25 +09:00
|
|
|
|
import { useState, useMemo, useEffect } from "react"
|
2023-04-24 16:43:51 +09:00
|
|
|
|
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 } from "../const"
|
2023-01-12 23:01:45 +09:00
|
|
|
|
import { VoiceChangerClient } from "../VoiceChangerClient"
|
2023-01-29 09:42:45 +09:00
|
|
|
|
import { useIndexedDB } from "./useIndexedDB"
|
2023-01-12 16:38:45 +09:00
|
|
|
|
|
|
|
|
|
|
2023-01-29 14:41:44 +09:00
|
|
|
|
type ModelData = {
|
2023-01-29 15:25:44 +09:00
|
|
|
|
file?: File
|
|
|
|
|
data?: ArrayBuffer
|
|
|
|
|
filename?: string
|
2023-01-29 14:41:44 +09:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
export type FileUploadSetting = {
|
2023-01-29 14:41:44 +09:00
|
|
|
|
pyTorchModel: ModelData | null
|
|
|
|
|
onnxModel: ModelData | null
|
|
|
|
|
configFile: ModelData | null
|
2023-03-14 05:18:37 +09:00
|
|
|
|
clusterTorchModel: ModelData | null
|
2023-04-08 03:11:37 +09:00
|
|
|
|
|
|
|
|
|
feature: ModelData | null //RVC
|
|
|
|
|
index: ModelData | null //RVC
|
|
|
|
|
|
2023-04-08 03:56:40 +09:00
|
|
|
|
isHalf: boolean
|
2023-04-21 15:48:12 +09:00
|
|
|
|
uploaded: boolean
|
|
|
|
|
defaultTune: number
|
2023-04-24 16:43:51 +09:00
|
|
|
|
framework: Framework
|
2023-04-22 05:42:24 +09:00
|
|
|
|
params: string
|
2023-04-08 03:56:40 +09:00
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
2023-01-29 14:41:44 +09:00
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
const InitialFileUploadSetting: FileUploadSetting = {
|
|
|
|
|
pyTorchModel: null,
|
|
|
|
|
configFile: null,
|
|
|
|
|
onnxModel: null,
|
2023-03-14 09:57:52 +09:00
|
|
|
|
clusterTorchModel: null,
|
2023-04-08 03:11:37 +09:00
|
|
|
|
|
|
|
|
|
feature: null,
|
2023-04-08 03:56:40 +09:00
|
|
|
|
index: null,
|
|
|
|
|
|
2023-04-21 15:48:12 +09:00
|
|
|
|
isHalf: true,
|
|
|
|
|
uploaded: false,
|
2023-04-22 05:42:24 +09:00
|
|
|
|
defaultTune: 0,
|
2023-04-24 16:43:51 +09:00
|
|
|
|
framework: Framework.PyTorch,
|
2023-04-22 05:42:24 +09:00
|
|
|
|
params: "{}"
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
2023-01-29 14:41:44 +09:00
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
export type UseServerSettingProps = {
|
2023-04-11 00:21:17 +09:00
|
|
|
|
clientType: ClientType | null
|
2023-01-12 16:38:45 +09:00
|
|
|
|
voiceChangerClient: VoiceChangerClient | null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ServerSettingState = {
|
2023-02-19 10:12:25 +09:00
|
|
|
|
serverSetting: ServerInfo
|
|
|
|
|
updateServerSettings: (setting: ServerInfo) => Promise<void>
|
2023-01-29 09:42:45 +09:00
|
|
|
|
clearSetting: () => Promise<void>
|
2023-01-12 16:38:45 +09:00
|
|
|
|
reloadServerInfo: () => Promise<void>;
|
2023-02-19 10:12:25 +09:00
|
|
|
|
|
2023-04-21 15:48:12 +09:00
|
|
|
|
fileUploadSettings: FileUploadSetting[]
|
|
|
|
|
setFileUploadSetting: (slot: number, val: FileUploadSetting) => void
|
|
|
|
|
loadModel: (slot: number) => Promise<void>
|
2023-01-12 16:38:45 +09:00
|
|
|
|
uploadProgress: number
|
|
|
|
|
isUploading: boolean
|
2023-02-19 10:12:25 +09:00
|
|
|
|
|
2023-04-13 08:00:28 +09:00
|
|
|
|
getOnnx: () => Promise<OnnxExporterInfo>
|
2023-04-22 05:42:24 +09:00
|
|
|
|
// updateDefaultTune: (slot: number, tune: number) => void
|
2023-04-13 08:00:28 +09:00
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useServerSetting = (props: UseServerSettingProps): ServerSettingState => {
|
2023-02-19 10:12:25 +09:00
|
|
|
|
// const settingRef = useRef<VoiceChangerServerSetting>(DefaultVoiceChangerServerSetting)
|
2023-04-11 00:21:17 +09:00
|
|
|
|
const getDefaultServerSetting = () => {
|
2023-03-09 06:55:57 +09:00
|
|
|
|
if (props.clientType == "MMVCv13") {
|
|
|
|
|
return DefaultServerSetting_MMVCv13
|
|
|
|
|
} else if (props.clientType == "MMVCv15") {
|
|
|
|
|
return DefaultServerSetting_MMVCv15
|
2023-04-05 18:08:06 +09:00
|
|
|
|
} else if (props.clientType == "so-vits-svc-40") {
|
2023-03-19 01:43:36 +09:00
|
|
|
|
return DefaultServerSetting_so_vits_svc_40
|
2023-04-05 18:08:06 +09:00
|
|
|
|
} else if (props.clientType == "so-vits-svc-40_c") {
|
|
|
|
|
console.log("default so_vits_svc_40_c")
|
|
|
|
|
return DefaultServerSetting_so_vits_svc_40_c
|
|
|
|
|
} else if (props.clientType == "so-vits-svc-40v2") {
|
2023-03-11 08:37:41 +09:00
|
|
|
|
return DefaultServerSetting_so_vits_svc_40v2
|
2023-04-16 21:34:00 +09:00
|
|
|
|
} else if (props.clientType == "DDSP-SVC") {
|
|
|
|
|
return DefaultServerSetting_DDSP_SVC
|
2023-04-06 04:03:09 +09:00
|
|
|
|
} else if (props.clientType == "RVC") {
|
|
|
|
|
return DefaultServerSetting_RVC
|
2023-03-09 06:55:57 +09:00
|
|
|
|
} else {
|
|
|
|
|
return DefaultServerSetting_MMVCv15
|
|
|
|
|
}
|
2023-04-11 00:21:17 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [serverSetting, setServerSetting] = useState<ServerInfo>(getDefaultServerSetting())
|
2023-04-21 15:48:12 +09:00
|
|
|
|
const [fileUploadSettings, setFileUploadSettings] = useState<FileUploadSetting[]>([])
|
2023-03-09 06:47:11 +09:00
|
|
|
|
const { setItem, getItem, removeItem } = useIndexedDB({ clientType: props.clientType })
|
2023-01-29 09:42:45 +09:00
|
|
|
|
|
|
|
|
|
|
2023-04-11 00:21:17 +09:00
|
|
|
|
// clientTypeが新しく設定されたときに、serverのmodelType動作を変更+設定反映
|
2023-01-29 09:42:45 +09:00
|
|
|
|
useEffect(() => {
|
2023-04-11 00:21:17 +09:00
|
|
|
|
if (!props.voiceChangerClient) return
|
|
|
|
|
if (!props.clientType) return
|
|
|
|
|
const setInitialSetting = async () => {
|
|
|
|
|
// Set Model Type
|
|
|
|
|
await props.voiceChangerClient!.switchModelType(props.clientType!)
|
|
|
|
|
|
|
|
|
|
// Load Default (and Cache) and set
|
|
|
|
|
const defaultServerSetting = getDefaultServerSetting()
|
|
|
|
|
const cachedServerSetting = await getItem(INDEXEDDB_KEY_SERVER)
|
|
|
|
|
let initialSetting: ServerInfo
|
|
|
|
|
if (cachedServerSetting) {
|
2023-04-20 17:17:43 +09:00
|
|
|
|
initialSetting = { ...defaultServerSetting, ...cachedServerSetting as ServerInfo, inputSampleRate: 48000 }// sample rateは時限措置
|
2023-01-29 09:42:45 +09:00
|
|
|
|
} else {
|
2023-04-11 00:21:17 +09:00
|
|
|
|
initialSetting = { ...defaultServerSetting }
|
|
|
|
|
}
|
|
|
|
|
setServerSetting(initialSetting)
|
|
|
|
|
|
|
|
|
|
// upload setting
|
|
|
|
|
for (let i = 0; i < Object.values(ServerSettingKey).length; i++) {
|
|
|
|
|
const k = Object.values(ServerSettingKey)[i] as keyof VoiceChangerServerSetting
|
|
|
|
|
const v = initialSetting[k]
|
|
|
|
|
if (v) {
|
|
|
|
|
props.voiceChangerClient!.updateServerSettings(k, "" + v)
|
|
|
|
|
}
|
2023-01-29 09:42:45 +09:00
|
|
|
|
}
|
2023-01-29 15:25:44 +09:00
|
|
|
|
|
2023-04-21 15:48:12 +09:00
|
|
|
|
// Load file upload cache
|
|
|
|
|
const loadedFileUploadSettings: FileUploadSetting[] = []
|
|
|
|
|
for (let i = 0; i < MAX_MODEL_SLOT_NUM; i++) {
|
|
|
|
|
const modleKey = `${INDEXEDDB_KEY_MODEL_DATA}_${i}`
|
|
|
|
|
const fileuploadSetting = await getItem(modleKey)
|
|
|
|
|
if (!fileuploadSetting) {
|
|
|
|
|
loadedFileUploadSettings.push(InitialFileUploadSetting)
|
|
|
|
|
} else {
|
|
|
|
|
loadedFileUploadSettings.push(fileuploadSetting as FileUploadSetting)
|
|
|
|
|
}
|
2023-01-29 15:25:44 +09:00
|
|
|
|
}
|
2023-04-21 15:48:12 +09:00
|
|
|
|
setFileUploadSettings(loadedFileUploadSettings)
|
|
|
|
|
|
2023-04-11 00:21:17 +09:00
|
|
|
|
|
|
|
|
|
reloadServerInfo()
|
2023-01-29 09:42:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-11 00:21:17 +09:00
|
|
|
|
setInitialSetting()
|
2023-02-19 06:25:22 +09:00
|
|
|
|
|
2023-04-11 00:21:17 +09:00
|
|
|
|
}, [props.voiceChangerClient, props.clientType])
|
2023-01-12 16:38:45 +09:00
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
|
// 設定
|
|
|
|
|
/////////////
|
2023-02-19 10:12:25 +09:00
|
|
|
|
const updateServerSettings = useMemo(() => {
|
|
|
|
|
return async (setting: ServerInfo) => {
|
|
|
|
|
if (!props.voiceChangerClient) return
|
|
|
|
|
for (let i = 0; i < Object.values(ServerSettingKey).length; i++) {
|
|
|
|
|
const k = Object.values(ServerSettingKey)[i] as keyof VoiceChangerServerSetting
|
|
|
|
|
const cur_v = serverSetting[k]
|
|
|
|
|
const new_v = setting[k]
|
|
|
|
|
if (cur_v != new_v) {
|
|
|
|
|
const res = await props.voiceChangerClient.updateServerSettings(k, "" + new_v)
|
2023-04-11 00:21:17 +09:00
|
|
|
|
if (res.onnxExecutionProviders && res.onnxExecutionProviders.length > 0) {
|
2023-02-21 17:54:02 +09:00
|
|
|
|
res.onnxExecutionProvider = res.onnxExecutionProviders[0]
|
|
|
|
|
} else {
|
|
|
|
|
res.onnxExecutionProvider = "CPUExecutionProvider"
|
|
|
|
|
}
|
2023-02-19 10:12:25 +09:00
|
|
|
|
|
|
|
|
|
setServerSetting(res)
|
2023-02-20 07:46:33 +09:00
|
|
|
|
const storeData = { ...res }
|
|
|
|
|
storeData.recordIO = 0
|
|
|
|
|
setItem(INDEXEDDB_KEY_SERVER, storeData)
|
2023-02-19 10:12:25 +09:00
|
|
|
|
}
|
2023-01-29 09:42:45 +09:00
|
|
|
|
}
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
2023-02-19 10:12:25 +09:00
|
|
|
|
}, [props.voiceChangerClient, serverSetting])
|
2023-02-19 06:25:22 +09:00
|
|
|
|
|
2023-04-21 15:48:12 +09:00
|
|
|
|
const setFileUploadSetting = useMemo(() => {
|
|
|
|
|
return async (slot: number, fileUploadSetting: FileUploadSetting) => {
|
|
|
|
|
fileUploadSetting.uploaded = false
|
|
|
|
|
fileUploadSettings[slot] = fileUploadSetting
|
|
|
|
|
setFileUploadSettings([...fileUploadSettings])
|
|
|
|
|
}
|
|
|
|
|
}, [fileUploadSettings])
|
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
|
// 操作
|
|
|
|
|
/////////////
|
|
|
|
|
const [uploadProgress, setUploadProgress] = useState<number>(0)
|
|
|
|
|
const [isUploading, setIsUploading] = useState<boolean>(false)
|
|
|
|
|
|
|
|
|
|
// (e) モデルアップロード
|
|
|
|
|
const _uploadFile = useMemo(() => {
|
2023-01-29 14:41:44 +09:00
|
|
|
|
return async (modelData: ModelData, onprogress: (progress: number, end: boolean) => void) => {
|
2023-01-12 16:38:45 +09:00
|
|
|
|
if (!props.voiceChangerClient) return
|
2023-01-29 15:25:44 +09:00
|
|
|
|
const num = await props.voiceChangerClient.uploadFile(modelData.data!, modelData.filename!, onprogress)
|
|
|
|
|
const res = await props.voiceChangerClient.concatUploadedFile(modelData.filename!, num)
|
2023-01-12 16:38:45 +09:00
|
|
|
|
console.log("uploaded", num, res)
|
|
|
|
|
}
|
|
|
|
|
}, [props.voiceChangerClient])
|
|
|
|
|
const loadModel = useMemo(() => {
|
2023-04-21 15:48:12 +09:00
|
|
|
|
return async (slot: number) => {
|
|
|
|
|
if (!fileUploadSettings[slot].pyTorchModel && !fileUploadSettings[slot].onnxModel) {
|
2023-01-12 16:38:45 +09:00
|
|
|
|
alert("PyTorchモデルとONNXモデルのどちらか一つ以上指定する必要があります。")
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-04-21 15:48:12 +09:00
|
|
|
|
if (!fileUploadSettings[slot].configFile && props.clientType != "RVC") {
|
2023-01-12 16:38:45 +09:00
|
|
|
|
alert("Configファイルを指定する必要があります。")
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-03-14 09:57:52 +09:00
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
if (!props.voiceChangerClient) return
|
2023-01-29 14:41:44 +09:00
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
setUploadProgress(0)
|
|
|
|
|
setIsUploading(true)
|
2023-01-29 14:41:44 +09:00
|
|
|
|
|
2023-04-08 03:11:37 +09:00
|
|
|
|
// ファイルをメモリにロード(dataがある場合は、キャッシュから読まれていると想定しスキップ)
|
2023-04-21 15:48:12 +09:00
|
|
|
|
const fileUploadSetting = fileUploadSettings[slot]
|
2023-01-29 15:25:44 +09:00
|
|
|
|
if (fileUploadSetting.onnxModel && !fileUploadSetting.onnxModel.data) {
|
|
|
|
|
fileUploadSetting.onnxModel.data = await fileUploadSetting.onnxModel.file!.arrayBuffer()
|
|
|
|
|
fileUploadSetting.onnxModel.filename = await fileUploadSetting.onnxModel.file!.name
|
|
|
|
|
}
|
|
|
|
|
if (fileUploadSetting.pyTorchModel && !fileUploadSetting.pyTorchModel.data) {
|
|
|
|
|
fileUploadSetting.pyTorchModel.data = await fileUploadSetting.pyTorchModel.file!.arrayBuffer()
|
|
|
|
|
fileUploadSetting.pyTorchModel.filename = await fileUploadSetting.pyTorchModel.file!.name
|
|
|
|
|
}
|
2023-04-06 04:27:46 +09:00
|
|
|
|
if (fileUploadSetting.configFile && !fileUploadSetting.configFile.data) {
|
2023-01-29 15:25:44 +09:00
|
|
|
|
fileUploadSetting.configFile.data = await fileUploadSetting.configFile.file!.arrayBuffer()
|
|
|
|
|
fileUploadSetting.configFile.filename = await fileUploadSetting.configFile.file!.name
|
|
|
|
|
}
|
2023-04-20 16:35:42 +09:00
|
|
|
|
|
2023-03-14 11:04:00 +09:00
|
|
|
|
if (fileUploadSetting.clusterTorchModel) {
|
2023-04-05 18:08:06 +09:00
|
|
|
|
if ((props.clientType == "so-vits-svc-40v2" || props.clientType == "so-vits-svc-40") && !fileUploadSetting.clusterTorchModel!.data) {
|
2023-03-14 11:04:00 +09:00
|
|
|
|
fileUploadSetting.clusterTorchModel!.data = await fileUploadSetting.clusterTorchModel!.file!.arrayBuffer()
|
|
|
|
|
fileUploadSetting.clusterTorchModel!.filename = await fileUploadSetting.clusterTorchModel!.file!.name
|
|
|
|
|
}
|
2023-03-14 05:18:37 +09:00
|
|
|
|
}
|
2023-03-15 22:43:59 +09:00
|
|
|
|
|
2023-04-08 03:11:37 +09:00
|
|
|
|
if (fileUploadSetting.feature) {
|
|
|
|
|
if ((props.clientType == "RVC") && !fileUploadSetting.feature!.data) {
|
|
|
|
|
fileUploadSetting.feature!.data = await fileUploadSetting.feature!.file!.arrayBuffer()
|
|
|
|
|
fileUploadSetting.feature!.filename = await fileUploadSetting.feature!.file!.name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (fileUploadSetting.index) {
|
|
|
|
|
if ((props.clientType == "RVC") && !fileUploadSetting.index!.data) {
|
|
|
|
|
fileUploadSetting.index!.data = await fileUploadSetting.index!.file!.arrayBuffer()
|
|
|
|
|
fileUploadSetting.index!.filename = await fileUploadSetting.index!.file!.name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-29 15:25:44 +09:00
|
|
|
|
// ファイルをサーバにアップロード
|
2023-04-08 03:11:37 +09:00
|
|
|
|
const models = [
|
|
|
|
|
fileUploadSetting.onnxModel,
|
|
|
|
|
fileUploadSetting.pyTorchModel,
|
|
|
|
|
fileUploadSetting.clusterTorchModel,
|
|
|
|
|
fileUploadSetting.feature,
|
|
|
|
|
fileUploadSetting.index,
|
|
|
|
|
].filter(x => { return x != null }) as ModelData[]
|
2023-01-12 16:38:45 +09:00
|
|
|
|
for (let i = 0; i < models.length; i++) {
|
|
|
|
|
const progRate = 1 / models.length
|
|
|
|
|
const progOffset = 100 * i * progRate
|
2023-01-12 23:01:45 +09:00
|
|
|
|
await _uploadFile(models[i], (progress: number, _end: boolean) => {
|
2023-01-12 16:38:45 +09:00
|
|
|
|
// console.log(progress * progRate + progOffset, end, progRate,)
|
|
|
|
|
setUploadProgress(progress * progRate + progOffset)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-06 04:27:46 +09:00
|
|
|
|
if (fileUploadSetting.configFile) {
|
|
|
|
|
await _uploadFile(fileUploadSetting.configFile, (progress: number, end: boolean) => {
|
|
|
|
|
console.log(progress, end)
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-01-12 16:38:45 +09:00
|
|
|
|
|
2023-04-06 04:27:46 +09:00
|
|
|
|
const configFileName = fileUploadSetting.configFile ? fileUploadSetting.configFile.filename || "-" : "-"
|
2023-04-22 05:42:24 +09:00
|
|
|
|
const params = JSON.stringify({
|
2023-04-25 18:53:24 +09:00
|
|
|
|
trans: fileUploadSetting.defaultTune || 0
|
2023-04-22 05:42:24 +09:00
|
|
|
|
})
|
2023-04-25 18:53:24 +09:00
|
|
|
|
if (fileUploadSetting.isHalf == undefined) {
|
|
|
|
|
fileUploadSetting.isHalf = false
|
|
|
|
|
}
|
2023-04-08 03:11:37 +09:00
|
|
|
|
const loadPromise = props.voiceChangerClient.loadModel(
|
2023-04-21 15:48:12 +09:00
|
|
|
|
slot,
|
2023-04-08 03:11:37 +09:00
|
|
|
|
configFileName,
|
|
|
|
|
fileUploadSetting.pyTorchModel?.filename || null,
|
|
|
|
|
fileUploadSetting.onnxModel?.filename || null,
|
|
|
|
|
fileUploadSetting.clusterTorchModel?.filename || null,
|
|
|
|
|
fileUploadSetting.feature?.filename || null,
|
2023-04-08 03:56:40 +09:00
|
|
|
|
fileUploadSetting.index?.filename || null,
|
2023-04-22 05:42:24 +09:00
|
|
|
|
fileUploadSetting.isHalf,
|
|
|
|
|
params,
|
2023-04-08 03:11:37 +09:00
|
|
|
|
)
|
2023-01-29 15:25:44 +09:00
|
|
|
|
|
|
|
|
|
// サーバでロード中にキャッシュにセーブ
|
2023-04-21 15:48:12 +09:00
|
|
|
|
storeToCache(slot, fileUploadSetting)
|
2023-01-29 15:25:44 +09:00
|
|
|
|
|
|
|
|
|
await loadPromise
|
2023-04-21 15:48:12 +09:00
|
|
|
|
|
|
|
|
|
fileUploadSetting.uploaded = true
|
|
|
|
|
fileUploadSettings[slot] = fileUploadSetting
|
|
|
|
|
setFileUploadSettings([...fileUploadSettings])
|
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
setUploadProgress(0)
|
|
|
|
|
setIsUploading(false)
|
2023-01-28 15:56:56 +09:00
|
|
|
|
reloadServerInfo()
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
2023-04-21 15:48:12 +09:00
|
|
|
|
}, [fileUploadSettings, props.voiceChangerClient, props.clientType])
|
|
|
|
|
|
|
|
|
|
|
2023-04-22 05:42:24 +09:00
|
|
|
|
// const updateDefaultTune = (slot: number, tune: number) => {
|
|
|
|
|
// fileUploadSettings[slot].defaultTune = tune
|
|
|
|
|
// storeToCache(slot, fileUploadSettings[slot])
|
|
|
|
|
// setFileUploadSettings([...fileUploadSettings])
|
|
|
|
|
// }
|
2023-04-21 15:48:12 +09:00
|
|
|
|
|
|
|
|
|
const storeToCache = (slot: number, fileUploadSetting: FileUploadSetting) => {
|
|
|
|
|
try {
|
|
|
|
|
const saveData: FileUploadSetting = {
|
|
|
|
|
pyTorchModel: fileUploadSetting.pyTorchModel ? { data: fileUploadSetting.pyTorchModel.data, filename: fileUploadSetting.pyTorchModel.filename } : null,
|
|
|
|
|
onnxModel: fileUploadSetting.onnxModel ? { data: fileUploadSetting.onnxModel.data, filename: fileUploadSetting.onnxModel.filename } : null,
|
|
|
|
|
configFile: fileUploadSetting.configFile ? { data: fileUploadSetting.configFile.data, filename: fileUploadSetting.configFile.filename } : null,
|
|
|
|
|
clusterTorchModel: fileUploadSetting.clusterTorchModel ? {
|
|
|
|
|
data: fileUploadSetting.clusterTorchModel.data, filename: fileUploadSetting.clusterTorchModel.filename
|
|
|
|
|
} : null,
|
|
|
|
|
feature: fileUploadSetting.feature ? {
|
|
|
|
|
data: fileUploadSetting.feature.data, filename: fileUploadSetting.feature.filename
|
|
|
|
|
} : null,
|
|
|
|
|
index: fileUploadSetting.index ? {
|
|
|
|
|
data: fileUploadSetting.index.data, filename: fileUploadSetting.index.filename
|
|
|
|
|
} : null,
|
|
|
|
|
isHalf: fileUploadSetting.isHalf, // キャッシュとしては不使用。guiで上書きされる。
|
|
|
|
|
uploaded: false, // キャッシュから読み込まれるときには、まだuploadされていないから。
|
2023-04-22 05:42:24 +09:00
|
|
|
|
defaultTune: fileUploadSetting.defaultTune,
|
2023-04-24 16:43:51 +09:00
|
|
|
|
framework: fileUploadSetting.framework,
|
2023-04-22 05:42:24 +09:00
|
|
|
|
params: fileUploadSetting.params
|
2023-04-21 15:48:12 +09:00
|
|
|
|
}
|
|
|
|
|
setItem(`${INDEXEDDB_KEY_MODEL_DATA}_${slot}`, saveData)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("Excpetion:::::::::", e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
|
|
|
|
|
const reloadServerInfo = useMemo(() => {
|
|
|
|
|
return async () => {
|
2023-02-19 10:12:25 +09:00
|
|
|
|
console.log("reload server info")
|
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
if (!props.voiceChangerClient) return
|
|
|
|
|
const res = await props.voiceChangerClient.getServerSettings()
|
2023-02-19 10:12:25 +09:00
|
|
|
|
setServerSetting(res)
|
2023-02-20 07:46:33 +09:00
|
|
|
|
const storeData = { ...res }
|
|
|
|
|
storeData.recordIO = 0
|
|
|
|
|
setItem(INDEXEDDB_KEY_SERVER, storeData)
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
|
|
|
|
}, [props.voiceChangerClient])
|
|
|
|
|
|
2023-01-29 09:42:45 +09:00
|
|
|
|
const clearSetting = async () => {
|
|
|
|
|
await removeItem(INDEXEDDB_KEY_SERVER)
|
2023-01-29 15:25:44 +09:00
|
|
|
|
await removeItem(INDEXEDDB_KEY_MODEL_DATA)
|
2023-04-21 15:48:12 +09:00
|
|
|
|
for (let i = 0; i < MAX_MODEL_SLOT_NUM; i++) {
|
|
|
|
|
const modleKey = `${INDEXEDDB_KEY_MODEL_DATA}_${i}`
|
|
|
|
|
await removeItem(modleKey)
|
|
|
|
|
}
|
2023-01-29 09:42:45 +09:00
|
|
|
|
}
|
2023-01-12 18:06:15 +09:00
|
|
|
|
|
2023-04-13 08:00:28 +09:00
|
|
|
|
|
|
|
|
|
const getOnnx = async () => {
|
|
|
|
|
return props.voiceChangerClient!.getOnnx()
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 16:38:45 +09:00
|
|
|
|
return {
|
2023-02-19 10:12:25 +09:00
|
|
|
|
serverSetting,
|
|
|
|
|
updateServerSettings,
|
2023-01-29 09:42:45 +09:00
|
|
|
|
clearSetting,
|
2023-01-12 16:38:45 +09:00
|
|
|
|
reloadServerInfo,
|
2023-02-19 10:12:25 +09:00
|
|
|
|
|
2023-04-21 15:48:12 +09:00
|
|
|
|
fileUploadSettings,
|
2023-01-12 16:38:45 +09:00
|
|
|
|
setFileUploadSetting,
|
|
|
|
|
loadModel,
|
|
|
|
|
uploadProgress,
|
|
|
|
|
isUploading,
|
2023-04-13 08:00:28 +09:00
|
|
|
|
getOnnx,
|
2023-04-22 05:42:24 +09:00
|
|
|
|
// updateDefaultTune,
|
2023-01-12 16:38:45 +09:00
|
|
|
|
}
|
|
|
|
|
}
|