口型同步
你说什么?

让它更真实
游戏里有几个会说话的角色,而现在你只能看到一个对话气泡。其实我已经可以使用音频了,但看起来还不够好看。有人说话时嘴巴就得动,所以我研究了动画片里是怎么做的。
长话短说,只要有至少6到9张不同的嘴型图片,就能让角色看起来像是真的在说话。有好几种程序可以把音频转换成应该显示哪张图片。
音频输入 > 程序 > [ABBFGG] 输出。
然后在游戏中,每个字母都会显示头部的不同帧。
-- convert csv to a lua table
local libSyncTable = {}
for line in csvData:gmatch("[^\r\n]+") do
local a, b = line:match("(%S+)\t(%w)")
local framekey
if b == "A" then
framekey = 1
elseif b == "B" then
framekey = 2
elseif b == "C" then
framekey = 3
elseif b == "D" then
framekey = 4
elseif b == "E" then
framekey = 5
elseif b == "F" then
framekey = 6
-- elseif b == "G" then
-- framekey = 7
-- elseif b == "H" then
-- framekey = 8
-- elseif b == "X" then
-- framekey = 9
end
table.insert(libSyncTable, {a, framekey})
end
能做到这一点的程序有好几种,我选择了免费的 https://github.com/DanielSWolf/rhubarb-lip-sync。
if not os.path.exists(audioPath_lsc):
print(f"create lcs {audioPath} with text {text}")
with open("../temp/lipsync.txt", 'w') as file:
file.write(text)
command = [
"../src/lib-dev/rhubarb/rhubarb", # Het pad naar het rhubarb-programma
audioPath_ogg, # SOUND_FILE
"--recognizer", "pocketSphinx", # Recognizer instellen
"--exportFormat", "tsv", # Export formaat instellen
"--dialogFile", f"../temp/lipsync.txt", # TEMP_DIR voor dialogFile
"--output", audioPath_lsc, # OUTPUT_FILE
"--datFrameRate", "60", # Data frame rate
"--extendedShapes", "ABCDEF" # Extended shapes
]
result = subprocess.run(command, check=True)
if result.returncode != 0:
print("error")