Claude CodeのMCPを使ってWSL2でもAivisSpeechにしゃべらせたい!
そもそも、Hookでいいじゃない!!
というのは、あえて置いときます。
ことのほったん
とあるのお部屋にて、とある方がWindow環境でニケちゃん↓出来ないって困ってました。
なるほど、AivisSpeech見たらVOICEVOX互換って書いてあった。
じゃあWSL環境で作ってみよう
早速、Windows+WSL2でニケちゃんMCPやってみましょう~!
わたしの環境
環境と既にインストールされているもの
- DockerDesktop
- Windwos11
- グラフィックボード RADEON社
こんかい準備するもの
- Docker版 AivisSpeech Engine (わたしはRadeonなので CPU ver)
利用前提環境の準備
Docker版 AivisSpeechEngineのイメージを取得
WSLにログインして、以下のDockerコマンドでDockerイメージをPull
docker pull ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
以下のようなログになるよ
cpu-latest: Pulling from aivis-project/aivisspeech-engine
9113feee1f2a: Pull complete
b29845f05c34: Pull complete
89dc6ea4eae2: Pull complete
0b9c1a1884f5: Pull complete
2afd99efa0a7: Pull complete
1df450faa589: Pull complete
ecc75e4719ec: Pull complete
59530021a611: Pull complete
83ffba936c0a: Pull complete
aa5d4346a21a: Pull complete
9d80da36f822: Pull complete
583acbd98172: Pull complete
d25f1638c57e: Pull complete
7106d534cd47: Pull complete
bbfa74cd6ce2: Pull complete
Digest: sha256:c18026ab21e5133eed19882f22bccc091c86b30d891e1e4148a05dce059e0d31
Status: Downloaded newer image for ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
Dockerで AivisSpeechEngine を起動
ここではまったよ!
参考:はまったこと
以下のDockerコマンドでコンテナを起動
docker run --rm -p '10101:10101' -v ~/.local/share/AivisSpeech-Engine:/home/user/.local/share/AivisSpeech-Engine-Dev ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
以下どちらかでコンテナ起動確認
-
DockerDesktopのContainerタブ
-
docker psコマンド
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abec89209278 ghcr.io/aivis-project/aivisspeech-engine:cpu-latest "/entrypoint.sh gosu…" 13 minutes ago Up 13 minutes 0.0.0.0:10101->10101/tcp musing_euler
ホストのブラウザで確認
おめでとうございます!
実際に利用してみる
前提が整ったので、実際にニケちゃんのMCPを利用したいと思います
ニケちゃんMCP準備
ニケちゃんのGitHubにインストール、MCP起動手順記載ありますが、手順を載せます。
Claude CodeのMCPへニケちゃんをMCP登録(ローカル)
今回は「/mnt/d/claude/poc/nike-chan-example」で作業します
cd /mnt/d/claude/poc/nike-chan-example
一部ソースいじるため、あえてクローンします
git clone git@github.com:tegnike/mcp-simple-aivisspeech.git
cloneしたら、WSLで動作するようにaivisspeech-client.tsのplayAudioメソッドを修正
パス変換して無理やりPowerShell叩きます!
private async playAudio(audioData: ArrayBuffer): Promise<void> {
const fs = await import('fs');
const path = await import('path');
const { spawn, execSync } = await import('child_process');
const os = await import('os');
return new Promise((resolve, reject) => {
// WindowsのTempフォルダにファイルを保存
const tempFileName = `aivisspeech_${Date.now()}.wav`;
const wslTempPath = path.join('/mnt/c/Windows/Temp', tempFileName);
const windowsTempPath = `C:\\Windows\\Temp\\${tempFileName}`;
// 音声データを一時ファイルに保存
fs.writeFileSync(wslTempPath, Buffer.from(audioData));
// プラットフォームに応じた再生コマンドを選択
let command: string;
let args: string[];
// WSL環境からWindowsのPowerShellを実行
command = '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe';
args = [
'-NoProfile',
'-Command',
`Add-Type -AssemblyName System.Media; $player = New-Object System.Media.SoundPlayer("${windowsTempPath}"); $player.PlaySync()`,
];
const player = spawn(command, args);
player.on('close', (code) => {
// 一時ファイルを削除
try {
fs.unlinkSync(wslTempPath);
} catch (e) {
console.error('一時ファイルの削除に失敗:', e);
}
if (code === 0) {
resolve();
} else {
reject(new Error(`音声再生に失敗しました。終了コード: ${code}`));
}
});
player.on('error', (error) => {
// 一時ファイルを削除
try {
fs.unlinkSync(wslTempPath);
} catch (e) {
console.error('一時ファイルの削除に失敗:', e);
}
reject(new Error(`音声再生エラー: ${error.message}`));
});
// PowerShellのエラー出力を確認
player.stderr?.on('data', (data) => {
console.error('PowerShell エラー:', data.toString());
});
});
}
cloneしたプロジェクトのディレクトリに移動し、インストール&ビルドし、グローバルリンク張りますます
cd ./mcp-simple-aivisspeech/
npm install
npm run build
npm link
MCPサーバを起動します
mcp-simple-aivisspeech
以下ログが出ればOK
MCP AIVISSPEECH Server running on stdio
作業ディレクトリに戻ります
cd ../
claude mcp addでニケちゃんMCPを追加します
claude mcp add aivisspeech -- mcp-simple-aivisspeech
以下ログで追加完了
Added stdio MCP server aivisspeech with command: mcp-simple-aivisspeech to local config
claude code で確認する
claude コマンドで claude codeに入る
claude
claude codeで登録されたMCPをスラッシュコマンドで確認
/mcp list
aivisspeechが確認できればOK
では、しゃべってもらおう
やっと、話してもらえる環境が整いました。
claude codeのプロンプトで以下をのプロンプトを実行すると・・・。
AIVISSPEECHで「こんにちは、テストです」を話者ID 888753760で読み上げてください
どこからともなく、「こんにちは、テストです」が聞こえればせいこう!です。
おつかれさまでした。
はまったこと
windowsアプリ版で動作させようとした
つい、AivisSpeechからWindows版ダウンロードしてしまった。
HostのWindowsのブラウザで「localhost:10101」につなげて設定画面を確認
Windowsアプリ版を起動しWSLから繋がらないん…と一瞬なってました
初回起動時にPermission deniedのエラー
以下のようなエラーが出たら、権限の問題です。
xxxxx@DESKTOP-5IISQ2F:/mnt/c/Users/xxxxx$ docker run --rm -p '10101:10101' \
-v ~/.local/share/AivisSpeech-Engine:/home/user/.local/share/AivisSpeech-Engine-Dev \
ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
+ exec gosu user /opt/python/bin/poetry run python ./run.py --host 0.0.0.0
Traceback (most recent call last):
File "/opt/aivisspeech-engine/./run.py", line 30, in <module>
from voicevox_engine.aivm_manager import AivmManager
File "/opt/aivisspeech-engine/voicevox_engine/aivm_manager.py", line 18, in <module>
from voicevox_engine.aivm_infos_repository import AivmInfosRepository
File "/opt/aivisspeech-engine/voicevox_engine/aivm_infos_repository.py", line 19, in <module>
from voicevox_engine.logging import logger
File "/opt/aivisspeech-engine/voicevox_engine/logging.py", line 14, in <module>
ENGINE_LOG_DIR.mkdir(parents=True, exist_ok=True)
File "/opt/python/lib/python3.11/pathlib.py", line 1116, in mkdir
os.mkdir(self, mode)
PermissionError: [Errno 13] Permission denied: '/home/user/.local/share/AivisSpeech-Engine-Dev/Logs'
以下コマンドで確認すると、たぶん所有者「root」になっている
xxxxx@DESKTOP-5IISQ2F:/mnt/c/Users/xxxxx$ ls -ld ~/.local/share/AivisSpeech-Engine
drwxr-xr-x 2 root root 4096 Jul 1 22:03 /home/xxxxx/.local/share/AivisSpeech-Engine
権限をユーザに変更(今回はxxxxx)
変更時、パスワード入力を求められます。
xxxxx@DESKTOP-5IISQ2F:/mnt/c/Users/xxxxx$ sudo chown -R xxxxx:xxxxx ~/.local/share/AivisSpeech-Engine
[sudo] password for xxxxx:
xxxxx@DESKTOP-5IISQ2F:/mnt/c/Users/xxxxx$ ls -ld ~/.local/share/AivisSpeech-Engine
drwxr-xr-x 2 xxxxx xxxxx 4096 Jul 1 22:03 /home/xxxxx/.local/share/AivisSpeech-Engine
再度、起動で解決する(はず!)
xxxxx@DESKTOP-5IISQ2F:/mnt/c/Users/xxxxx$ docker run --rm -p '10101:10101' \
-v ~/.local/share/AivisSpeech-Engine:/home/user/.local/share/AivisSpeech-Engine-Dev \
ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
DNSの名前解決できず、モデルのダウンロードできない場合
DNSの名前解決が出来ず、以下のようなエラーでBERTモデルのダウンロード失敗で落ちてしまった場合
OSError: We couldn't connect to 'https://huggingface.co' to load the files, and couldn't find them in the cached files.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
DNSサーバでGoogleあたりを指定して、起動してみましょう
docker run --rm -p '10101:10101' --dns 8.8.8.8 --dns 8.8.4.4 -v ~/.local/share/AivisSpeech-Engine:/home/user/.local/share/AivisSpeech-Engine-Dev ghcr.io/aivis-project/aivisspeech-engine:cpu-latest
Discussion