Views
No views yet
z.1conda create -n losatok python=3.10 -y
2conda activate losatok1git clone https://github.com/wxzyd123/LoSATok.git
2cd LoSATok
3
4pip install torch==2.8.0 torchaudio==2.8.0
5pip install -r requirements.txt
6
7sudo apt install ffmpeg| File | Description |
|---|---|
ckpts/semantic_encoder.pth | Frozen MiDashengLM semantic encoder + pretrained Semantic Bottleneck checkpoint. |
ckpts/losatok_kl1e-3.pth or ckpts/losatok_kl1e-2.pth | LoSATok checkpoint. kl1e-3 and kl1e-2 correspond to different KL clamp strengths. |
ckpts/ directory so that the layout looks like:1python infer.py \
2 --config_path config/16k_16k_25Hz_losatok.yml \
3 --model_path ckpts/losatok_kl1e-2.pth \
4 --input_path example/en.wav \
5 --output_path example/recon.wav \
6 --save_features example/en_features.pt| Argument | Description |
|---|---|
--config_path | YAML config that defines the AudioVAE skeleton. Default: config/16k_16k_25Hz_losatok.yml. |
--model_path | Trained LoSATok checkpoint (*.pth). If omitted, an untrained model is built (debug only). |
--input_path | Input wav path. |
--output_path | Reconstructed wav path. |
--device | cuda (default) or cpu. |
--sample | If set, use the reparameterized z = mu + eps * std instead of the deterministic mu. |
--max_duration | Optional float, clip the input to the first N seconds (avoids OOM on long files). |
--save_features | Optional .pt path to also dump the full encoded feature dict. |
1[LoSATok] Encoded feature shapes:
2 z (1, T_token, 128)
3 mu (1, T_token, 128)
4 logvar (1, T_token, 128)
5 semantic_emb (1, T_token, 1280)
6 acoustic_emb (1, T_token, 1280)
7 unified_emb (1, T_token, 1280)
8 semantic_emb_low (1, T_token, 128)
9 acoustic_emb_low (1, T_token, 128)
10 unified_emb_low (1, T_token, 128)1import librosa, torch
2from infer import load_losatok, encode, decode
3
4model = load_losatok(
5 config_path="config/16k_16k_25Hz_losatok.yml",
6 model_path="ckpts/losatok_kl1e-3.pth",
7 device="cuda",
8)
9
10wav, sr = librosa.load("example/en.wav", sr=model.sample_rate, mono=True)
11audio = torch.from_numpy(wav).unsqueeze(0)
12
13# ---- Encode: waveform -> LoSATok tokens ----
14features = encode(model, audio)
15
16z = features["z"] # (B, T_token, 128) <- LoSATok tokens
17mu = features["mu"] # (B, T_token, 128)
18logvar = features["logvar"] # (B, T_token, 128)
19semantic_emb = features["semantic_emb"] # (B, T_token, 1280)
20acoustic_emb = features["acoustic_emb"] # (B, T_token, 1280)
21unified_emb = features["unified_emb"] # (B, T_token, 1280)
22semantic_emb_low = features["semantic_emb_low"] # (B, T_token, 128)
23acoustic_emb_low = features["acoustic_emb_low"] # (B, T_token, 128)
24unified_emb_low = features["unified_emb_low"] # (B, T_token, 128)
25
26# ---- Decode: LoSATok tokens -> waveform ----
27audio_recon = decode(model, z)z is the 128-dim continuous LoSATok token, typically fed to downstream models
(LLMs, DiTs, etc.).