voice-changer/client/lib/src/const.ts

229 lines
6.3 KiB
TypeScript
Raw Normal View History

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
2023-02-14 16:32:25 +03:00
2023-01-04 20:28:36 +03:00
// types
2023-01-12 10:38:45 +03:00
export type VoiceChangerServerSetting = {
2023-01-05 05:45:42 +03:00
convertChunkNum: number, // VITSに入力する変換サイズ。(入力データの2倍以上の大きさで指定。それより小さいものが指定された場合は、サーバ側で自動的に入力の2倍のサイズが設定される。)
2023-01-12 15:42:02 +03:00
minConvertSize: number, // この値より小さい場合にこの値に揃える。
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-12 10:38:45 +03:00
framework: Framework
onnxExecutionProvider: OnnxExecutionProvider,
2023-02-10 18:59:44 +03:00
f0Factor: number
2023-01-04 20:28:36 +03:00
}
2023-01-12 10:38:45 +03:00
export type VoiceChangerClientSetting = {
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[],
2023-02-12 06:25:57 +03:00
correspondences: Correspondence[],
2023-01-04 20:28:36 +03:00
forceVfDisable: boolean,
voiceChangerMode: VoiceChangerMode,
2023-02-14 16:32:25 +03:00
downSamplingMode: DownSamplingMode,
2023-02-12 12:19:22 +03:00
inputGain: number
outputGain: number
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-02-12 06:25:57 +03:00
export type Correspondence = {
"sid": number,
"correspondence": number,
"dirname": string
}
2023-01-04 20:28:36 +03:00
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,
2023-01-12 15:42:02 +03:00
minConvertSize: number,
2023-01-10 20:19:54 +03:00
crossFadeOffsetRate: number,
crossFadeEndRate: number,
2023-01-12 10:38:45 +03:00
crossFadeOverlapRate: number,
2023-01-10 20:19:54 +03:00
gpu: number,
srcId: number,
dstId: number,
framework: Framework,
2023-01-12 10:38:45 +03:00
onnxExecutionProvider: string[]
2023-02-10 18:59:44 +03:00
f0Factor: number
2023-01-08 10:18:20 +03:00
}
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]
2023-02-14 16:32:25 +03:00
export const DownSamplingMode = {
"decimate": "decimate",
"average": "average"
} as const
export type DownSamplingMode = typeof DownSamplingMode[keyof typeof DownSamplingMode]
2023-01-04 20:28:36 +03:00
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",
2023-01-12 15:42:02 +03:00
"minConvertSize": "minConvertSize",
2023-01-08 10:18:20 +03:00
"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",
2023-02-10 18:59:44 +03:00
"onnxExecutionProvider": "onnxExecutionProvider",
"f0Factor": "f0Factor"
2023-01-08 10:18:20 +03:00
} as const
export type ServerSettingKey = typeof ServerSettingKey[keyof typeof ServerSettingKey]
2023-01-04 20:28:36 +03:00
// Defaults
2023-01-12 10:38:45 +03:00
export const DefaultVoiceChangerServerSetting: VoiceChangerServerSetting = {
2023-01-07 14:07:39 +03:00
convertChunkNum: 32, //(★1)
2023-01-12 15:42:02 +03:00
minConvertSize: 0,
2023-02-12 16:14:34 +03:00
srcId: 0,
dstId: 101,
2023-01-04 20:28:36 +03:00
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,
2023-01-12 10:38:45 +03:00
crossFadeOverlapRate: 0.5,
2023-02-12 16:14:34 +03:00
framework: "PyTorch",
2023-02-10 18:59:44 +03:00
f0Factor: 1.0,
2023-01-12 10:38:45 +03:00
onnxExecutionProvider: "CPUExecutionProvider"
2023-01-05 05:45:42 +03:00
}
2023-01-12 10:38:45 +03:00
export const DefaultVoiceChangerClientSetting: VoiceChangerClientSetting = {
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: [
{
2023-02-12 06:25:57 +03:00
"id": 0,
2023-01-05 05:45:42 +03:00
"name": "user"
},
{
"id": 101,
2023-02-12 06:25:57 +03:00
"name": "ずんだもん"
2023-01-05 05:45:42 +03:00
},
{
"id": 102,
2023-02-12 06:25:57 +03:00
"name": "そら"
2023-01-05 05:45:42 +03:00
},
{
"id": 103,
2023-02-12 06:25:57 +03:00
"name": "めたん"
},
{
"id": 104,
2023-01-05 05:45:42 +03:00
"name": "つむぎ"
}
],
2023-02-12 06:25:57 +03:00
correspondences: [],
2023-01-05 05:45:42 +03:00
forceVfDisable: false,
2023-01-07 14:07:39 +03:00
voiceChangerMode: "realtime",
2023-02-14 16:32:25 +03:00
downSamplingMode: "average",
2023-02-12 12:19:22 +03:00
inputGain: 1.0,
outputGain: 1.0
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
2023-01-29 03:42:45 +03:00
////////////////////////////////////
// indexedDB
////////////////////////////////////
export const INDEXEDDB_DB_APP_NAME = "INDEXEDDB_KEY_VOICE_CHANGER"
export const INDEXEDDB_DB_NAME = "INDEXEDDB_KEY_VOICE_CHANGER_DB"
export const INDEXEDDB_KEY_CLIENT = "INDEXEDDB_KEY_VOICE_CHANGER_LIB_CLIENT"
export const INDEXEDDB_KEY_SERVER = "INDEXEDDB_KEY_VOICE_CHANGER_LIB_SERVER"
2023-01-29 09:25:44 +03:00
export const INDEXEDDB_KEY_MODEL_DATA = "INDEXEDDB_KEY_VOICE_CHANGER_LIB_MODEL_DATA"
export const INDEXEDDB_KEY_WORKLET = "INDEXEDDB_KEY_VOICE_CHANGER_LIB_WORKLET"