Views
No views yet
📖 For more information, see the TinyWave paper (arXiv:2506.23670) and project website.
1git clone https://github.com/facebookresearch/spiritlm
2cd spiritlm
3pip install -e '.[eval]'1from spiritlm.speech_tokenizer import spiritlm_expressive
2speech_tokenizer = spiritlm_expressive()1from transformers import LlamaForCausalLM, AutoTokenizer
2import torchaudio
3import torch
4
5# Load model and tokenizer
6MODEL_PATH = "tinywave/interleaved-expressive-2b-v2"
7tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
8model = LlamaForCausalLM.from_pretrained(MODEL_PATH, device_map="auto", torch_dtype=torch.bfloat16)
9
10# Audio + Speech tokenizer
11speech_tokenizer = spiritlm_expressive()
12
13def get_inference(input_audio_path):
14 audio, _ = torchaudio.load(input_audio_path)
15 input_values = audio.view(1, 1, -1).to(speech_tokenizer.hubert_model.device).float()
16 string_tokens = speech_tokenizer.encode_string(input_values)
17 input_ids = tokenizer(string_tokens, return_tensors="pt").input_ids.to(model.device)
18 output = model.generate(input_ids, max_new_tokens=256, top_p=0.9, temperature=0.9, do_sample=True)
19 return tokenizer.decode(output[0])
20
21# Text-based prompt
22def get_inference_text(prompt):
23 input_ids = tokenizer(prompt + " [Speech]", return_tensors="pt").input_ids.to(model.device)
24 output = model.generate(input_ids, max_new_tokens=256, top_p=0.9, temperature=0.9, do_sample=True)
25 return tokenizer.decode(output[0])1import numpy as np
2from scipy.io.wavfile import write
3
4def save_array_to_wav_int16(audio_array: np.ndarray, sampling_rate=16000, filename="output.wav"):
5 scaled = np.int16(audio_array / np.max(np.abs(audio_array)) * 32767)
6 write(filename, sampling_rate, scaled)
7
8decoded_audio = speech_tokenizer.decode(output_text.replace(" ", "").replace("<s>", "").replace("</s>", ""), speaker_id=2)
9save_array_to_wav_int16(decoded_audio, filename="generated.wav")speech.wav (spoken sentence)
Output: Expressive speech continuation in the same style and tone."Once upon a time in a small village, a mysterious sound echoed through the forest. [Speech]"| Feature | Description |
|---|---|
| Architecture | 2B parameter distilled transformer |
| Tokenizer | SPIRIT-LM Expressive (HuBERT + pitch/style) |
| Tasks | Speech continuation, mixed speech-text generation |
| Teacher Model | SPIRIT-LM-Expressive 7B |
| Distillation Method | Layer-aligned: hidden states, attention, logits |
| Input Types | Discrete HuBERT tokens and text |
1@article{nouriborji2025tinywave,
2 title={Efficient Interleaved Speech Modeling through Knowledge Distillation},
3 author={Nouriborji, Mohammadmahdi and Rohanian, Morteza},
4 journal={arXiv preprint arXiv:2506.23670},
5 year={2025}
6}