Views
No views yet

| Model | Context Length | Generation Length | Weight |
|---|---|---|---|
| VibeVoice-1.5B | 64K | ~90 min | This model |
| VibeVoice-7B | 32K | ~45 min | HF link |
| VibeVoice-0.5B-Streaming | - | - | On the way |
1pip install git+https://github.com/pengzhiliang/transformers.git
2pip install torch torchvision torchaudio
3pip install diffusers librosa accelerate1from transformers import AutoProcessor, VibeVoiceForConditionalGeneration
2
3repo_id = "microsoft/VibeVoice-1.5B-hf"
4processor = AutoProcessor.from_pretrained(repo_id)
5model = VibeVoiceForConditionalGeneration.from_pretrained(repo_id)1import time
2import diffusers
3import numpy as np
4import torch
5from tqdm import tqdm
6
7from transformers import AutoProcessor, VibeVoiceForConditionalGeneration
8from transformers.audio_utils import load_audio_librosa
9
10
11repo_id = "microsoft/VibeVoice-1.5B-hf"
12sampling_rate = 24000
13max_new_tokens = 512 # set to None for full generation
14cfg_scale = 1.3 # classifier-free guidance for diffusion process
15
16# set seed for deterministic
17seed = 42
18torch.manual_seed(seed)
19np.random.seed(seed)
20
21# create conversation with an audio for the first time a speaker appears to clone that particular voice
22conversation = [
23 {"role": "0", "content": [
24 {"type": "text", "text": "Hello everyone, and welcome to the VibeVoice podcast. I'm your host, Linda, and today we're getting into one of the biggest debates in all of sports: who's the greatest basketball player of all time? I'm so excited to have Thomas here to talk about it with me."},
25 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav", sampling_rate=sampling_rate)}
26 ]},
27 {"role": "1", "content": [
28 {"type": "text", "text": "Thanks so much for having me, Linda. You're absolutely right—this question always brings out some seriously strong feelings."},
29 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Frank_man.wav", sampling_rate=sampling_rate)}
30 ]},
31 {"role": "0", "content": [
32 {"type": "text", "text": "Okay, so let's get right into it. For me, it has to be Michael Jordan. Six trips to the Finals, six championships. That kind of perfection is just incredible."},
33 ]},
34 {"role": "1", "content": [
35 {"type": "text", "text": "Oh man, the first thing that always pops into my head is that shot against the Cleveland Cavaliers back in '89. Jordan just rises, hangs in the air forever, and just sinks it"},
36 ]},
37]
38
39# load model
40device = "cuda" if torch.cuda.is_available() else "cpu"
41processor = AutoProcessor.from_pretrained(repo_id)
42model = VibeVoiceForConditionalGeneration.from_pretrained(repo_id, device_map=device).eval()
43
44# prepare inputs
45inputs = processor.apply_chat_template(
46 conversation, tokenize=True, return_dict=True
47).to(device)
48
49# Generate audio with a callback to track progress
50noise_scheduler = getattr(diffusers, model.generation_config.noise_scheduler_class)(
51 **model.generation_config.noise_scheduler_config
52)
53start_time = time.time()
54completed_samples = set()
55with tqdm(desc="Generating") as pbar:
56 def monitor_progress(p_batch):
57 # p_batch format: [current_step, max_step, completion_step] for each sample
58 finished_samples = (p_batch[:, 0] == p_batch[:, 1]).nonzero(as_tuple=False).squeeze(1)
59 if finished_samples.numel() > 0:
60 for sample_idx in finished_samples.tolist():
61 if sample_idx not in completed_samples:
62 completed_samples.add(sample_idx)
63 completion_step = int(p_batch[sample_idx, 2])
64 print(f"Sample {sample_idx} completed at step {completion_step}", flush=True)
65
66 active_samples = p_batch[:, 0] < p_batch[:, 1]
67 if active_samples.any():
68 active_progress = p_batch[active_samples]
69 max_active_idx = torch.argmax(active_progress[:, 0])
70 p = active_progress[max_active_idx].detach().cpu()
71 else:
72 p = p_batch[0].detach().cpu()
73
74 pbar.total = int(p[1])
75 pbar.n = int(p[0])
76 pbar.update()
77 outputs = model.generate(
78 **inputs,
79 max_new_tokens=max_new_tokens,
80 cfg_scale=cfg_scale,
81 noise_scheduler=noise_scheduler,
82 monitor_progress=monitor_progress,
83 return_dict_in_generate=True,
84 )
85generation_time = time.time() - start_time
86print(f"Generation time: {generation_time:.2f} seconds")
87
88# Save audio
89output_fp = "vibevoice_output.wav"
90processor.save_audio(outputs.audio[0], output_fp)
91print(f"Saved output to {output_fp}")processor.apply_chat_template to prepare the inputs:1inputs = processor.apply_chat_template(
2 [conversation1, conversation2],
3 tokenize=True,
4 return_dict=True
5)1import time
2import diffusers
3import numpy as np
4import torch
5from tqdm import tqdm
6
7from transformers import AutoProcessor, VibeVoiceForConditionalGeneration
8from transformers.audio_utils import load_audio_librosa
9
10
11repo_id = "microsoft/VibeVoice-1.5B-hf"
12sampling_rate = 24000
13max_new_tokens = 512 # set to None for full generation
14cfg_scale = 1.3 # classifier-free guidance for diffusion process
15
16# set seed for deterministic
17seed = 99
18torch.manual_seed(seed)
19np.random.seed(seed)
20
21# create conversation with an audio for the first time a speaker appears to clone that particular voice
22conversations = [
23 [
24 {"role": "0", "content": [
25 {"type": "text", "text": "Hello everyone, and welcome to the VibeVoice podcast. I'm your host, Linda, and today we're getting into one of the biggest debates in all of sports: who's the greatest basketball player of all time? I'm so excited to have Thomas here to talk about it with me."},
26 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav", sampling_rate=sampling_rate)}
27 ]},
28 {"role": "1", "content": [
29 {"type": "text", "text": "Thanks so much for having me, Linda. You're absolutely right—this question always brings out some seriously strong feelings."},
30 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Frank_man.wav", sampling_rate=sampling_rate)}
31 ]},
32 {"role": "0", "content": [
33 {"type": "text", "text": "Okay, so let's get right into it. For me, it has to be Michael Jordan. Six trips to the Finals, six championships. That kind of perfection is just incredible."},
34 ]},
35 {"role": "1", "content": [
36 {"type": "text", "text": "Oh man, the first thing that always pops into my head is that shot against the Cleveland Cavaliers back in '89. Jordan just rises, hangs in the air forever, and just sinks it"},
37 ]},
38 ],
39 [
40 {"role": "0", "content": [
41 {"type": "text", "text": "Hello and welcome to Planet in Peril. I'm your host, Alice. We're here today to discuss a really sobering new report that looks back at the last ten years of climate change, from 2015 to 2025. It paints a picture not just of steady warming, but of a dangerous acceleration. And to help us unpack this, I'm joined by our expert panel. Welcome Carter, Frank, and Maya."},
42 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav", sampling_rate=sampling_rate)}
43 ]},
44 {"role": "1", "content": [
45 {"type": "text", "text": "Hi Alice, it's great to be here. I'm Carter."},
46 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Carter_man.wav", sampling_rate=sampling_rate)}
47 ]},
48 {"role": "2", "content": [
49 {"type": "text", "text": "Hello, uh, I'm Frank. Good to be on."},
50 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Frank_man.wav", sampling_rate=sampling_rate)}
51 ]},
52 {"role": "3", "content": [
53 {"type": "text", "text": "And I'm Maya. Thanks for having me."},
54 {"type": "audio", "path": load_audio_librosa("https://hf.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Maya_woman.wav", sampling_rate=sampling_rate)}
55 ]},
56 ],
57]
58
59# load model
60device = "cuda" if torch.cuda.is_available() else "cpu"
61processor = AutoProcessor.from_pretrained(repo_id)
62model = VibeVoiceForConditionalGeneration.from_pretrained(repo_id, device_map=device).eval()
63
64# prepare inputs
65inputs = processor.apply_chat_template(
66 conversations, tokenize=True, return_dict=True
67).to(device)
68
69# Generate audio with a callback to track progress
70noise_scheduler = getattr(diffusers, model.generation_config.noise_scheduler_class)(
71 **model.generation_config.noise_scheduler_config
72)
73start_time = time.time()
74completed_samples = set()
75with tqdm(desc="Generating") as pbar:
76 def monitor_progress(p_batch):
77 # p_batch format: [current_step, max_step, completion_step] for each sample
78 finished_samples = (p_batch[:, 0] == p_batch[:, 1]).nonzero(as_tuple=False).squeeze(1)
79 if finished_samples.numel() > 0:
80 for sample_idx in finished_samples.tolist():
81 if sample_idx not in completed_samples:
82 completed_samples.add(sample_idx)
83 completion_step = int(p_batch[sample_idx, 2])
84 print(f"Sample {sample_idx} completed at step {completion_step}", flush=True)
85
86 active_samples = p_batch[:, 0] < p_batch[:, 1]
87 if active_samples.any():
88 active_progress = p_batch[active_samples]
89 max_active_idx = torch.argmax(active_progress[:, 0])
90 p = active_progress[max_active_idx].detach().cpu()
91 else:
92 p = p_batch[0].detach().cpu()
93
94 pbar.total = int(p[1])
95 pbar.n = int(p[0])
96 pbar.update()
97 outputs = model.generate(
98 **inputs,
99 max_new_tokens=max_new_tokens,
100 cfg_scale=cfg_scale,
101 noise_scheduler=noise_scheduler,
102 monitor_progress=monitor_progress,
103 return_dict_in_generate=True,
104 )
105generation_time = time.time() - start_time
106print(f"Generation time: {generation_time:.2f} seconds")
107
108# Save audio
109for i, speech_output in enumerate(outputs.audio):
110 output_fp = f"vibevoice_output_{i}.wav"
111 processor.save_audio(speech_output, output_fp)
112 print(f"Saved output to {output_fp}")