リップシンク

何て言ったの?

ピクセル+動き+音=命

よりリアルに

ゲームには話すキャラクターが何人かいますが、今は吹き出しが表示されるだけです。音声を使えるようにはすでになっていましたが、見た目はまだいまひとつでした。誰かが話すときは口が動かなければなりません。そこで、アニメではどうやっているのかを調べました。

手短に言うと、口の画像が最低でも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")