This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ユーザとの対話は日本語で行うこと。
- 本プロジェクトはDLL形式で動作する。メモリ解放、ヒープ管理の安全性に最新の注意を払うこと。
- リファクタリングの際はデグレーションを防ぎつつも、パフォーマンスや安全性のための最適化を積極的に行うこと。
GhostSpeaker is a Rust-based SHIORI plugin for 伺か (Ukagaka) that enables text-to-speech functionality for ghost characters using various TTS engines. It's built as a Windows DLL (ghost_speaker.dll) that integrates with the 伺か ecosystem.
# Build in release mode (standard)
cargo build --release
# Build for 32-bit Windows (production target)
cargo build --release --target=i686-pc-windows-msvc
# Run tests
cargo test
# Format code (uses 2-space indentation, no hard tabs)
cargo fmt
# Check for clippy warnings
cargo clippyThe project is configured to build 32-bit Windows DLLs for compatibility with 伺か systems:
- Target:
i686-pc-windows-msvc - Output:
ghost_speaker.dll(copied to project root) - CI builds automatically update MD5 checksums via GitHub Actions
Plugin Interface (src/lib.rs)
- SHIORI plugin entry points:
load(),loadu(),unload(),request() - Handles UTF-8/ANSI encoding conversion for Japanese text
- Manages plugin lifecycle and panic handling
Engine System (src/engine/)
- Modular TTS engine support via trait system
- Supported engines: COEIROINK (v1/v2), VOICEVOX, LMROID, SHAREVOX, ITVOICE, AivisSpeech, 棒読みちゃん
- Each engine has dedicated modules with
speaker.rsandpredict.rs - HTTP-based communication with TTS services (except 棒読みちゃん)
Event Handling (src/events/)
menu.rs: Plugin menu system integrationperiodic.rs: Timer-based eventsother_ghost.rs: Inter-ghost communicationcommon.rs: Shared event utilities
Audio System
src/player.rs: Audio playback using rodiosrc/queue.rs: Speech queue managementsrc/speaker.rs: Voice/speaker configuration
Configuration (src/variables/)
rawvariables.rs: Persistent settings storage- Saves to
vars.yamlin plugin directory - Manages per-ghost voice assignments and engine settings
Async Architecture
- Heavy use of
tokiofor async HTTP requests to TTS engines async-traitfor engine abstraction- Queue system for managing concurrent speech requests
Plugin Integration
- SHIORI protocol implementation for 伺か communication
- Windows-specific memory management via
shiori_hglobal - Japanese text encoding support (UTF-8/ANSI fallback)
Engine Abstraction
- Trait-based design allows easy addition of new TTS engines
- Each engine implements speaker discovery and speech synthesis
- Consistent API despite different underlying protocols
- Built for 32-bit Windows compatibility
- Uses Windows API for process management (
CreateProcessW) - Character encoding handling for Japanese text is critical
- Most engines use REST APIs on localhost ports
- 棒読みちゃん uses a different protocol
- Engines must be running before plugin can connect
- Each engine has unique speaker/voice identification schemes
vars.yaml: User settings and voice assignmentsdescript.txt: Plugin metadata for 伺かrustfmt.toml: Code formatting (2 spaces, no hard tabs)
- GitHub Actions builds on Windows
- Auto-updates MD5 checksums for distribution
- Builds target i686-pc-windows-msvc specifically