Синхронизация губ
Что ты сказал?

Сделать реалистичнее
В игре будут говорящие персонажи, а пока видно только облачко с текстом. Возможность использовать звук у меня уже была, но выглядело это ещё некрасиво. Когда кто-то говорит, рот должен двигаться, поэтому я выяснил, как это делают в мультфильмах.
Короче говоря, имея хотя бы от 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")