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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- ja
|
| 4 |
+
base_model:
|
| 5 |
+
- webbigdata/VoiceCore
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# VoiceCore GGUF - 次世代 日本語Voice AI Agent用モデル(量子化版)
|
| 9 |
+
|
| 10 |
+
これは[webbigdata/VoiceCore](https://huggingface.co/webbigdata/VoiceCore)のGGUF(量子化)版です。
|
| 11 |
+
Mac環境や低スペックPCでも手軽に動作させることができるように最適化されています。
|
| 12 |
+
|
| 13 |
+
## GGUFとは?
|
| 14 |
+
|
| 15 |
+
GGUF(GPT-Generated Unified Format)は、大規模言語モデルを効率的に配布・実行するためのファイルフォーマットです。
|
| 16 |
+
llama.cppというGPUがない環境でもCPU環境でもLLMを動かすため純粋なC++プログラムとして開発がスタートしましたが、移植性が高いため、Macやスマートフォンなどでも動作するようになっています。
|
| 17 |
+
|
| 18 |
+
### 主な特徴
|
| 19 |
+
- **軽量化**: モデルサイズを大幅に削減(元の50%以下に)
|
| 20 |
+
- **高速起動**: モデルの読み込みが高速
|
| 21 |
+
- **メモリ効率**: RAM使用量を削減
|
| 22 |
+
- **互換性**: CPU/GPU両方で動作可能
|
| 23 |
+
- **簡単実行**: 様々な環境に移植されており特別な環境構築が不要
|
| 24 |
+
|
| 25 |
+
### 量子化について
|
| 26 |
+
量子化とは、モデルの重みを低精度(例:32bit→4bit)に変換する技術です。これにより:
|
| 27 |
+
- ファイルサイズが削減
|
| 28 |
+
- 必要メモリが減少
|
| 29 |
+
- 推論速度が向上
|
| 30 |
+
- わずかな精度低下と引き換えに実用性が向上
|
| 31 |
+
|
| 32 |
+
## 提供モデル
|
| 33 |
+
|
| 34 |
+
| モデル名 | サイズ | 特徴 | 推奨用途 |
|
| 35 |
+
|---------|--------|------|----------|
|
| 36 |
+
| VoiceCore-BF16.gguf | 6.61 GB | 最高品質、元モデルと同等の精度 | 高品質が必要な場合 |
|
| 37 |
+
| VoiceCore-Q4_K-f16.gguf | 2.66 GB | バランス型、実用的な精度 | 通常使用(要注意) |
|
| 38 |
+
|
| 39 |
+
⚠️ **重要な注意事項**: VoiceCoreは量子化に敏感なモデルです。Q4_K-f16以下の量子化レベルでは音声ファイルの作成に失敗する事がある事がわかっています。安定性を重視する場合はBF16版の使用を推奨します。
|
| 40 |
+
|
| 41 |
+
## システム概要
|
| 42 |
+
|
| 43 |
+
```mermaid
|
| 44 |
+
graph LR
|
| 45 |
+
A[ユーザー入力] --> B[llama.cpp サーバー]
|
| 46 |
+
B --> C[VoiceCore GGUF]
|
| 47 |
+
C --> D[音声トークン生成]
|
| 48 |
+
D --> E[SNACデコーダー]
|
| 49 |
+
E --> F[音声ファイル/リアルタイム再生]
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## セットアップガイド(Mac/初心者向け)
|
| 53 |
+
|
| 54 |
+
### 1. 必要なツールのインストール
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
# Homebrewのインストール(まだの場合)
|
| 58 |
+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
| 59 |
+
|
| 60 |
+
# 必要なパッケージのインストール
|
| 61 |
+
brew install cmake
|
| 62 |
+
brew install python@3.11
|
| 63 |
+
|
| 64 |
+
# Pythonライブラリのインストール
|
| 65 |
+
pip3 install torch snac numpy httpx pyaudio scipy
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### 2. llama.cppのセットアップ
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
# llama.cppのクローン
|
| 72 |
+
git clone https://github.com/ggerganov/llama.cpp
|
| 73 |
+
cd llama.cpp
|
| 74 |
+
|
| 75 |
+
# ビルド(Macの場合)
|
| 76 |
+
make
|
| 77 |
+
|
| 78 |
+
# Metal(Mac GPU)を使用する場合
|
| 79 |
+
make LLAMA_METAL=1
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### 3. モデルのダウンロード
|
| 83 |
+
|
| 84 |
+
[dahara1/orpheus-3b-0.1-ft_gguf](https://huggingface.co/webbigdata/VoiceCore_gguf)から必要なモデルをダウンロードしてください。
|
| 85 |
+
|
| 86 |
+
### 4. サーバーの起動
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
# 基本的な起動方法
|
| 90 |
+
.//llama-server \
|
| 91 |
+
-m path/to/VoiceCore-BF16.gguf \
|
| 92 |
+
--prio 3 \
|
| 93 |
+
-c 2048 \
|
| 94 |
+
-e \
|
| 95 |
+
-n -2 \
|
| 96 |
+
-fa \
|
| 97 |
+
-ngl 99 \
|
| 98 |
+
-v \
|
| 99 |
+
--port 8080 \
|
| 100 |
+
--host 0.0.0.0 \
|
| 101 |
+
--no-webui
|
| 102 |
+
nblはgpu環境でgpuメモリに収まる範囲で指定
|
| 103 |
+
faはフラッシュアテンション有りでコンパイルした時のみ利用
|
| 104 |
+
|
| 105 |
+
# Macでメタル(GPU)を使用する場合
|
| 106 |
+
./llama-server \
|
| 107 |
+
-m path/to/VoiceCore-BF16.gguf \
|
| 108 |
+
--prio 3 \
|
| 109 |
+
-c 2048 \
|
| 110 |
+
-e \
|
| 111 |
+
-n -2 \
|
| 112 |
+
-fa \
|
| 113 |
+
-ngl 1 \ # Macの場合は1を推奨
|
| 114 |
+
-v \
|
| 115 |
+
--port 8080 \
|
| 116 |
+
--host 0.0.0.0 \
|
| 117 |
+
--no-webui
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### 5. 音声生成の実行
|
| 121 |
+
|
| 122 |
+
シンプルなサンプルスクリプト(simple_voice.py):
|
| 123 |
+
|
| 124 |
+
```python
|
| 125 |
+
import asyncio
|
| 126 |
+
import httpx
|
| 127 |
+
import json
|
| 128 |
+
import re
|
| 129 |
+
import torch
|
| 130 |
+
from snac import SNAC
|
| 131 |
+
import scipy.io.wavfile as wavfile
|
| 132 |
+
import numpy as np
|
| 133 |
+
|
| 134 |
+
async def generate_voice(prompt, output_file="output.wav"):
|
| 135 |
+
"""シンプルな音声生成関数"""
|
| 136 |
+
|
| 137 |
+
# SNACモデルの読み込み
|
| 138 |
+
print("SNACモデルを読み込んでいます...")
|
| 139 |
+
snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz")
|
| 140 |
+
snac_model.to("cpu")
|
| 141 |
+
|
| 142 |
+
# サーバーにリクエスト送信
|
| 143 |
+
payload = {
|
| 144 |
+
"prompt": prompt,
|
| 145 |
+
"temperature": 0.8,
|
| 146 |
+
"top_p": 0.95,
|
| 147 |
+
"n_predict": 2048
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
collected_tokens = []
|
| 151 |
+
|
| 152 |
+
async with httpx.AsyncClient(timeout=None) as client:
|
| 153 |
+
response = await client.post(
|
| 154 |
+
"http://localhost:8080/completion",
|
| 155 |
+
json=payload,
|
| 156 |
+
headers={"Accept": "application/x-ndjson"}
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
# トークンの収集
|
| 160 |
+
async for line in response.aiter_text():
|
| 161 |
+
if line.strip():
|
| 162 |
+
try:
|
| 163 |
+
data = json.loads(line)
|
| 164 |
+
if "content" in data:
|
| 165 |
+
matches = re.findall(r'<custom_token_(\d+)>', data["content"])
|
| 166 |
+
for match in matches:
|
| 167 |
+
token_id = 128256 + int(match)
|
| 168 |
+
collected_tokens.append(token_id)
|
| 169 |
+
except:
|
| 170 |
+
pass
|
| 171 |
+
|
| 172 |
+
# 音声の生成
|
| 173 |
+
if collected_tokens:
|
| 174 |
+
# 7の倍数に調整
|
| 175 |
+
code_length = (len(collected_tokens) // 7) * 7
|
| 176 |
+
tokens = collected_tokens[:code_length]
|
| 177 |
+
|
| 178 |
+
# コードの再分配
|
| 179 |
+
codes = redistribute_codes(tokens)
|
| 180 |
+
|
| 181 |
+
# 音声デコード
|
| 182 |
+
with torch.inference_mode():
|
| 183 |
+
audio_hat = snac_model.decode(codes)
|
| 184 |
+
|
| 185 |
+
audio_np = audio_hat.detach().squeeze().cpu().numpy()
|
| 186 |
+
|
| 187 |
+
# WAVファイルとして保存
|
| 188 |
+
wavfile.write(output_file, 24000, audio_np)
|
| 189 |
+
print(f"音声を {output_file} に保存しました。")
|
| 190 |
+
|
| 191 |
+
def redistribute_codes(tokens):
|
| 192 |
+
"""トークンをSNACコード形式に変換"""
|
| 193 |
+
code_list = [t - 128266 for t in tokens]
|
| 194 |
+
|
| 195 |
+
layer_1, layer_2, layer_3 = [], [], []
|
| 196 |
+
|
| 197 |
+
for i in range(len(code_list) // 7):
|
| 198 |
+
layer_1.append(code_list[7*i])
|
| 199 |
+
layer_2.append(code_list[7*i+1]-4096)
|
| 200 |
+
layer_3.append(code_list[7*i+2]-(2*4096))
|
| 201 |
+
layer_3.append(code_list[7*i+3]-(3*4096))
|
| 202 |
+
layer_2.append(code_list[7*i+4]-(4*4096))
|
| 203 |
+
layer_3.append(code_list[7*i+5]-(5*4096))
|
| 204 |
+
layer_3.append(code_list[7*i+6]-(6*4096))
|
| 205 |
+
|
| 206 |
+
return [
|
| 207 |
+
torch.tensor(layer_1).unsqueeze(0),
|
| 208 |
+
torch.tensor(layer_2).unsqueeze(0),
|
| 209 |
+
torch.tensor(layer_3).unsqueeze(0)
|
| 210 |
+
]
|
| 211 |
+
|
| 212 |
+
# 使用例
|
| 213 |
+
async def main():
|
| 214 |
+
# 松風さんの声で挨拶
|
| 215 |
+
prompt = "<custom_token_3><|begin_of_text|>matsukaze_male[neutral]: こんにちは!よろしくお願いします!<|eot_id|><custom_token_4><custom_token_5><custom_token_1>"
|
| 216 |
+
await generate_voice(prompt, "greeting.wav")
|
| 217 |
+
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
asyncio.run(main())
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
## その他のツールでの利用方法
|
| 223 |
+
|
| 224 |
+
### Ollama
|
| 225 |
+
[Ollama](https://ollama.ai/)は、大規模言語モデルをローカルで簡単に実行できるツールです。
|
| 226 |
+
|
| 227 |
+
**特徴:**
|
| 228 |
+
- ワンコマンドでモデルの実行が可能
|
| 229 |
+
- Docker風のシンプルなインターフェース
|
| 230 |
+
- 自動的な量子化対応
|
| 231 |
+
|
| 232 |
+
**注意:** 現時点でOllamaはカスタムトークナイザーに対応していないため、VoiceCoreの音声生成機能は制限される可能性があります。
|
| 233 |
+
|
| 234 |
+
### LM Studio
|
| 235 |
+
[LM Studio](https://lmstudio.ai/)は、GUIベースでLLMを実行できるツールです。
|
| 236 |
+
|
| 237 |
+
**特徴:**
|
| 238 |
+
- 直感的なGUIインターフェース
|
| 239 |
+
- モデルの自動ダウンロード機能
|
| 240 |
+
- チャット履歴の管理
|
| 241 |
+
|
| 242 |
+
**使用方法:**
|
| 243 |
+
1. LM Studioをダウンロード・インストール
|
| 244 |
+
2. モデルファイル(.gguf)をインポート
|
| 245 |
+
3. 設定でコンテキストサイズを2048に設定
|
| 246 |
+
4. APIサーバーモードで起動
|
| 247 |
+
|
| 248 |
+
### llama.cpp Python バインディング
|
| 249 |
+
```bash
|
| 250 |
+
pip install llama-cpp-python
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
Pythonから直接モデルを使用できます。詳細は[公式ドキュメント](https://github.com/abetlen/llama-cpp-python)を参照してください。
|
| 254 |
+
|
| 255 |
+
## トラブルシューティング
|
| 256 |
+
|
| 257 |
+
### よくある問題と解決方法
|
| 258 |
+
|
| 259 |
+
1. **音声生成に失敗する**
|
| 260 |
+
- Q4_K量子化版を使用している場合は、BF16版に切り替えてください
|
| 261 |
+
- メモリ不足の場合は、コンテキストサイズを小さくしてください
|
| 262 |
+
|
| 263 |
+
2. **サーバーが起動しない**
|
| 264 |
+
- ポート8080が使用中でないか確認してください
|
| 265 |
+
- モデルファイルのパスが正しいか確認してください
|
| 266 |
+
|
| 267 |
+
3. **生成速度が遅い**
|
| 268 |
+
- CPU環境での推論実行は時間がかかります。[webbigdata/VoiceCore](https://huggingface.co/webbigdata/VoiceCore)のサンプルColabスクリプトの利用も検討してください
|
| 269 |
+
- GPU(Metal)を有効にしているか確認してください
|
| 270 |
+
- `-ngl`パラメータを調整してください
|
| 271 |
+
|
| 272 |
+
## ライセンス
|
| 273 |
+
|
| 274 |
+
- モデル: [LLAMA 3.2 COMMUNITY LICENSE](https://huggingface.co/meta-llama/Llama-3.2-1B/blob/main/LICENSE.txt)または[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 275 |
+
- 音声データ: 各音声提供者のライセンスに従ってください([元モデルのライセンス情報](https://huggingface.co/webbigdata/VoiceCore#ディフォルト利用可能な音声の提供元とそのライセンス-default-voice-providers-and-their-licenses)を参照)
|
| 276 |
+
|
| 277 |
+
## 謝辞
|
| 278 |
+
|
| 279 |
+
- オリジナルモデル: [webbigdata/VoiceCore](https://huggingface.co/webbigdata/VoiceCore)
|
| 280 |
+
- ベースモデル: [canopylabs/orpheus-tts](https://huggingface.co/collections/canopylabs/orpheus-tts-67d9ea3f6c05a941c06ad9d2)
|