salmon-fish
Built with Fish Audio
以簡潔 Python API 使用 Fish Audio S2-Pro 真實權重,支援文字轉語音、參考語音 ICL、 可檢查的 prompt packing 與 WAV 輸出。復用官方模型層、KV cache、採樣器與 DAC codec, 不需要 SGLang 或常駐服務。
教學核心集中在 ar.py:公開的 decode_one_token_ar() 保持官方
單幀解碼行為,並可透過 on_event 觀察 fusion、slow logits/條件 hidden、semantic/RAS
採樣、fast prefill、各 codebook 的 logits/probs/token,以及完整 frame。
詳見 Dual-AR 逐步教學與等價性驗證。
套件名稱:salmon-fish;Python import:salmon_fish。目前為發布前版本,尚未上傳 PyPI。
安裝
Python 3.11–3.13。從本地原始碼以標準 pip 安裝:
python -m pip install .
正式發布後的安裝名稱為 pip install salmon-fish。本專案固定配對的 Torch/torchaudio
2.11.0;已有相同版本(包含相符的 CUDA build)可直接重用。需要選擇 CUDA runtime 時,
先依 PyTorch 官方方式 安裝對應的兩個套件,再安裝本套件。
本地開發的 uv sync --locked 預設沿用 CUDA 13.0 wheel 索引;pip 安裝不依賴 uv 設定。
最小 Python API
from salmon_fish import S2Pro
tts = S2Pro.from_pretrained() # 自動下載 fishaudio/s2-pro,之後重用快取
result = tts.infer("你好,歡迎使用語音合成。", "output.wav")
print(result.sample_rate, result.codes.shape, result.finish_reason)
觀察中間狀態只需加入回呼;一般推論與教學觀察使用同一份核心流程:
def inspect(event):
if event.frame_index == 0:
print(event.stage, event.codebook_index,
{name: tuple(t.shape) for name, t in event.tensors.items()})
tts.infer("你好。", "teaching.wav", on_event=inspect)
回呼收到獨立 CPU tensor 快照;預設不收集。也可從 salmon_fish 直接匯入
decode_one_token_ar 與 DecodeEvent,逐幀操作:
uv run python examples/inspect_ar.py --model ./checkpoints/s2-pro --frames 2
首次使用下載約 11 GB。預設使用固定 revision
1de9996b6be38b745688de084d87a5633f714e4e;權重、tokenizer、codec 與模型 license
由 Hugging Face 官方 API 取得,不包含在 Python 發布檔或 GitHub 原始碼中。
只有 from_pretrained()/download_model() 會觸發模型資產下載;一般 import 與 CLI help 不會。
from salmon_fish import download_model, S2Pro
checkpoint = download_model(cache_dir="/path/to/model-cache") # 可選:預先下載
# 也可直接傳 cache_dir 給 from_pretrained(),自動下載並載入。
tts = S2Pro.from_pretrained(cache_dir="/path/to/model-cache", local_files_only=True)
# 已有獨立 checkpoint 目錄:S2Pro.from_pretrained("./checkpoints/s2-pro")
不指定 cache_dir 時沿用 Hugging Face 的 HF_HOME/HF_HUB_CACHE;離線使用
local_files_only=True。需要驗證身分時使用標準 HF_TOKEN/hf auth login,程式不保存金鑰。
下載行為遵循 Hugging Face snapshot cache API。
ICL:參考語音 → 新語音
from salmon_fish import S2Pro
tts = S2Pro.from_pretrained()
reference = tts.encode_reference(
audio_path="reference.wav",
transcript="這裡必須是參考語音實際說出的文字。",
)
new_text = "這是希望使用參考聲音生成的新句子。"
prompt = tts.pack_prompt(new_text, reference=reference) # [11, prompt_length]
result = tts.infer(new_text, "new.wav", reference=reference)
reference 可重用多次。ICL 不更新模型權重,也不自動辨識逐字稿。
pack_prompt() 保留完整格式與矩陣布局的程式註解:
system: 參考逐字稿 + VQPart(參考音訊 codes)
user: 要生成的新文字
assistant: <|voice|>,保持未結束狀態,從此生成新音訊
每個參考音訊 frame 佔一欄:第 0 列是 semantic_begin_id + codes[0],第 1~10 列
是 10 個 codebook;純文字欄位的第 1~10 列為零。官方 token fusion 直接處理此矩陣。
輸出 WAV 只包含新生成的語音,不接上參考錄音。
CLI
salmon-fish infer '你好,歡迎使用語音合成。' --output hello.wav
salmon-fish infer '新しい日本語の文章です。' --output new.wav \
--reference-audio reference.wav --reference-text '参照音声の正確な文字起こしです。'
salmon-fish download # 下載至標準 HF cache
salmon-fish download --local-dir checkpoints/s2-pro
salmon-fish infer '離線測試。' --model ./checkpoints/s2-pro --offline
python -m salmon_fish --help
CLI 可指定 --cache-dir、--revision、--device、context 長度與 sampling 參數。
舊版 from s2_pro import S2Pro 仍提供相容匯入;新程式請使用 salmon_fish。
原始碼目錄中的 main.py 也保留為舊 CLI 啟動器。
結構與開發
src/salmon_fish/
__init__.py 公開 API,延遲匯入模型
pipeline.py S2Pro、ICL、prompt packing、雙層 AR、WAV
ar.py 單幀雙 AR 教學核心與 DecodeEvent 觀察介面
types.py SpeechReference/SpeechOutput
hub.py 自動下載、cache、本地與離線解析
_loading.py 實際權重與 codec 載入、架構/參數驗證
cli.py infer/download
_vendor/fish_speech/ 固定上游 commit 的官方推論元件,隔離命名空間
examples/ 基本、通用 ICL、日語語料範例
scripts/check_dist.py 發布檔內容驗證
tests/ 單元測試與真實權重整合驗證
.github/workflows/ Python 3.11–3.13 CI 與手動發布工作流程
uv sync --locked
uv run ruff check src tests examples scripts main.py
uv run python -m unittest discover -s tests -v
uv run python tests/smoke_checkpoint.py --model checkpoints/s2-pro # 可選,需要 GPU/權重
uv run python examples/icl_japanese.py --model checkpoints/s2-pro # 可選,需要本地 data/
data/、checkpoints/、outputs/ 與本地憑證已排除 Git 與發布檔;語料範例需要自行準備資料。
CI 只下載 tokenizer,使用 CPU 測試,不下載 11 GB 模型。
授權
自行撰寫的整合程式碼採 MIT。ar.py 的官方單步流程改編及內附官方程式碼保留
Fish Audio Community License;此部分僅調整 Python import
與 Hydra target 的命名空間,模型計算保持不變。整體發布檔的 license expression 為
MIT AND LicenseRef-Fish-Audio-Community。
S2-Pro 權重另依模型庫的 Fish Audio Research License 授權;自動下載不變更其授權。MIT 不涵蓋官方程式碼或模型權重。
Metadata
Release files for salmon-fish 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| salmon_fish-0.1.0.tar.gz | 249.1 kB | Without provenance | Details for salmon_fish-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| salmon_fish-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for salmon_fish-0.1.0-py3-none-any.whl |
Total release size: 355.2 kB
Release files / salmon_fish-0.1.0.tar.gz
| Download URL | salmon_fish-0.1.0.tar.gz |
|---|---|
| Size | 249.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2df7ba09d7777ed2e456723699f44c3ee746a91109bcb6ecef5341f89aa912f3
|
|
BLAKE2b-256 checksum How to use checksums |
cbebd6b1902dce4b80afd372ec6740b193ed0b0c52af15b2d8b2e08d774f305c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / salmon_fish-0.1.0-py3-none-any.whl
| Download URL | salmon_fish-0.1.0-py3-none-any.whl |
|---|---|
| Size | 106.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb19e0c1e7d65aa233e0da165749ad29724998ea59a1a905229491f1b12d3fc6
|
|
BLAKE2b-256 checksum How to use checksums |
3c0c2c7f5a2fec699f7cffddf278d02c803f65d91ff69a498e037b92be93f703
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Security for salmon-fish 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.