123 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-01-05 02:28:36 +09:00
// (★1) chunk sizeは 128サンプル, 256byte(int16)と定義。
// (★2) 256byte(最低バッファサイズ256から間引いた個数x2byte)をchunkとして管理。
// types
export type VoiceChangerRequestParamas = {
2023-01-05 11:45:42 +09:00
convertChunkNum: number, // VITSに入力する変換サイズ。(入力データの2倍以上の大きさで指定。それより小さいものが指定された場合は、サーバ側で自動的に入力の2倍のサイズが設定される。)
2023-01-05 02:28:36 +09:00
srcId: number,
dstId: number,
gpu: number,
crossFadeLowerValue: number,
crossFadeOffsetRate: number,
crossFadeEndRate: number,
}
export type VoiceChangerOptions = {
audioInputDeviceId: string | null,
mediaStream: MediaStream | null,
mmvcServerUrl: string,
2023-01-05 11:45:42 +09:00
protocol: Protocol,
2023-01-05 02:28:36 +09:00
sampleRate: SampleRate, // 48000Hz
bufferSize: BufferSize, // 256, 512, 1024, 2048, 4096, 8192, 16384 (for mic stream)
2023-01-05 11:45:42 +09:00
inputChunkNum: number, // n of (256 x n) for send buffer
2023-01-05 02:28:36 +09:00
speakers: Speaker[],
forceVfDisable: boolean,
voiceChangerMode: VoiceChangerMode,
}
export type Speaker = {
"id": number,
"name": string,
}
// Consts
2023-01-05 11:45:42 +09:00
export const Protocol = {
2023-01-05 02:28:36 +09:00
"sio": "sio",
"rest": "rest",
} as const
2023-01-05 11:45:42 +09:00
export type Protocol = typeof Protocol[keyof typeof Protocol]
2023-01-05 02:28:36 +09: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 11:45:42 +09:00
"256": 256,
"512": 512,
2023-01-05 02:28:36 +09:00
"1024": 1024,
2023-01-05 11:45:42 +09:00
"2048": 2048,
"4096": 4096,
"8192": 8192,
"16384": 16384
2023-01-05 02:28:36 +09:00
} as const
export type BufferSize = typeof BufferSize[keyof typeof BufferSize]
// Defaults
export const DefaultVoiceChangerRequestParamas: VoiceChangerRequestParamas = {
2023-01-05 11:45:42 +09:00
convertChunkNum: 1, //(★1)
2023-01-05 02:28:36 +09:00
srcId: 107,
dstId: 100,
gpu: 0,
crossFadeLowerValue: 0.1,
2023-01-05 11:45:42 +09:00
crossFadeOffsetRate: 0.1,
crossFadeEndRate: 0.9
}
export const DefaultVoiceChangerOptions: VoiceChangerOptions = {
audioInputDeviceId: null,
mediaStream: null,
mmvcServerUrl: "https://192.168.0.3:18888/test",
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,
voiceChangerMode: "realtime"
2023-01-05 02:28:36 +09:00
}
2023-01-05 11:45:42 +09:00
export const VOICE_CHANGER_CLIENT_EXCEPTION = {
ERR_SIO_CONNECT_FAILED: "ERR_SIO_CONNECT_FAILED",
ERR_SIO_INVALID_RESPONSE: "ERR_SIO_INVALID_RESPONSE",
ERR_REST_INVALID_RESPONSE: "ERR_REST_INVALID_RESPONSE"
} as const
export type VOICE_CHANGER_CLIENT_EXCEPTION = typeof VOICE_CHANGER_CLIENT_EXCEPTION[keyof typeof VOICE_CHANGER_CLIENT_EXCEPTION]
2023-01-05 02:28:36 +09:00