-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { config } from "@/config"; | ||
import { SoundManager } from "@/cubism-common"; | ||
import { Cubism4InternalModel, Cubism4ModelSettings } from "@/cubism4"; | ||
import { afterEach, beforeEach, expect } from "vitest"; | ||
import soundUrl from "../assets/shizuku/sounds/tapBody_00.mp3"; | ||
import { TEST_MODEL4, test } from "../env"; | ||
import { delay } from "../utils"; | ||
|
||
beforeEach(() => { | ||
config.sound = true; | ||
}); | ||
|
||
afterEach(() => { | ||
SoundManager.destroy(); | ||
}); | ||
|
||
test("lip sync", async () => { | ||
const mouthParam = "ParamMouthOpenY"; | ||
const model = new Cubism4InternalModel( | ||
await TEST_MODEL4.coreModel(), | ||
new Cubism4ModelSettings(TEST_MODEL4.modelJsonWithUrl), | ||
{ idleMotionGroup: "nonExistent" }, | ||
); | ||
|
||
expect(model.coreModel.getParameterValueById(mouthParam)).toBe(0); | ||
|
||
await expect(model.lipSync.play(soundUrl, { volume: 1 })).resolves.toBe(undefined); | ||
|
||
const audio = model.lipSync.currentAudio!; | ||
expect(audio).toBeTruthy(); | ||
|
||
let prevTime = 0; | ||
|
||
async function seekAndGetParam(time: number) { | ||
audio.currentTime = time / 1000; | ||
await delay(100); | ||
|
||
let value = NaN; | ||
|
||
model.once("beforeModelUpdate", () => { | ||
value = model.coreModel.getParameterValueById(mouthParam); | ||
}); | ||
model.update(time - prevTime, time); | ||
|
||
prevTime = time; | ||
|
||
return value; | ||
} | ||
|
||
const timeOffsetBeforeWave = 100; | ||
const timeOffsetDuringWave = 560; | ||
|
||
await expect(seekAndGetParam(timeOffsetBeforeWave)).resolves.toBe(0); | ||
await expect(seekAndGetParam(timeOffsetDuringWave)).resolves.toBeGreaterThan(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
declare const __CUBISM2_CORE_SOURCE__: string; | ||
declare const __CUBISM4_CORE_SOURCE__: string; | ||
|
||
const excludedLogs = [ | ||
`Live2D %s`, | ||
`profile : Desktop`, | ||
`[PROFILE_NAME]`, | ||
`[USE_ADJUST_TRANSLATION]`, | ||
`[USE_CACHED_POLYGON_IMAGE]`, | ||
`[EXPAND_W]`, | ||
`Live2D Cubism SDK Core Version`, | ||
`[CSM][I]`, | ||
]; | ||
|
||
const log = console.log; | ||
console.log = function (...args) { | ||
const firstArg = args[0]; | ||
|
||
if (typeof firstArg === "string" && excludedLogs.some((log) => firstArg.includes(log))) { | ||
return; | ||
} | ||
|
||
log(...args); | ||
}; | ||
|
||
(() => { | ||
__CUBISM2_CORE_SOURCE__; | ||
})(); | ||
(() => { | ||
__CUBISM4_CORE_SOURCE__; | ||
window.Live2DCubismCore = Live2DCubismCore; | ||
})(); | ||
|
||
console.log = log; |