Views
No views yet

| Model | Context Length | Generation Length | Weight |
|---|---|---|---|
| VibeVoice-1.5B | 64K | ~90 min | HF link |
| VibeVoice-7B | 32K | ~45 min | This model |
| VibeVoice-0.5B-Streaming | - | - | On the way |
1pip install git+https://github.com/pengzhiliang/transformers.git@4b4f4bdc64baca807e8364692313a6183a6116f6
2pip install torch torchvision torchaudio
3pip install diffusers soundfile accelerate1from transformers import AutoProcessor, VibeVoiceForConditionalGeneration
2
3repo_id = "microsoft/VibeVoice-7B-hf"
4processor = AutoProcessor.from_pretrained(repo_id)
5model = VibeVoiceForConditionalGeneration.from_pretrained(repo_id)1import time
2import numpy as np
3import torch
4import os
5import soundfile as sf
6
7from transformers import pipeline
8
9
10repo_id = "microsoft/VibeVoice-7B-hf"
11sampling_rate = 24000
12text = "Hello, nice to meet you. I'm Vibey."
13
14# Optional parameters for diffusion process, defaults are in the model's generation_config.json
15cfg_scale = 1.3 # classifier-free guidance for diffusion process
16n_diffusion_steps = 8 # number of diffusion steps for each audio chunk
17
18# Set seed for deterministic
19seed = 42
20torch.manual_seed(seed)
21np.random.seed(seed)
22
23# Load pipeline
24pipe = pipeline("text-to-speech", model=repo_id, no_processor=False)
25
26# Prepare input
27input_data = pipe.processor.apply_chat_template(
28 [{"role": "0", "content": [{"type": "text", "text": text}]}], tokenize=False,
29)
30
31# Generate!
32start_time = time.time()
33generate_kwargs = {
34 "cfg_scale": cfg_scale,
35 "n_diffusion_steps": n_diffusion_steps,
36}
37output = pipe(input_data, generate_kwargs=generate_kwargs)
38end_time = time.time()
39print(f"Generation took {end_time - start_time:.2f} seconds.")
40
41# Save to file
42audio = output["audio"][0].squeeze()
43fn = f"{os.path.basename(repo_id)}_pipeline_tts.wav"
44sf.write(fn, audio, sampling_rate)
45print(f"Audio saved to {fn}")1import time
2import numpy as np
3import torch
4from tqdm import tqdm
5import os
6
7from transformers import AutoProcessor, VibeVoiceForConditionalGeneration
8
9
10repo_id = "microsoft/VibeVoice-7B-hf"
11sampling_rate = 24000
12max_new_tokens = 400 # set to None for generation till the end of script
13
14# Optional parameters for diffusion process, defaults are in the model's generation_config.json
15cfg_scale = 1.3 # classifier-free guidance for diffusion process
16n_diffusion_steps = 10 # number of diffusion steps for each audio chunk
17
18# set seed for deterministic
19seed = 42
20torch.manual_seed(seed)
21np.random.seed(seed)
22
23conversation = [
24 {"role": "0", "content": [
25 {"type": "text", "text": "Hello everyone, and welcome to the VibeVoice podcast. I'm your host, Alex, 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 Sam here to talk about it with me."},
26 ]},
27 {"role": "1", "content": [
28 {"type": "text", "text": "Thanks so much for having me, Alex. You're absolutely right—this question always brings out some seriously strong feelings."},
29 ]},
30 {"role": "0", "content": [
31 {"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."},
32 ]},
33 {"role": "1", "content": [
34 {"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"},
35 ]},
36]
37
38# load model
39device = "cuda" if torch.cuda.is_available() else "cpu"
40processor = AutoProcessor.from_pretrained(repo_id)
41model = VibeVoiceForConditionalGeneration.from_pretrained(repo_id, device_map=device).eval()
42
43# prepare inputs
44inputs = processor.apply_chat_template(
45 conversation, tokenize=True, return_dict=True
46).to(device)
47
48# Generate audio with a callback to track progress
49start_time = time.time()
50completed_samples = set()
51with tqdm(desc="Generating") as pbar:
52 def monitor_progress(p_batch):
53 # p_batch format: [current_step, max_step, completion_step] for each sample
54 finished_samples = (p_batch[:, 0] == p_batch[:, 1]).nonzero(as_tuple=False).squeeze(1)
55 if finished_samples.numel() > 0:
56 for sample_idx in finished_samples.tolist():
57 if sample_idx not in completed_samples:
58 completed_samples.add(sample_idx)
59 completion_step = int(p_batch[sample_idx, 2])
60 print(f"Sample {sample_idx} completed at step {completion_step}", flush=True)
61
62 active_samples = p_batch[:, 0] < p_batch[:, 1]
63 if active_samples.any():
64 active_progress = p_batch[active_samples]
65 max_active_idx = torch.argmax(active_progress[:, 0])
66 p = active_progress[max_active_idx].detach().cpu()
67 else:
68 p = p_batch[0].detach().cpu()
69
70 pbar.total = int(p[1])
71 pbar.n = int(p[0])
72 pbar.update()
73 outputs = model.generate(
74 **inputs,
75 max_new_tokens=max_new_tokens,
76 cfg_scale=cfg_scale,
77 n_diffusion_steps=n_diffusion_steps,
78 monitor_progress=monitor_progress,
79 return_dict_in_generate=True,
80 )
81generation_time = time.time() - start_time
82print(f"Generation time: {generation_time:.2f} seconds")
83
84# Save audio
85output_fp = f"{os.path.basename(repo_id)}_output.wav"
86processor.save_audio(outputs.audio[0], output_fp)
87print(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-7B-hf"
12sampling_rate = 24000
13max_new_tokens = 400 # set to None for generation till the end of script
14
15# Optional parameters for diffusion process, defaults are in the model's generation_config.json
16cfg_scale = 1.3 # classifier-free guidance for diffusion process
17n_diffusion_steps = 10 # number of diffusion steps for each audio chunk
18
19# set seed for deterministic
20seed = 42
21torch.manual_seed(seed)
22np.random.seed(seed)
23
24conversations = [
25 [
26 {"role": "0", "content": [
27 {"type": "text", "text": "Hello everyone, and welcome to the VibeVoice podcast. I'm your host, Alex, 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 Sam here to talk about it with me."},
28 ]},
29 {"role": "1", "content": [
30 {"type": "text", "text": "Thanks so much for having me, Alex. You're absolutely right—this question always brings out some seriously strong feelings."},
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, Alex. 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 Sam, Morgan, and Jordan."},
42 ]},
43 {"role": "1", "content": [
44 {"type": "text", "text": "Hi Alex, it's great to be here. I'm Sam."},
45 ]},
46 {"role": "2", "content": [
47 {"type": "text", "text": "Hello, uh, I'm Morgan. Good to be on."},
48 ]},
49 {"role": "3", "content": [
50 {"type": "text", "text": "And I'm Jordan. Thanks for having me."},
51 ]},
52 ],
53]
54
55# load model
56device = "cuda" if torch.cuda.is_available() else "cpu"
57processor = AutoProcessor.from_pretrained(repo_id)
58model = VibeVoiceForConditionalGeneration.from_pretrained(
59 repo_id,
60 device_map=device,
61).to(device).eval()
62
63# prepare inputs
64inputs = processor.apply_chat_template(
65 conversations, return_dict=True, tokenize=True,
66).to(device)
67
68# Generate audio with a callback to track progress
69start_time = time.time()
70completed_samples = set()
71with tqdm(desc="Generating") as pbar:
72 def monitor_progress(p_batch):
73 # p_batch format: [current_step, max_step, completion_step] for each sample
74 finished_samples = (p_batch[:, 0] == p_batch[:, 1]).nonzero(as_tuple=False).squeeze(1)
75 if finished_samples.numel() > 0:
76 for sample_idx in finished_samples.tolist():
77 if sample_idx not in completed_samples:
78 completed_samples.add(sample_idx)
79 completion_step = int(p_batch[sample_idx, 2])
80 print(f"Sample {sample_idx} completed at step {completion_step}", flush=True)
81
82 active_samples = p_batch[:, 0] < p_batch[:, 1]
83 if active_samples.any():
84 active_progress = p_batch[active_samples]
85 max_active_idx = torch.argmax(active_progress[:, 0])
86 p = active_progress[max_active_idx].detach().cpu()
87 else:
88 p = p_batch[0].detach().cpu()
89
90 pbar.total = int(p[1])
91 pbar.n = int(p[0])
92 pbar.update()
93 outputs = model.generate(
94 **inputs,
95 max_new_tokens=max_new_tokens,
96 cfg_scale=cfg_scale,
97 n_diffusion_steps=n_diffusion_steps,
98 monitor_progress=monitor_progress,
99 return_dict_in_generate=True,
100 )
101generation_time = time.time() - start_time
102print(f"Generation time: {generation_time:.2f} seconds")
103
104# Save audio
105for i, audio in enumerate(outputs.audio):
106 output_fp = f"{os.path.basename(repo_id)}_output_{i}.wav"
107 processor.save_audio(audio, output_fp)
108 print(f"Saved output to {output_fp}")