Skip to content

Instantly share code, notes, and snippets.

@lincerely
Last active February 13, 2020 08:29
Show Gist options
  • Save lincerely/838900f9bde4d4fc674f2f73c11aadbd to your computer and use it in GitHub Desktop.
Save lincerely/838900f9bde4d4fc674f2f73c11aadbd to your computer and use it in GitHub Desktop.
"Visual novel reader" Mac workaround
#!/bin/bash
# How to use:
# 1. Download this script
# 2. Open any game made with rpg maker/ wolf rpg, using wine with JP encoding, for example:
# LC_ALL=ja_JP.UTF-8 LANG=ja_JP.UTF-8 wine Game.exe
# 3. Get the coordinate of the textbox, you can use Cmd-Shift-4 to find the value.
# 4. Change the config below
# 5. Save and Run the script
# Dependencies:
# wine: https://www.winehq.org/
# translate-shell: https://www.soimort.org/translate-shell/
# imagemagick: https://www.imagemagick.org
#
# You can install them using brew.
# Config:
# x1: top left x-coordinate of the textbox
# y1: top left y-coordinate of the textbox
#
x1=426
y1=570
w=585
h=125
translate() {
screencapture -x -R $x1,$y1,$w,$h /tmp/cap.png
convert /tmp/cap.png -threshold 50% -channel RGB -negate /tmp/cap.jpg && \
tesseract //tmp/cap.jpg stdout -l jpn |\
tee >(say -v Kyoko) |\
trans -e bing -b -j -s ja
}
while true; do
translate
read -p "Press enter to translate another dialogue. (Ctrl-c to exit)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment