server device mode fallback
This commit is contained in:
parent
7746f3168f
commit
3d8dc7a9bd
11
client/demo/dist/index.html
vendored
11
client/demo/dist/index.html
vendored
@ -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>
|
||||||
|
1706
client/demo/dist/index.js
vendored
1706
client/demo/dist/index.js
vendored
File diff suppressed because one or more lines are too long
2783
client/demo/dist/index.js.LICENSE.txt
vendored
2783
client/demo/dist/index.js.LICENSE.txt
vendored
File diff suppressed because it is too large
Load Diff
@ -9,14 +9,14 @@ export const PerformanceRow = (_props: PerformanceRowProps) => {
|
|||||||
const [showPerformanceDetail, setShowPerformanceDetail] = useState<boolean>(false)
|
const [showPerformanceDetail, setShowPerformanceDetail] = useState<boolean>(false)
|
||||||
|
|
||||||
const performanceRow = useMemo(() => {
|
const performanceRow = useMemo(() => {
|
||||||
if (appState.serverSetting.serverSetting.enableServerAudio) {
|
// if (appState.serverSetting.serverSetting.enableServerAudio) {
|
||||||
return (
|
// return (
|
||||||
<div className="body-row split-3-7 left-padding-1 guided">
|
// <div className="body-row split-3-7 left-padding-1 guided">
|
||||||
<div className="body-item-title left-padding-1">monitor:</div>
|
// <div className="body-item-title left-padding-1">monitor:</div>
|
||||||
<div className="body-item-text">server device mode. refer console.</div>
|
// <div className="body-item-text">server device mode. refer console.</div>
|
||||||
</div>
|
// </div>
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
const performanceDetailLabel = showPerformanceDetail ? "[pre, main, post] <<" : "more >>"
|
const performanceDetailLabel = showPerformanceDetail ? "[pre, main, post] <<" : "more >>"
|
||||||
const performanceData = showPerformanceDetail ? `[${appState.performance.preprocessTime}, ${appState.performance.mainprocessTime},${appState.performance.postprocessTime}]` : ""
|
const performanceData = showPerformanceDetail ? `[${appState.performance.preprocessTime}, ${appState.performance.mainprocessTime},${appState.performance.postprocessTime}]` : ""
|
||||||
return (
|
return (
|
||||||
|
@ -15,7 +15,6 @@ export const ServerOpertationRow = (props: ServerOpertationRowProps) => {
|
|||||||
const guiState = useGuiState()
|
const guiState = useGuiState()
|
||||||
|
|
||||||
const serverOpertationRow = useMemo(() => {
|
const serverOpertationRow = useMemo(() => {
|
||||||
console.log("UPDATE OPERATION ROW:::::::::::::::::::::::")
|
|
||||||
|
|
||||||
const onnxExportButtonAction = async () => {
|
const onnxExportButtonAction = async () => {
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export const SampleDownloadControlRow = (_props: SampleDownloadControlRowProps)
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="body-row split-3-3-4 left-padding-1 guided">
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
||||||
<div className="body-item-title left-padding-1 ">Advanced Configuration</div>
|
<div className="body-item-title left-padding-2 ">Advanced Configuration</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="checkbox" checked={fileUploadSetting.rvcIndexDownload} onChange={(e) => {
|
<input type="checkbox" checked={fileUploadSetting.rvcIndexDownload} onChange={(e) => {
|
||||||
appState.serverSetting.setFileUploadSetting(slot, { ...fileUploadSetting, rvcIndexDownload: e.target.checked })
|
appState.serverSetting.setFileUploadSetting(slot, { ...fileUploadSetting, rvcIndexDownload: e.target.checked })
|
||||||
|
@ -74,15 +74,32 @@ export class VoiceChangerWorkletNode extends AudioWorkletNode {
|
|||||||
this.listener.notifyException(VOICE_CHANGER_CLIENT_EXCEPTION.ERR_SIO_CONNECT_FAILED, `[SIO] rconnection failed ${err}`)
|
this.listener.notifyException(VOICE_CHANGER_CLIENT_EXCEPTION.ERR_SIO_CONNECT_FAILED, `[SIO] rconnection failed ${err}`)
|
||||||
})
|
})
|
||||||
this.socket.on('connect', () => {
|
this.socket.on('connect', () => {
|
||||||
console.log(`[SIO] sonnect to ${this.setting.serverUrl}`)
|
console.log(`[SIO] connect to ${this.setting.serverUrl}`)
|
||||||
console.log(`[SIO] ${this.socket?.id}`)
|
console.log(`[SIO] ${this.socket?.id}`)
|
||||||
});
|
});
|
||||||
|
this.socket.on('close', function (socket) {
|
||||||
|
console.log(`[SIO] close ${socket.id}`)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.socket.on('message', (response: any[]) => {
|
||||||
|
console.log("message:", response)
|
||||||
|
});
|
||||||
|
|
||||||
this.socket.on('response', (response: any[]) => {
|
this.socket.on('response', (response: any[]) => {
|
||||||
// console.log("response:", response)
|
|
||||||
const cur = Date.now()
|
const cur = Date.now()
|
||||||
const responseTime = cur - response[0]
|
const responseTime = cur - response[0]
|
||||||
const result = response[1] as ArrayBuffer
|
const result = response[1] as ArrayBuffer
|
||||||
const perf = response[2]
|
const perf = response[2]
|
||||||
|
|
||||||
|
// Quick hack for server device mode
|
||||||
|
if (response[0] == 0) {
|
||||||
|
this.listener.notifyResponseTime(Math.round(perf[0] * 1000), perf.slice(1, 4))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (result.byteLength < 128 * 2) {
|
if (result.byteLength < 128 * 2) {
|
||||||
this.listener.notifyException(VOICE_CHANGER_CLIENT_EXCEPTION.ERR_SIO_INVALID_RESPONSE, `[SIO] recevied data is too short ${result.byteLength}`)
|
this.listener.notifyException(VOICE_CHANGER_CLIENT_EXCEPTION.ERR_SIO_INVALID_RESPONSE, `[SIO] recevied data is too short ${result.byteLength}`)
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,13 +4,27 @@ import numpy as np
|
|||||||
import socketio
|
import socketio
|
||||||
from voice_changer.VoiceChangerManager import VoiceChangerManager
|
from voice_changer.VoiceChangerManager import VoiceChangerManager
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
class MMVC_Namespace(socketio.AsyncNamespace):
|
class MMVC_Namespace(socketio.AsyncNamespace):
|
||||||
sid: int = 0
|
sid: int = 0
|
||||||
|
|
||||||
|
async def emitTo(self, data):
|
||||||
|
timestamp = 0
|
||||||
|
audio1 = np.zeros(1).astype(np.int16)
|
||||||
|
bin = struct.pack("<%sh" % len(audio1), *audio1)
|
||||||
|
perf = data
|
||||||
|
|
||||||
|
await self.emit("response", [timestamp, bin, perf], to=self.sid)
|
||||||
|
|
||||||
|
def emit_coroutine(self, data):
|
||||||
|
asyncio.run(self.emitTo(data))
|
||||||
|
|
||||||
def __init__(self, namespace: str, voiceChangerManager: VoiceChangerManager):
|
def __init__(self, namespace: str, voiceChangerManager: VoiceChangerManager):
|
||||||
super().__init__(namespace)
|
super().__init__(namespace)
|
||||||
self.voiceChangerManager = voiceChangerManager
|
self.voiceChangerManager = voiceChangerManager
|
||||||
|
self.voiceChangerManager.voiceChanger.emitTo = self.emit_coroutine
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, voiceChangerManager: VoiceChangerManager):
|
def get_instance(cls, voiceChangerManager: VoiceChangerManager):
|
||||||
@ -29,6 +43,7 @@ class MMVC_Namespace(socketio.AsyncNamespace):
|
|||||||
|
|
||||||
async def on_request_message(self, sid, msg):
|
async def on_request_message(self, sid, msg):
|
||||||
self.sid = sid
|
self.sid = sid
|
||||||
|
await self.asynctest("on req")
|
||||||
timestamp = int(msg[0])
|
timestamp = int(msg[0])
|
||||||
data = msg[1]
|
data = msg[1]
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
|
@ -11,13 +11,14 @@ class ServerAudioDevice:
|
|||||||
hostAPI: str = ""
|
hostAPI: str = ""
|
||||||
maxInputChannels: int = 0
|
maxInputChannels: int = 0
|
||||||
maxOutputChannels: int = 0
|
maxOutputChannels: int = 0
|
||||||
|
default_samplerate: int = 0
|
||||||
|
|
||||||
|
|
||||||
def list_audio_device():
|
def list_audio_device():
|
||||||
audioDeviceList = sd.query_devices()
|
audioDeviceList = sd.query_devices()
|
||||||
|
|
||||||
inputAudioDeviceList = [d for d in audioDeviceList if d["max_input_channels"] > 0]
|
inputAudioDeviceList = [d for d in audioDeviceList if d["max_input_channels"] > 0]
|
||||||
outputDeviceList = [d for d in audioDeviceList if d["max_output_channels"] > 0]
|
outputAudioDeviceList = [d for d in audioDeviceList if d["max_output_channels"] > 0]
|
||||||
hostapis = sd.query_hostapis()
|
hostapis = sd.query_hostapis()
|
||||||
|
|
||||||
# print("input:", inputAudioDeviceList)
|
# print("input:", inputAudioDeviceList)
|
||||||
@ -34,9 +35,10 @@ def list_audio_device():
|
|||||||
hostAPI=hostapis[d["hostapi"]]["name"],
|
hostAPI=hostapis[d["hostapi"]]["name"],
|
||||||
maxInputChannels=d["max_input_channels"],
|
maxInputChannels=d["max_input_channels"],
|
||||||
maxOutputChannels=d["max_output_channels"],
|
maxOutputChannels=d["max_output_channels"],
|
||||||
|
default_samplerate=d["default_samplerate"],
|
||||||
)
|
)
|
||||||
serverAudioInputDevices.append(serverInputAudioDevice)
|
serverAudioInputDevices.append(serverInputAudioDevice)
|
||||||
for d in outputDeviceList:
|
for d in outputAudioDeviceList:
|
||||||
serverOutputAudioDevice: ServerAudioDevice = ServerAudioDevice(
|
serverOutputAudioDevice: ServerAudioDevice = ServerAudioDevice(
|
||||||
kind=ServerAudioDeviceTypes.audiooutput,
|
kind=ServerAudioDeviceTypes.audiooutput,
|
||||||
index=d["index"],
|
index=d["index"],
|
||||||
@ -44,6 +46,7 @@ def list_audio_device():
|
|||||||
hostAPI=hostapis[d["hostapi"]]["name"],
|
hostAPI=hostapis[d["hostapi"]]["name"],
|
||||||
maxInputChannels=d["max_input_channels"],
|
maxInputChannels=d["max_input_channels"],
|
||||||
maxOutputChannels=d["max_output_channels"],
|
maxOutputChannels=d["max_output_channels"],
|
||||||
|
default_samplerate=d["default_samplerate"],
|
||||||
)
|
)
|
||||||
serverAudioOutputDevices.append(serverOutputAudioDevice)
|
serverAudioOutputDevices.append(serverOutputAudioDevice)
|
||||||
|
|
||||||
|
@ -99,6 +99,8 @@ class VoiceChanger:
|
|||||||
|
|
||||||
localPerformanceShowTime = 0.0
|
localPerformanceShowTime = 0.0
|
||||||
|
|
||||||
|
emitTo = None
|
||||||
|
|
||||||
def audio_callback(
|
def audio_callback(
|
||||||
self, indata: np.ndarray, outdata: np.ndarray, frames, times, status
|
self, indata: np.ndarray, outdata: np.ndarray, frames, times, status
|
||||||
):
|
):
|
||||||
@ -113,6 +115,8 @@ class VoiceChanger:
|
|||||||
)
|
)
|
||||||
all_inference_time = t.secs
|
all_inference_time = t.secs
|
||||||
performance = [all_inference_time] + times
|
performance = [all_inference_time] + times
|
||||||
|
if self.emitTo is not None:
|
||||||
|
self.emitTo(performance)
|
||||||
self.settings.performance = [round(x * 1000) for x in performance]
|
self.settings.performance = [round(x * 1000) for x in performance]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[Voice Changer] ex:", e)
|
print("[Voice Changer] ex:", e)
|
||||||
@ -131,6 +135,7 @@ class VoiceChanger:
|
|||||||
|
|
||||||
currentInputDeviceId = -1
|
currentInputDeviceId = -1
|
||||||
currentInputSampleRate = -1
|
currentInputSampleRate = -1
|
||||||
|
model_sampling_rate = -1
|
||||||
currentOutputDeviceId = -1
|
currentOutputDeviceId = -1
|
||||||
currentInputChunkNum = -1
|
currentInputChunkNum = -1
|
||||||
while True:
|
while True:
|
||||||
@ -166,13 +171,33 @@ class VoiceChanger:
|
|||||||
currentInputChannelNum = serverInputAudioDevice.maxInputChannels
|
currentInputChannelNum = serverInputAudioDevice.maxInputChannels
|
||||||
currentOutputChannelNum = serverOutputAudioDevice.maxOutputChannels
|
currentOutputChannelNum = serverOutputAudioDevice.maxOutputChannels
|
||||||
|
|
||||||
vc.settings.serverInputAudioSampleRate = (
|
|
||||||
self.voiceChanger.get_processing_sampling_rate()
|
|
||||||
)
|
|
||||||
currentInputSampleRate = vc.settings.serverInputAudioSampleRate
|
|
||||||
currentInputChunkNum = vc.settings.serverReadChunkSize
|
currentInputChunkNum = vc.settings.serverReadChunkSize
|
||||||
block_frame = currentInputChunkNum * 128
|
block_frame = currentInputChunkNum * 128
|
||||||
|
|
||||||
|
# sample rate precheck(alsa cannot use 40000?)
|
||||||
|
model_sampling_rate = self.voiceChanger.get_processing_sampling_rate()
|
||||||
|
try:
|
||||||
|
with sd.Stream(
|
||||||
|
callback=self.audio_callback,
|
||||||
|
blocksize=block_frame,
|
||||||
|
samplerate=model_sampling_rate,
|
||||||
|
dtype="float32",
|
||||||
|
channels=[currentInputChannelNum, currentOutputChannelNum],
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
currentInputSampleRate = model_sampling_rate
|
||||||
|
vc.settings.serverInputAudioSampleRate = model_sampling_rate
|
||||||
|
print(f"[Voice Changer] sample rate {model_sampling_rate}")
|
||||||
|
except Exception as e:
|
||||||
|
print(
|
||||||
|
"[Voice Changer] ex: fallback to device default samplerate", e
|
||||||
|
)
|
||||||
|
currentInputSampleRate = serverInputAudioDevice.default_samplerate
|
||||||
|
vc.settings.serverInputAudioSampleRate = (
|
||||||
|
serverInputAudioDevice.default_samplerate
|
||||||
|
)
|
||||||
|
|
||||||
|
# main loop
|
||||||
try:
|
try:
|
||||||
with sd.Stream(
|
with sd.Stream(
|
||||||
callback=self.audio_callback,
|
callback=self.audio_callback,
|
||||||
@ -181,14 +206,13 @@ class VoiceChanger:
|
|||||||
dtype="float32",
|
dtype="float32",
|
||||||
channels=[currentInputChannelNum, currentOutputChannelNum],
|
channels=[currentInputChannelNum, currentOutputChannelNum],
|
||||||
):
|
):
|
||||||
print()
|
|
||||||
while (
|
while (
|
||||||
vc.settings.serverAudioStated == 1
|
vc.settings.serverAudioStated == 1
|
||||||
and currentInputDeviceId == vc.settings.serverInputDeviceId
|
and currentInputDeviceId == vc.settings.serverInputDeviceId
|
||||||
and currentOutputDeviceId
|
and currentOutputDeviceId
|
||||||
== vc.settings.serverOutputDeviceId
|
== vc.settings.serverOutputDeviceId
|
||||||
and currentInputSampleRate
|
and model_sampling_rate
|
||||||
== vc.settings.serverInputAudioSampleRate
|
== self.voiceChanger.get_processing_sampling_rate()
|
||||||
and currentInputChunkNum == vc.settings.serverReadChunkSize
|
and currentInputChunkNum == vc.settings.serverReadChunkSize
|
||||||
):
|
):
|
||||||
vc.settings.serverInputAudioSampleRate = (
|
vc.settings.serverInputAudioSampleRate = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user