Doki Doki Literature Club x Python ① Character file analysis


Doki Doki Literature Club, a game that everyone in the know knows.

Did you know that this pounding literary club is written in Python (Renpy)? Then, this project is to use that Python to make the Doki Doki Literature Club naked.

If you are interested, please play the main story. Free.

__ Includes spoilers __ __ The copyright of the content of the article belongs to the author of the Doki Doki Literature Club __

Week 1 "Character file analysis"

Character files deeply involved in story progress

Halfbeak (Awesome air conditioner)

See sayori.chr.

When you open it with a text file normally, the beginning is


It starts with. From this, it may be a __.ogg file (audio data) __.

When you actually play it, you should hear high frequency noise.

This is spectrogram-analyzed.

Spectrogram analysis is a visualization of audio data with time on the horizontal axis and frequency on the vertical axis.

Click here for the code

from pydub import AudioSegment
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

#Read ogg and sample
AudioSegment.ffmpeg = "/."
sound = AudioSegment.from_ogg("sayori.ogg")
samples = np.array(sound.get_array_of_samples())
sample = samples[::sound.channels]

#Spectral storage width
w = 100
s = 50

ampList = []
argList = []

#Fourier transform
for i in range(int((sample.shape[0]- w) / s)):
    data = sample[i*s:i*s+w]
    spec = np.fft.fft(data)
    spec = spec[:int(spec.shape[0]/2)]
    spec[0] = spec[0] / 2

freq = np.fft.fftfreq(data.shape[0], 1.0/sound.frame_rate)
freq = freq[:int(freq.shape[0]/2)]

time = np.arange(0, i+1, 1) * s / sound.frame_rate

ampList = np.array(ampList)
argList = np.array(argList)

df_amp = pd.DataFrame(data=ampList, index=time, columns=freq)
plt.figure(figsize=(10, 10))
sns.heatmap(data=np.log(df_amp.iloc[:, :100].T), 

First, challenge with w = 100 s = 50. Figure_1.png

I see something meaningful. Let's make it a little rougher. w = 200 s = 100 It is easier to see with cmap =


No, it's a QR code. If you regenerate this into a 25x25 QR code ... S__65118215.jpg


44GC44Gq44Gf44GM44GT44Gu5omL57SZ44KS6Kqt44KT44Gn44G ....

Repeat 44xx. Especially when I checked the first 44GC, it seems to be" A "of base64 encoding. That's why base64 decodes it.

import base64

with open("yuri.chr", mode="rb") as f:
    txt =
If you are reading this letter, it means that the heart symbol has found a small wooden box as a landmark. Congrats ! Maybe you are the first time. I didn't mean to show it to anyone, but the red one is this
I'm thrilled when I think of finding a letter and reading my story. Someone who I couldn't have met knows me deeply. I'm obsessed with an idea. Someone in us dies ... it may be tomorrow
And those who are left do not know it. I wrote to you all the proof that I have lived so far in this letter. So, as long as you don't forget me, I can live forever. You read this letter and fascinate
I'm wondering if I'll be able to or hate it while writing this letter. Don't you think it's interesting?

(The following is abbreviated by your own hands.) 


As before, open it as text for the time being.


came out. Extension JFIF. If you set the extension to JPEG, you can see it as a flat image.

I tried to handle this with Python, but unfortunately I rely on Unity because I'm not sure. Create a cone and paste the texture.

The writing seemed to be dangerous, so please do a Google image search on "natsuki.chr".


Finally appeared Monica-chan. As usual.


No, it says PNG! Then it will open. monika.png

You can see the black and white mosaic in the center. Binary encode this (black is 0, white is 1) Prepare a cropped image excluding the surrounding red part,

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt

#Loading the original image
im = np.array('text.png'))

txt_binary = ""
im = im.reshape([im.shape[0] * im.shape[1], 1])
for x in im:
    if x == 1:
        txt_binary += "1"
        txt_binary += "0"


txt = ""
while True:
    tmp = txt_binary[0:8]
    if tmp == "00000000":
    txt_binary = txt_binary[8:]
    txt += chr(int("0b"+tmp, 0))


base64 encoding.

Can you hear me?

...Who are you?

I can't...I can't see you.

But I know you're there. can definitely hear me.

You've been watching for a while now, right?

(The following is abbreviated by your own hands.) 

At the end

It was just like that. It's just a story part, but let's elaborate so far. I felt it was wonderful.

Next time, we will talk about establishing the main story. see you.

Reference site

Recommended Posts

Doki Doki Literature Club x Python ① Character file analysis
2.x, 3.x character code of python
[Python] Get the character code of the file
[Python] [chardet] Automatic detection of character code of file
Convert the character code of the file with Python3
Script python file
Data analysis python
python character code
Python file processing
Download the file while viewing the progress in Python 3.x