Skip to content

Linux recipes

Piotr Grabowski edited this page Jan 26, 2023 · 13 revisions

For more, see Mining recipes and OCR recipes.

Cleanly launch/close a VN + Textractor + Kamite in a single terminal window

A template of a bash script to launch multiple programs that does not leave behind background processes when terminated with Ctrl + C.

#!/usr/bin/env bash

trap "kill 0" EXIT

export WINEPREFIX=/path/to/wineprefix
export WINEARCH=win32
export LANG="ja_JP.UTF-8"

TZ="JAPAN" \
  wine start /exec "/path/to/vn/VN.lnk" &
kamite --profile=vn --controlWindow=no &
wine "/path/to/textractor/Textractor.exe" &

wait

Credit: https://spin.atomicobject.com/2017/08/24/start-stop-bash-background-process/.

Watch clipboard, send text to Kamite, automatically look up with DeepL (wlroots)

#!/usr/bin/env bash

CMD_ENDPOINT="localhost:4110/cmd"

wl-paste --watch bash -c \
  "xargs -r -0 -I{} curl -i -X POST -d '{\"chunk\":\"{}\"}' $CMD_ENDPOINT/chunk/show;
   sleep 0.1;
   curl -i -X POST -d '{\"targetSymbol\":\"DEP\"}' $CMD_ENDPOINT/misc/lookup"

Read text from Kamite aloud using Microsoft’s TTS

The contrib/edge-tts-cached.sh script is a wrapper for the edge-tts Python module, which can send text to Microsoft’s freely-accessible TTS API and receive an audio file with the text spoken by a synthesized voice. The script then plays the audio using mpv.

The added value of the script over bare edge-tts is that it saves locally the most recent audio response with the correspoding request text, so that subsequent consecutive requests for the same string of text are served directly from the local audio file instead of being re-requested from the API.

Setup:

  1. Install mpv and edge-tts (e.g., pipx install edge-tts or paru -S python-edge-tts)

    Test the TTS service and playback:

    edge-playback --voice ja-JP-NanamiNeural --text "かみて"
  2. Download contrib/edge-tts-cached.sh and set it as executable.

  3. Set up a Kamite custom command that will run the wrapper script with Kamite’s effective text as an argument:

    In Kamite config:

    commands: {
      custom: [
        ${CUSTOM_COMMANDS.say}
      ]
    }
    
    CUSTOM_COMMANDS: {
      say: {
        symbol: SAY
        name: Say with TTS
        command: ["/path/to/edge-tts-cached.sh", "ja-JP-NanamiNeural", "{effectiveText}"]
      }
    }

With this setup, a button labelled SAY will appear in Kamite's command palette, that, upon click, will cause the current chunk to be read aloud (or a part of it, if text selection present; or multiple chunks combined, if there is a selection in the Chunk History tab).

Clone this wiki locally