FIsh / docs /ko /inference.md
samarth2002's picture
files added
5fc76ef
|
raw
history blame
6.13 kB
# μΆ”λ‘ 
좔둠은 λͺ…령쀄, HTTP API, 그리고 μ›Ή UIμ—μ„œ μ§€μ›λ©λ‹ˆλ‹€.
!!! note
전체 μΆ”λ‘  과정은 λ‹€μŒμ˜ μ—¬λŸ¬ λ‹¨κ³„λ‘œ κ΅¬μ„±λ©λ‹ˆλ‹€:
1. VQGAN을 μ‚¬μš©ν•˜μ—¬ μ•½ 10초 λΆ„λŸ‰μ˜ μŒμ„±μ„ μΈμ½”λ”©ν•©λ‹ˆλ‹€.
2. μΈμ½”λ”©λœ μ‹œλ§¨ν‹± 토큰과 ν•΄λ‹Ή ν…μŠ€νŠΈλ₯Ό μ˜ˆμ‹œλ‘œ μ–Έμ–΄ λͺ¨λΈμ— μž…λ ₯ν•©λ‹ˆλ‹€.
3. μƒˆλ‘œμš΄ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄, λͺ¨λΈμ΄ ν•΄λ‹Ήν•˜λŠ” μ‹œλ§¨ν‹± 토큰을 μƒμ„±ν•©λ‹ˆλ‹€.
4. μƒμ„±λœ μ‹œλ§¨ν‹± 토큰을 VITS / VQGAN에 μž…λ ₯ν•˜μ—¬ μŒμ„±μ„ λ””μ½”λ”©ν•˜κ³  μƒμ„±ν•©λ‹ˆλ‹€.
## λͺ¨λΈ λ‹€μš΄λ‘œλ“œ
ν•„μš”ν•œ `vqgan` 및 `llama` λͺ¨λΈμ„ Hugging Face λ¦¬ν¬μ§€ν† λ¦¬μ—μ„œ λ‹€μš΄λ‘œλ“œν•˜μ„Έμš”.
```bash
huggingface-cli download fishaudio/fish-speech-1.5 --local-dir checkpoints/fish-speech-1.5
```
## λͺ…령쀄 μΆ”λ‘ 
### 1. μŒμ„±μ—μ„œ ν”„λ‘¬ν”„νŠΈ 생성:
!!! note
λͺ¨λΈμ΄ μŒμƒ‰μ„ λ¬΄μž‘μœ„λ‘œ μ„ νƒν•˜λ„λ‘ ν•˜λ €λ©΄ 이 단계λ₯Ό κ±΄λ„ˆλ›Έ 수 μžˆμŠ΅λ‹ˆλ‹€.
!!! warning "ν–₯ν›„ 버전 κ²½κ³ "
μ›λž˜ 경둜(tools/vqgan/infernce.py)μ—μ„œ μ ‘κ·Όν•  수 μžˆλŠ” μΈν„°νŽ˜μ΄μŠ€λŠ” μœ μ§€ν–ˆμ§€λ§Œ, 이 μΈν„°νŽ˜μ΄μŠ€λŠ” ν–₯ν›„ λͺ‡λͺ‡ λ²„μ „μ—μ„œ μ‚­μ œλ  수 μžˆμŠ΅λ‹ˆλ‹€. κ°€λŠ₯ν•œ ν•œ 빨리 μ½”λ“œλ₯Ό λ³€κ²½ν•˜μ‹­μ‹œμ˜€.
```bash
python fish_speech/models/vqgan/inference.py \
-i "paimon.wav" \
--checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth"
```
이 λͺ…령을 μ‹€ν–‰ν•˜λ©΄ `fake.npy` νŒŒμΌμ„ μ–»κ²Œ λ©λ‹ˆλ‹€.
### 2. ν…μŠ€νŠΈμ—μ„œ μ‹œλ§¨ν‹± 토큰 생성:
!!! warning "ν–₯ν›„ 버전 κ²½κ³ "
μ›λž˜ 경둜(tools/llama/generate.py)μ—μ„œ μ ‘κ·Όν•  수 μžˆλŠ” μΈν„°νŽ˜μ΄μŠ€λŠ” μœ μ§€ν–ˆμ§€λ§Œ, 이 μΈν„°νŽ˜μ΄μŠ€λŠ” ν–₯ν›„ λͺ‡λͺ‡ λ²„μ „μ—μ„œ μ‚­μ œλ  수 μžˆμŠ΅λ‹ˆλ‹€. κ°€λŠ₯ν•œ ν•œ 빨리 μ½”λ“œλ₯Ό λ³€κ²½ν•˜μ‹­μ‹œμ˜€.
```bash
python fish_speech/models/text2semantic/inference.py \
--text "λ³€ν™˜ν•  ν…μŠ€νŠΈ" \
--prompt-text "μ°Έκ³ ν•  ν…μŠ€νŠΈ" \
--prompt-tokens "fake.npy" \
--checkpoint-path "checkpoints/fish-speech-1.5" \
--num-samples 2 \
--compile
```
이 λͺ…령을 μ‹€ν–‰ν•˜λ©΄ μž‘μ—… 디렉토리에 `codes_N` 파일이 μƒμ„±λ˜λ©°, N은 0λΆ€ν„° μ‹œμž‘ν•˜λŠ” μ •μˆ˜μž…λ‹ˆλ‹€.
!!! note
λΉ λ₯Έ 좔둠을 μœ„ν•΄ `--compile` μ˜΅μ…˜μ„ μ‚¬μš©ν•˜μ—¬ CUDA 컀널을 κ²°ν•©ν•  수 μžˆμŠ΅λ‹ˆλ‹€ (~μ΄ˆλ‹Ή 30 토큰 -> ~μ΄ˆλ‹Ή 500 토큰).
`--compile` λ§€κ°œλ³€μˆ˜λ₯Ό 주석 μ²˜λ¦¬ν•˜μ—¬ 가속화 μ˜΅μ…˜μ„ μ‚¬μš©ν•˜μ§€ μ•Šμ„ μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.
!!! info
bf16을 μ§€μ›ν•˜μ§€ μ•ŠλŠ” GPU의 경우 `--half` λ§€κ°œλ³€μˆ˜λ₯Ό μ‚¬μš©ν•΄μ•Ό ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
### 3. μ‹œλ§¨ν‹± ν† ν°μ—μ„œ μŒμ„± 생성:
#### VQGAN 디코더
!!! warning "ν–₯ν›„ 버전 κ²½κ³ "
μ›λž˜ 경둜(tools/vqgan/infernce.py)μ—μ„œ μ ‘κ·Όν•  수 μžˆλŠ” μΈν„°νŽ˜μ΄μŠ€λŠ” μœ μ§€ν–ˆμ§€λ§Œ, 이 μΈν„°νŽ˜μ΄μŠ€λŠ” ν–₯ν›„ λͺ‡λͺ‡ λ²„μ „μ—μ„œ μ‚­μ œλ  수 μžˆμŠ΅λ‹ˆλ‹€. κ°€λŠ₯ν•œ ν•œ 빨리 μ½”λ“œλ₯Ό λ³€κ²½ν•˜μ‹­μ‹œμ˜€.
```bash
python fish_speech/models/vqgan/inference.py \
-i "codes_0.npy" \
--checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth"
```
## HTTP API μΆ”λ‘ 
좔둠을 μœ„ν•œ HTTP APIλ₯Ό μ œκ³΅ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. μ•„λž˜μ˜ λͺ…λ Ήμ–΄λ‘œ μ„œλ²„λ₯Ό μ‹œμž‘ν•  수 μžˆμŠ΅λ‹ˆλ‹€:
```bash
python -m tools.api_server \
--listen 0.0.0.0:8080 \
--llama-checkpoint-path "checkpoints/fish-speech-1.5" \
--decoder-checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth" \
--decoder-config-name firefly_gan_vq
```
μΆ”λ‘  속도λ₯Ό 높이고 μ‹Άλ‹€λ©΄ `--compile` λ§€κ°œλ³€μˆ˜λ₯Ό μΆ”κ°€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
이후, http://127.0.0.1:8080/ μ—μ„œ APIλ₯Ό ν™•μΈν•˜κ³  ν…ŒμŠ€νŠΈν•  수 μžˆμŠ΅λ‹ˆλ‹€.
μ•„λž˜λŠ” `tools/api_client.py`λ₯Ό μ‚¬μš©ν•˜μ—¬ μš”μ²­μ„ λ³΄λ‚΄λŠ” μ˜ˆμ‹œμž…λ‹ˆλ‹€.
```bash
python -m tools.api_client \
--text "μž…λ ₯ν•  ν…μŠ€νŠΈ" \
--reference_audio "μ°Έκ³  μŒμ„± 경둜" \
--reference_text "μ°Έκ³  μŒμ„±μ˜ ν…μŠ€νŠΈ λ‚΄μš©" \
--streaming True
```
μœ„ λͺ…령은 μ°Έκ³  μŒμ„± 정보λ₯Ό λ°”νƒ•μœΌλ‘œ μ›ν•˜λŠ” μŒμ„±μ„ ν•©μ„±ν•˜κ³ , 슀트리밍 λ°©μ‹μœΌλ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€.
λ‹€μŒ μ˜ˆμ‹œλŠ” μ—¬λŸ¬ 개의 μ°Έκ³  μŒμ„± κ²½λ‘œμ™€ ν…μŠ€νŠΈλ₯Ό ν•œκΊΌλ²ˆμ— μ‚¬μš©ν•  수 μžˆμŒμ„ λ³΄μ—¬μ€λ‹ˆλ‹€. λͺ…λ Ήμ—μ„œ 곡백으둜 κ΅¬λΆ„ν•˜μ—¬ μž…λ ₯ν•©λ‹ˆλ‹€.
```bash
python -m tools.api_client \
--text "μž…λ ₯ν•  ν…μŠ€νŠΈ" \
--reference_audio "μ°Έκ³  μŒμ„± 경둜1" "μ°Έκ³  μŒμ„± 경둜2" \
--reference_text "μ°Έκ³  μŒμ„± ν…μŠ€νŠΈ1" "μ°Έκ³  μŒμ„± ν…μŠ€νŠΈ2"\
--streaming False \
--output "generated" \
--format "mp3"
```
μœ„ λͺ…λ Ήμ–΄λŠ” μ—¬λŸ¬ μ°Έκ³  μŒμ„± 정보λ₯Ό λ°”νƒ•μœΌλ‘œ `MP3` ν˜•μ‹μ˜ μŒμ„±μ„ ν•©μ„±ν•˜μ—¬, ν˜„μž¬ 디렉토리에 `generated.mp3`둜 μ €μž₯ν•©λ‹ˆλ‹€.
`--reference_audio`와 `--reference_text` λŒ€μ‹ μ— `--reference_id`(ν•˜λ‚˜λ§Œ μ‚¬μš© κ°€λŠ₯)λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. ν”„λ‘œμ νŠΈ 루트 디렉토리에 `references/<your reference_id>` 폴더λ₯Ό λ§Œλ“€μ–΄ ν•΄λ‹Ή μŒμ„±κ³Ό 주석 ν…μŠ€νŠΈλ₯Ό λ„£μ–΄μ•Ό ν•©λ‹ˆλ‹€. μ°Έκ³  μŒμ„±μ€ μ΅œλŒ€ 90μ΄ˆκΉŒμ§€ μ§€μ›λ©λ‹ˆλ‹€.
!!! info
μ œκ³΅λ˜λŠ” νŒŒλΌλ―Έν„°λŠ” `python -m tools.api_client -h`λ₯Ό μ‚¬μš©ν•˜μ—¬ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.
## GUI μΆ”λ‘ 
[ν΄λΌμ΄μ–ΈνŠΈ λ‹€μš΄λ‘œλ“œ](https://github.com/AnyaCoder/fish-speech-gui/releases)
## WebUI μΆ”λ‘ 
λ‹€μŒ λͺ…λ ΉμœΌλ‘œ WebUIλ₯Ό μ‹œμž‘ν•  수 μžˆμŠ΅λ‹ˆλ‹€:
```bash
python -m tools.run_webui \
--llama-checkpoint-path "checkpoints/fish-speech-1.5" \
--decoder-checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth" \
--decoder-config-name firefly_gan_vq
```
> μΆ”λ‘  속도λ₯Ό 높이고 μ‹Άλ‹€λ©΄ `--compile` λ§€κ°œλ³€μˆ˜λ₯Ό μΆ”κ°€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
!!! note
라벨 파일과 μ°Έκ³  μŒμ„± νŒŒμΌμ„ 미리 메인 λ””λ ‰ν† λ¦¬μ˜ `references` 폴더에 μ €μž₯ν•΄ 두면, WebUIμ—μ„œ λ°”λ‘œ ν˜ΈμΆœν•  수 μžˆμŠ΅λ‹ˆλ‹€. (ν•΄λ‹Ή ν΄λ”λŠ” 직접 생성해야 ν•©λ‹ˆλ‹€.)
!!! note
WebUIλ₯Ό κ΅¬μ„±ν•˜κΈ° μœ„ν•΄ `GRADIO_SHARE`, `GRADIO_SERVER_PORT`, `GRADIO_SERVER_NAME`κ³Ό 같은 Gradio ν™˜κ²½ λ³€μˆ˜λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
μ¦κΈ°μ„Έμš”!