2023-01-04 20:28:36 +03:00
|
|
|
|
|
|
|
// (★1) chunk sizeは 128サンプル, 256byte(int16)と定義。
|
|
|
|
// (★2) 256byte(最低バッファサイズ256から間引いた個数x2byte)をchunkとして管理。
|
2023-01-11 21:49:22 +03:00
|
|
|
// 24000sample -> 1sec, 128sample(1chunk) -> 5.333msec
|
2023-01-11 22:52:01 +03:00
|
|
|
// 187.5chunk -> 1sec
|
2023-01-04 20:28:36 +03:00
|
|
|
|
|
|
|
// types
|
|
|
|
export type VoiceChangerRequestParamas = {
|
2023-01-05 05:45:42 +03:00
|
|
|
convertChunkNum: number, // VITSに入力する変換サイズ。(入力データの2倍以上の大きさで指定。それより小さいものが指定された場合は、サーバ側で自動的に入力の2倍のサイズが設定される。)
|
2023-01-04 20:28:36 +03:00
|
|
|
srcId: number,
|
|
|
|
dstId: number,
|
|
|
|
gpu: number,
|
|
|
|
|
|
|
|
crossFadeLowerValue: number,
|
|
|
|
crossFadeOffsetRate: number,
|
|
|
|
crossFadeEndRate: number,
|
2023-01-11 19:05:38 +03:00
|
|
|
crossFadeOverlapRate: number,
|
2023-01-07 14:07:39 +03:00
|
|
|
|
2023-01-04 20:28:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export type VoiceChangerOptions = {
|
2023-01-05 12:35:56 +03:00
|
|
|
audioInput: string | MediaStream | null,
|
2023-01-04 20:28:36 +03:00
|
|
|
mmvcServerUrl: string,
|
2023-01-05 05:45:42 +03:00
|
|
|
protocol: Protocol,
|
2023-01-04 20:28:36 +03:00
|
|
|
sampleRate: SampleRate, // 48000Hz
|
|
|
|
bufferSize: BufferSize, // 256, 512, 1024, 2048, 4096, 8192, 16384 (for mic stream)
|
2023-01-05 05:45:42 +03:00
|
|
|
inputChunkNum: number, // n of (256 x n) for send buffer
|
2023-01-04 20:28:36 +03:00
|
|
|
speakers: Speaker[],
|
|
|
|
forceVfDisable: boolean,
|
|
|
|
voiceChangerMode: VoiceChangerMode,
|
2023-01-10 18:59:09 +03:00
|
|
|
onnxExecutionProvider: OnnxExecutionProvider,
|
|
|
|
framework: Framework
|
2023-01-04 20:28:36 +03:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:52:01 +03:00
|
|
|
export type WorkletSetting = {
|
|
|
|
numTrancateTreshold: number,
|
|
|
|
volTrancateThreshold: number,
|
|
|
|
volTrancateLength: number
|
|
|
|
}
|
2023-01-04 20:28:36 +03:00
|
|
|
|
|
|
|
export type Speaker = {
|
|
|
|
"id": number,
|
|
|
|
"name": string,
|
|
|
|
}
|
|
|
|
|
2023-01-08 10:18:20 +03:00
|
|
|
|
|
|
|
export type ServerInfo = {
|
2023-01-10 20:19:54 +03:00
|
|
|
status: string
|
|
|
|
configFile: string,
|
2023-01-08 10:18:20 +03:00
|
|
|
pyTorchModelFile: string,
|
|
|
|
onnxModelFile: string,
|
2023-01-10 20:19:54 +03:00
|
|
|
convertChunkNum: number,
|
|
|
|
crossFadeOffsetRate: number,
|
|
|
|
crossFadeEndRate: number,
|
|
|
|
gpu: number,
|
|
|
|
srcId: number,
|
|
|
|
dstId: number,
|
|
|
|
framework: Framework,
|
2023-01-08 10:18:20 +03:00
|
|
|
providers: string[]
|
|
|
|
}
|
|
|
|
|
2023-01-10 20:19:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-04 20:28:36 +03:00
|
|
|
// Consts
|
2023-01-05 05:45:42 +03:00
|
|
|
export const Protocol = {
|
2023-01-04 20:28:36 +03:00
|
|
|
"sio": "sio",
|
|
|
|
"rest": "rest",
|
|
|
|
} as const
|
2023-01-05 05:45:42 +03:00
|
|
|
export type Protocol = typeof Protocol[keyof typeof Protocol]
|
2023-01-04 20:28:36 +03:00
|
|
|
|
|
|
|
export const VoiceChangerMode = {
|
|
|
|
"realtime": "realtime",
|
|
|
|
"near-realtime": "near-realtime",
|
|
|
|
} as const
|
|
|
|
export type VoiceChangerMode = typeof VoiceChangerMode[keyof typeof VoiceChangerMode]
|
|
|
|
|
|
|
|
export const SampleRate = {
|
|
|
|
"48000": 48000,
|
|
|
|
} as const
|
|
|
|
export type SampleRate = typeof SampleRate[keyof typeof SampleRate]
|
|
|
|
|
|
|
|
export const BufferSize = {
|
2023-01-05 05:45:42 +03:00
|
|
|
"256": 256,
|
|
|
|
"512": 512,
|
2023-01-04 20:28:36 +03:00
|
|
|
"1024": 1024,
|
2023-01-05 05:45:42 +03:00
|
|
|
"2048": 2048,
|
|
|
|
"4096": 4096,
|
|
|
|
"8192": 8192,
|
|
|
|
"16384": 16384
|
2023-01-04 20:28:36 +03:00
|
|
|
} as const
|
|
|
|
export type BufferSize = typeof BufferSize[keyof typeof BufferSize]
|
|
|
|
|
2023-01-07 14:07:39 +03:00
|
|
|
export const OnnxExecutionProvider = {
|
|
|
|
"CPUExecutionProvider": "CPUExecutionProvider",
|
|
|
|
"CUDAExecutionProvider": "CUDAExecutionProvider",
|
|
|
|
"DmlExecutionProvider": "DmlExecutionProvider",
|
|
|
|
"OpenVINOExecutionProvider": "OpenVINOExecutionProvider",
|
|
|
|
} as const
|
|
|
|
export type OnnxExecutionProvider = typeof OnnxExecutionProvider[keyof typeof OnnxExecutionProvider]
|
|
|
|
|
|
|
|
export const Framework = {
|
|
|
|
"PyTorch": "PyTorch",
|
|
|
|
"ONNX": "ONNX",
|
|
|
|
}
|
|
|
|
export type Framework = typeof Framework[keyof typeof Framework]
|
2023-01-04 20:28:36 +03:00
|
|
|
|
2023-01-08 10:18:20 +03:00
|
|
|
export const ServerSettingKey = {
|
|
|
|
"srcId": "srcId",
|
|
|
|
"dstId": "dstId",
|
|
|
|
"convertChunkNum": "convertChunkNum",
|
|
|
|
"gpu": "gpu",
|
|
|
|
"crossFadeOffsetRate": "crossFadeOffsetRate",
|
|
|
|
"crossFadeEndRate": "crossFadeEndRate",
|
2023-01-11 19:05:38 +03:00
|
|
|
"crossFadeOverlapRate": "crossFadeOverlapRate",
|
2023-01-08 10:18:20 +03:00
|
|
|
"framework": "framework",
|
|
|
|
"onnxExecutionProvider": "onnxExecutionProvider"
|
|
|
|
} as const
|
|
|
|
export type ServerSettingKey = typeof ServerSettingKey[keyof typeof ServerSettingKey]
|
|
|
|
|
2023-01-04 20:28:36 +03:00
|
|
|
// Defaults
|
|
|
|
export const DefaultVoiceChangerRequestParamas: VoiceChangerRequestParamas = {
|
2023-01-07 14:07:39 +03:00
|
|
|
convertChunkNum: 32, //(★1)
|
2023-01-04 20:28:36 +03:00
|
|
|
srcId: 107,
|
|
|
|
dstId: 100,
|
|
|
|
gpu: 0,
|
|
|
|
crossFadeLowerValue: 0.1,
|
2023-01-05 05:45:42 +03:00
|
|
|
crossFadeOffsetRate: 0.1,
|
2023-01-11 19:05:38 +03:00
|
|
|
crossFadeEndRate: 0.9,
|
|
|
|
crossFadeOverlapRate: 0.5
|
2023-01-05 05:45:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export const DefaultVoiceChangerOptions: VoiceChangerOptions = {
|
2023-01-05 12:35:56 +03:00
|
|
|
audioInput: null,
|
2023-01-07 18:25:21 +03:00
|
|
|
mmvcServerUrl: "",
|
2023-01-05 05:45:42 +03:00
|
|
|
protocol: "sio",
|
|
|
|
sampleRate: 48000,
|
|
|
|
bufferSize: 1024,
|
|
|
|
inputChunkNum: 48,
|
|
|
|
speakers: [
|
|
|
|
{
|
|
|
|
"id": 100,
|
|
|
|
"name": "ずんだもん"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 107,
|
|
|
|
"name": "user"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 101,
|
|
|
|
"name": "そら"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 102,
|
|
|
|
"name": "めたん"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 103,
|
|
|
|
"name": "つむぎ"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
forceVfDisable: false,
|
2023-01-07 14:07:39 +03:00
|
|
|
voiceChangerMode: "realtime",
|
2023-01-10 18:59:09 +03:00
|
|
|
framework: "PyTorch",
|
|
|
|
onnxExecutionProvider: "CPUExecutionProvider"
|
2023-01-04 20:28:36 +03:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:52:01 +03:00
|
|
|
export const DefaultWorkletSetting: WorkletSetting = {
|
|
|
|
numTrancateTreshold: 188,
|
|
|
|
volTrancateThreshold: 0.0005,
|
|
|
|
volTrancateLength: 32
|
|
|
|
}
|
2023-01-07 14:07:39 +03:00
|
|
|
|
2023-01-05 05:45:42 +03:00
|
|
|
export const VOICE_CHANGER_CLIENT_EXCEPTION = {
|
|
|
|
ERR_SIO_CONNECT_FAILED: "ERR_SIO_CONNECT_FAILED",
|
|
|
|
ERR_SIO_INVALID_RESPONSE: "ERR_SIO_INVALID_RESPONSE",
|
2023-01-07 14:07:39 +03:00
|
|
|
ERR_REST_INVALID_RESPONSE: "ERR_REST_INVALID_RESPONSE",
|
|
|
|
ERR_MIC_STREAM_NOT_INITIALIZED: "ERR_MIC_STREAM_NOT_INITIALIZED"
|
2023-01-05 05:45:42 +03:00
|
|
|
|
|
|
|
} as const
|
|
|
|
export type VOICE_CHANGER_CLIENT_EXCEPTION = typeof VOICE_CHANGER_CLIENT_EXCEPTION[keyof typeof VOICE_CHANGER_CLIENT_EXCEPTION]
|
|
|
|
|
2023-01-04 20:28:36 +03:00
|
|
|
|