Add documentation and coding guidelines for VRCT backend
- Introduced a comprehensive coding rules document outlining naming conventions, module structure, import order, type annotations, error handling, and testing practices. - Created a specification document detailing project goals, target users, and functional/non-functional requirements for the VRCT project. - Added a design document describing the application's architecture, initialization policies, concurrency models, and error handling strategies. - Included a detailed design document specifying major classes, functions, data structures, and exception handling. - Removed outdated mypy configuration and several unused scripts related to documentation verification and cleanup. - Deleted test files for OSC and overlay imports as part of the cleanup process.
This commit is contained in:
66
src-python/docs/詳細設計書.md
Normal file
66
src-python/docs/詳細設計書.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# 詳細設計書
|
||||
|
||||
この文書は主要クラス・関数の詳細、データ構造、例外ケース、スレッドの振る舞いを記載する。
|
||||
|
||||
目次
|
||||
- Model
|
||||
- Controller
|
||||
- Main (mainloop)
|
||||
- DeviceManager
|
||||
- Utils
|
||||
- モデルの重みダウンロードと整合性
|
||||
|
||||
## Model
|
||||
- シングルトン: `model = Model()`
|
||||
- 遅延初期化: `init()` と `ensure_initialized()` を備え、init は重いリソース(Overlay, Translator, Watchdog, OSC ハンドラ等)を構築する。
|
||||
- 主な責務
|
||||
- 翻訳/文字起こし関連の起動停止ラッパ
|
||||
- Overlay/OSChandler/WebSocket の操作
|
||||
- キーワード検出(flashtext)と重複検出
|
||||
- VRAM エラー検出とフォールバック
|
||||
- 重要属性(抜粋)
|
||||
- `translator` : Translator インスタンス
|
||||
- `overlay` / `overlay_image` : Overlay 系
|
||||
- `mic_*`, `speaker_*` : 録音、トランスクリプタ、energy recorder
|
||||
- `watchdog` : Watchdog
|
||||
- `osc_handler`, `websocket_server`
|
||||
- スレッド制御
|
||||
- threadFnc を用いて周期処理を回す。stop/pause/resume が可能。
|
||||
|
||||
## Controller
|
||||
- GUI からの要求を受け、Model を操作して結果を run() コールバックへ返す。
|
||||
- 各種設定変更 (/set/ や /get/ エンドポイント) を実装。
|
||||
- 翻訳/文字起こし/オーバーレイ連携ロジックを持ち、メッセージ整形(messageFormatter)や OSC の送信を行う。
|
||||
- ダウンロード作業は別スレッドで行い、進捗を run_mapping を通して通知。
|
||||
|
||||
## Main (mainloop.Main)
|
||||
- stdin を readline() で受け取り JSON を parse、endpoint と data をキューへ投入。
|
||||
- worker_count 個の handler スレッドが queue を取り出し `_call_handler` を実行。
|
||||
- endpoint ロック正規化: `/set/enable/...` と `/set/disable/...` は同じ正規化キー `/lock/set/...` を共有して排他制御。
|
||||
- エラーレスポンスの標準化と再試行ロジック(status==423 は再キュー化)。
|
||||
|
||||
## DeviceManager
|
||||
- シングルトン。初期化は軽量で、`init()` により内部構造をセット、実デバイスは `update()` で取得。
|
||||
- Windows 環境では COM イベント (pycaw/MMNotificationClient) を用いた検出か、PyAudio によるポーリングでデバイス一覧を構成。
|
||||
- コールバック設計: 変更検出時に Controller のコールバックを呼び出して UI 更新を促す。
|
||||
|
||||
## Utils
|
||||
- `validateDictStructure(data, structure)` : JSON 構造検証。
|
||||
- `getComputeDeviceList()` / `getBestComputeType()` : CPU/CUDA を列挙し、推奨 compute_type を返す。
|
||||
- `setupLogger()` / `printLog()` / `printResponse()` / `errorLogging()` : ログ、標準出力の整形、エラー記録。
|
||||
- ネットワーク/ソケット/IP アドレス検査ユーティリティ。
|
||||
|
||||
## モデル重みダウンロード
|
||||
- `models.translation.translation_utils` と `models.transcription.transcription_whisper` にダウンロード/チェック関数があり、チェックサムやファイル存在を検証する。
|
||||
- GUI からの要求は Controller により非同期スレッドで実行され、進捗コールバックが run_mapping を介してフロントエンドに渡る。
|
||||
|
||||
## エッジケース / 例外処理
|
||||
- 外部 API のレート制限や認証エラーは呼び出し元に 400 系のレスポンスを返し、必要であればフォールバック実装(CTranslate2 への切替)を行う。
|
||||
- 大きなモデル実行時の VRAM エラーは検出し、当該機能を無効化してユーザへ通知する。
|
||||
- 音声デバイスが存在しない場合は NoDevice を返し、UI 側で扱う。
|
||||
|
||||
## テスト観点
|
||||
- メッセージ受信/送信のエンドツーエンド: stdin -> handler -> Controller -> Model -> printResponse の流れ。
|
||||
- デバイス挙動: DeviceManager.update() がデバイス一覧を取得できるか(PyAudio 経由)。
|
||||
- モデルダウンロード: ダウンロード成功・失敗、チェックサム検証。
|
||||
- ログ/エラー: errorLogging() による例外トレースが error.log に記録されるか。
|
||||
Reference in New Issue
Block a user