bugfix: analyzer

This commit is contained in:
wataru 2023-02-17 03:03:21 +09:00
parent bde3bc5933
commit b7b1e583ee
7 changed files with 57 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,12 +14,18 @@ export type StateControls = {
type FrontendManagerState = { type FrontendManagerState = {
stateControls: StateControls stateControls: StateControls
isConverting: boolean,
isAnalyzing: boolean
}; };
export type FrontendManagerStateAndMethod = FrontendManagerState & { export type FrontendManagerStateAndMethod = FrontendManagerState & {
setIsConverting: (val: boolean) => void
setIsAnalyzing: (val: boolean) => void
} }
export const useFrontendManager = (): FrontendManagerStateAndMethod => { export const useFrontendManager = (): FrontendManagerStateAndMethod => {
const [isConverting, setIsConverting] = useState<boolean>(false)
const [isAnalyzing, setIsAnalyzing] = useState<boolean>(false)
// (1) Controller Switch // (1) Controller Switch
const openServerControlCheckbox = useStateControlCheckbox(OpenServerControlCheckbox); const openServerControlCheckbox = useStateControlCheckbox(OpenServerControlCheckbox);
@ -51,7 +57,11 @@ export const useFrontendManager = (): FrontendManagerStateAndMethod => {
openSpeakerSettingCheckbox, openSpeakerSettingCheckbox,
openConverterSettingCheckbox, openConverterSettingCheckbox,
openAdvancedSettingCheckbox openAdvancedSettingCheckbox
} },
isConverting,
setIsConverting,
isAnalyzing,
setIsAnalyzing
}; };
return returnValue; return returnValue;
}; };

View File

