This project automates the recording of game sentence audio to help with Anki Card Creation.
You can trigger the entire process with a single hotkey that cuts out the before and after voice, gets a screenshot, and sends both to Anki.
Every game/hook is different, so it's really improbable that any script can get it perfect everytime. Also OBS is sometimes a bit finnicky if running for too long. If the audio timing is off, please first try some troubleshooting steps before making an issue:
config.toml
to better match your situation. (i.e. if the hook is late, add a negative beginning offset)config.toml
I redid the config parsing cause config.py
is not ideal, especially when distributing a script via git.
Your config.toml
file allows you to configure key settings for the automation process, file paths, and other behavior. Here are the configurable options:
Duplicate/rename config_EXAMPLE.toml to get started
# Path configurations
[paths]
folder_to_watch = "~/Videos/OBS"
audio_destination = "~/Videos/OBS/Audio/"
screenshot_destination = "~/Videos/OBS/SS/"
# Anki Fields
[anki]
url = 'http://127.0.0.1:8765'
sentence_audio_field = "SentenceAudio"
picture_field = "Picture"
word_field = "Word"
current_game = "Japanese Game"
custom_tags = ['JapaneseGameMiner', "Test Another Tag"] # leave Empty if you dont want to add tags
add_game_tag = true
# Feature Flags
[features]
do_vosk_postprocessing = true
update_anki = true
remove_video = true
remove_screenshot = false
remove_audio = false
notify_on_update = true
open_anki_edit = false
# Vosk Model
[vosk]
url = "https://alphacephei.com/vosk/models/vosk-model-small-ja-0.22.zip"
# If you have a high-performance PC, with 16GB+ of RAM, you can uncomment and use this model:
# url = "https://alphacephei.com/vosk/models/vosk-model-ja-0.22.zip"
log-level = -1
[screenshot]
width = 0 # Desired Width of Screenshot, 0 to disable scaling (Default 0)
quality = 85 # Quality of image, 100 is lossless (Default 85)
extension = "webp" # Codec of screenshot, Recommend Keeping this as webp (Default webp)
[audio]
extension = "opus" # Desired Extension/codec of Trimmed Audio, (Default opus)
beginning_offset = 0.0 # Negative Value = More time at the beginning (i.e. -1 is 1 extra second at the beginning)
end_offset = 0.5 # Positive Value = More time at the end (i.e. 1 is 1 extra second at the end)
vosk_trim_beginning = false # Only change If you run into issues with clipboard timing, add a negative beginning_offset as well, Warning: You may end up with audio from previous line depending on your setup!
[obs]
enabled = true
start_buffer = true
full_auto_mode = false # Automatically Create Cards when you Create in Yomi. REQUIRED for multi-card-per-voiceline
host = "localhost"
port = 4455
password = "your_password_here"
get_game_from_scene = false
If you know what you are doing, do this in a venv, but I'm not going to explain that here.
pip install -r requirements.txt
To run this script, you will need to have FFmpeg installed. If you don't have FFmpeg installed on your system, you can easily install it via Chocolatey (Preferred), or install it yourself and ensure it's in the PATH.
First, ensure you have Chocolatey installed. If you don't have it installed, follow the instructions on the Chocolatey installation page or run the following command in an elevated PowerShell window (run as Administrator):
Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Once Chocolatey is installed, open a new PowerShell or Command Prompt window (with administrator rights).
Run the following command to install FFmpeg:
choco install ffmpeg
After the installation is complete, verify that FFmpeg is correctly installed by running the following command:
ffmpeg -version
If the installation was successful, you should see the version information for FFmpeg.
Now you're ready to use FFmpeg in the script!
With the Latest Update it is now possible to do full 1-click card creation with this tool + Yomitan. This is configured in the obs
section in your config.toml
Demo: https://www.youtube.com/watch?v=9dmmXO2CGNw
Screenshots to help with setup:
python main.py
Once the hotkey is triggered:
There is now an Update script included! running python update.py
in the directory will attempt to update your scripts to the latest release. If you have made changes to any of the files, they will be safely backed up before being replaced.
To ensure you always have the latest version of this script, you can use git pull
to update your local repository with the latest changes from the remote repository.
Open your terminal and navigate to the directory where you cloned the repository:
cd path/to/script
Run the following command to fetch and integrate the latest changes:
git pull origin main
origin
refers to the remote repository from which you cloned the code.main
refers to the main branch of the repository. If your default branch has a different name (e.g., master
or dev
), replace main
with that branch name.The git pull
command will download and apply any updates from the remote repository to your local version.
$ cd path/to/script
$ git pull origin master
If you run into issues ask in my discord, or make an issue here.
If you've benefited from this or any of my other projects, please consider supporting my work via Github Sponsors or Ko-fi.