@ -4,7 +4,6 @@ import { AnimationTypes, HeaderButton, HeaderButtonProps } from "./components/10
export const useServerControl = () => { export const useServerControl = () => {
const appState = useAppState() const appState = useAppState()
const [isStarted, setIsStarted] = useState<boolean>(false)
const [startWithAudioContextCreate, setStartWithAudioContextCreate] = useState<boolean>(false) const [startWithAudioContextCreate, setStartWithAudioContextCreate] = useState<boolean>(false)
const accodionButton = useMemo(() => { const accodionButton = useMemo(() => {
@ -23,7 +22,7 @@ export const useServerControl = () => {
if (!startWithAudioContextCreate) { if (!startWithAudioContextCreate) {
return return
} }
setIsStarted(true) appState.frontendManagerState.setIsConverting(true)
appState.clientSetting.start() appState.clientSetting.start()
}, [startWithAudioContextCreate]) }, [startWithAudioContextCreate])
@ -36,16 +35,16 @@ export const useServerControl = () => {
}) })
setStartWithAudioContextCreate(true) setStartWithAudioContextCreate(true)
} else { } else {
setIsStarted(true) appState.frontendManagerState.setIsConverting(true)
await appState.clientSetting.start() await appState.clientSetting.start()
} }
} }
const onStopClicked = async () => { const onStopClicked = async () => {
setIsStarted(false) appState.frontendManagerState.setIsConverting(false)
await appState.clientSetting.stop() await appState.clientSetting.stop()
} }
const startClassName = isStarted ? "body-button-active" : "body-button-stanby" const startClassName = appState.frontendManagerState.isConverting ? "body-button-active" : "body-button-stanby"
const stopClassName = isStarted ? "body-button-stanby" : "body-button-active" const stopClassName = appState.frontendManagerState.isConverting ? "body-button-stanby" : "body-button-active"
return ( return (
<div className="body-row split-3-2-2-3 left-padding-1 guided"> <div className="body-row split-3-2-2-3 left-padding-1 guided">
@ -60,7 +59,7 @@ export const useServerControl = () => {
</div> </div>
</div> </div>
) )
}, [isStarted, appState.clientSetting.start, appState.clientSetting.stop]) }, [appState.frontendManagerState.isConverting, appState.clientSetting.start, appState.clientSetting.stop])
const performanceRow = useMemo(() => { const performanceRow = useMemo(() => {
return ( return (

View File

@ -134,6 +134,14 @@ export const useQualityControl = (): QualityControlState => {
const onRecordStopClicked = async () => { const onRecordStopClicked = async () => {
setRecording(false) setRecording(false)
await appState.serverSetting.setRecordIO(0) await appState.serverSetting.setRecordIO(0)
}
const onRecordAnalizeClicked = async () => {
if (appState.frontendManagerState.isConverting) {
alert("please stop voice conversion. 解析処理と音声変換を同時に行うことはできません。音声変化をストップしてください。")
return
}
appState.frontendManagerState.setIsAnalyzing(true)
await appState.serverSetting.setRecordIO(2)
// set spectrogram (dio) // set spectrogram (dio)
const imageDio = document.getElementById("body-image-container-img-dio") as HTMLImageElement const imageDio = document.getElementById("body-image-container-img-dio") as HTMLImageElement
imageDio.src = "/tmp/analyze-dio.png?" + new Date().getTime() imageDio.src = "/tmp/analyze-dio.png?" + new Date().getTime()
@ -157,10 +165,15 @@ export const useQualityControl = (): QualityControlState => {
wavOutput.controls = true wavOutput.controls = true
// @ts-ignore // @ts-ignore
wavOutput.setSinkId(audioOutputForGUI) wavOutput.setSinkId(audioOutputForGUI)
appState.frontendManagerState.setIsAnalyzing(false)
} }
const startClassName = recording ? "body-button-active" : "body-button-stanby" const startClassName = recording ? "body-button-active" : "body-button-stanby"
const stopClassName = recording ? "body-button-stanby" : "body-button-active" const stopClassName = recording ? "body-button-stanby" : "body-button-active"
const analyzeClassName = appState.frontendManagerState.isAnalyzing ? "body-button-active" : "body-button-stanby"
const analyzeLabel = appState.frontendManagerState.isAnalyzing ? "wait..." : "Analyze"
return ( return (
<> <>
@ -176,6 +189,7 @@ export const useQualityControl = (): QualityControlState => {
<div className="body-button-container"> <div className="body-button-container">
<div onClick={onRecordStartClicked} className={startClassName}>Start</div> <div onClick={onRecordStartClicked} className={startClassName}>Start</div>
<div onClick={onRecordStopClicked} className={stopClassName}>Stop</div> <div onClick={onRecordStopClicked} className={stopClassName}>Stop</div>
<div onClick={onRecordAnalizeClicked} className={analyzeClassName}>{analyzeLabel}</div>
</div> </div>
</div> </div>
@ -238,7 +252,7 @@ export const useQualityControl = (): QualityControlState => {
</div> </div>
</> </>
) )
}, [appState.serverSetting.setting.recordIO, appState.serverSetting.setRecordIO, outputAudioDeviceInfo, audioOutputForGUI]) }, [appState.serverSetting.setting.recordIO, appState.serverSetting.setRecordIO, outputAudioDeviceInfo, audioOutputForGUI, appState.frontendManagerState.isAnalyzing, appState.frontendManagerState.isConverting])
const QualityControlContent = useMemo(() => { const QualityControlContent = useMemo(() => {
return ( return (

View File

@ -1,22 +1,25 @@
import os, shutil import os
import shutil
from fastapi import UploadFile from fastapi import UploadFile
# UPLOAD_DIR = "model_upload_dir" # UPLOAD_DIR = "model_upload_dir"
def upload_file(upload_dirname:str, file:UploadFile, filename: str):
def upload_file(upload_dirname: str, file: UploadFile, filename: str):
if file and filename: if file and filename:
fileobj = file.file fileobj = file.file
upload_dir = open(os.path.join(upload_dirname, filename),'wb+') upload_dir = open(os.path.join(upload_dirname, filename), 'wb+')
shutil.copyfileobj(fileobj, upload_dir) shutil.copyfileobj(fileobj, upload_dir)
upload_dir.close() upload_dir.close()
return {"status":"OK", "msg": f"uploaded files {filename} "} return {"status": "OK", "msg": f"uploaded files {filename} "}
return {"status":"ERROR", "msg": "uploaded file is not found."} return {"status": "ERROR", "msg": "uploaded file is not found."}
def concat_file_chunks(upload_dirname:str, filename:str, chunkNum:int, dest_dirname:str):
def concat_file_chunks(upload_dirname: str, filename: str, chunkNum: int, dest_dirname: str):
target_file_name = os.path.join(dest_dirname, filename) target_file_name = os.path.join(dest_dirname, filename)
if os.path.exists(target_file_name): if os.path.exists(target_file_name):
os.unlink(target_file_name) os.remove(target_file_name)
with open(target_file_name, "ab") as target_file: with open(target_file_name, "ab") as target_file:
for i in range(chunkNum): for i in range(chunkNum):
chunkName = f"{filename}_{i}" chunkName = f"{filename}_{i}"
@ -24,7 +27,6 @@ def concat_file_chunks(upload_dirname:str, filename:str, chunkNum:int, dest_dirn
stored_chunk_file = open(chunk_file_path, 'rb') stored_chunk_file = open(chunk_file_path, 'rb')
target_file.write(stored_chunk_file.read()) target_file.write(stored_chunk_file.read())
stored_chunk_file.close() stored_chunk_file.close()
os.unlink(chunk_file_path) os.remove(chunk_file_path)
target_file.close() target_file.close()
return {"status":"OK", "msg": f"concat files {target_file_name} "} return {"status": "OK", "msg": f"concat files {target_file_name} "}

View File

@ -2,12 +2,13 @@
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
import os import os
def mod_get_model(modelFile:str):
modelPath = os.path.join("MMVC_Trainer/logs", modelFile)
return FileResponse(path=modelPath)
def mod_delete_model(modelFile:str): def mod_get_model(modelFile: str):
modelPath = os.path.join("MMVC_Trainer/logs", modelFile) modelPath = os.path.join("MMVC_Trainer/logs", modelFile)
os.unlink(modelPath) return FileResponse(path=modelPath)
return {"Model deleted": f"{modelFile}"}
def mod_delete_model(modelFile: str):
modelPath = os.path.join("MMVC_Trainer/logs", modelFile)
os.remove(modelPath)
return {"Model deleted": f"{modelFile}"}

View File

@ -131,14 +131,14 @@ class VoiceChanger():
mock_stream_out = MockStream(24000) mock_stream_out = MockStream(24000)
stream_output_file = os.path.join(TMP_DIR, "out.wav") stream_output_file = os.path.join(TMP_DIR, "out.wav")
if os.path.exists(stream_output_file): if os.path.exists(stream_output_file):
os.unlink(stream_output_file) os.remove(stream_output_file)
mock_stream_out.open_outputfile(stream_output_file) mock_stream_out.open_outputfile(stream_output_file)
self.stream_out = mock_stream_out self.stream_out = mock_stream_out
mock_stream_in = MockStream(24000) mock_stream_in = MockStream(24000)
stream_input_file = os.path.join(TMP_DIR, "in.wav") stream_input_file = os.path.join(TMP_DIR, "in.wav")
if os.path.exists(stream_input_file): if os.path.exists(stream_input_file):
os.unlink(stream_input_file) os.remove(stream_input_file)
mock_stream_in.open_outputfile(stream_input_file) mock_stream_in.open_outputfile(stream_input_file)
self.stream_in = mock_stream_in self.stream_in = mock_stream_in
@ -235,6 +235,8 @@ class VoiceChanger():
if key == "recordIO" and val == 1: if key == "recordIO" and val == 1:
self._setupRecordIO() self._setupRecordIO()
if key == "recordIO" and val == 0: if key == "recordIO" and val == 0:
pass
if key == "recordIO" and val == 2:
try: try:
stream_input_file = os.path.join(TMP_DIR, "in.wav") stream_input_file = os.path.join(TMP_DIR, "in.wav")
analyze_file_dio = os.path.join(TMP_DIR, "analyze-dio.png") analyze_file_dio = os.path.join(TMP_DIR, "analyze-dio.png")