Views
No views yet

pip install git+https://github.com/huggingface/transformers.gitdiffusers internally.pip install diffusers
pip install soundfile # for saving audio1from transformers import AutoProcessor, AutoModelForTextToWaveform
2
3model_id = "microsoft/VibeVoice-1.5B-hf"
4processor = AutoProcessor.from_pretrained(model_id)
5model = AutoModelForTextToWaveform.from_pretrained(model_id)1import os
2from transformers import AutoProcessor, AutoModelForTextToWaveform
3
4model_id = "microsoft/VibeVoice-1.5B-hf"
5text = "Hello, nice to meet you. How are you?"
6
7# Load model
8processor = AutoProcessor.from_pretrained(model_id)
9model = AutoModelForTextToWaveform.from_pretrained(model_id, device_map="auto")
10
11# Prepare input
12conversation = [{"role": "0", "content": [{"type": "text", "text": text}]}]
13inputs = processor.apply_chat_template(
14 conversation, return_dict=True, tokenize=True, add_generation_prompt=True,
15).to(model.device, model.dtype)
16
17# Generate!
18audio = model.generate(**inputs)
19
20# Save to file
21file_name = f"{os.path.basename(model_id)}_tts.wav"
22processor.save_audio(audio, file_name)
23print(f"Saved output to {file_name}")1import os
2from transformers import AutoProcessor, AutoModelForTextToWaveform, set_seed
3
4model_id = "microsoft/VibeVoice-1.5B-hf"
5text = "Hello, nice to meet you. How are you?"
6set_seed(42) # for deterministic results
7
8# Load model
9processor = AutoProcessor.from_pretrained(model_id)
10model = AutoModelForTextToWaveform.from_pretrained(model_id, device_map="auto")
11sampling_rate = processor.feature_extractor.sampling_rate
12
13# Prepare input
14conversation = [
15 {
16 "role": "0",
17 "content": [
18 {"type": "text", "text": text},
19 {
20 "type": "audio",
21 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav",
22 },
23 ],
24 }
25]
26inputs = processor.apply_chat_template(
27 conversation, return_dict=True, tokenize=True, add_generation_prompt=True,
28).to(model.device, model.dtype)
29
30# Generate!
31audio = model.generate(**inputs)
32
33# Save to file
34fn = f"{os.path.basename(model_id)}_tts_clone.wav"
35processor.save_audio(audio, fn)
36print(f"Saved output to {fn}")monitor_progress option to track the generation progress.1import os
2import time
3from transformers import AutoProcessor, AutoModelForTextToWaveform
4
5model_id = "microsoft/VibeVoice-1.5B-hf"
6max_new_tokens = 400 # `None` to ensure full generation
7
8# create conversation with an audio for the first time a speaker appears to clone that particular voice
9conversation = [
10 {
11 "role": "0",
12 "content": [
13 {
14 "type": "text",
15 "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.",
16 },
17 {
18 "type": "audio",
19 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav",
20 },
21 ],
22 },
23 {
24 "role": "1",
25 "content": [
26 {
27 "type": "text",
28 "text": "Thanks so much for having me, Linda. You're absolutely right—this question always brings out some seriously strong feelings.",
29 },
30 {
31 "type": "audio",
32 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Frank_man.wav",
33 },
34 ],
35 },
36 {
37 "role": "0",
38 "content": [
39 {
40 "type": "text",
41 "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.",
42 },
43 ],
44 },
45 {
46 "role": "1",
47 "content": [
48 {
49 "type": "text",
50 "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",
51 },
52 ],
53 },
54]
55
56# Load model
57processor = AutoProcessor.from_pretrained(model_id)
58model = AutoModelForTextToWaveform.from_pretrained(model_id, device_map="auto")
59
60# prepare inputs
61inputs = processor.apply_chat_template(
62 conversation, return_dict=True, tokenize=True, add_generation_prompt=True,
63).to(model.device, model.dtype)
64
65# Generate audio with a progress bar to track generation
66model.generation_config.max_new_tokens = max_new_tokens
67start_time = time.time()
68audio = model.generate(**inputs, monitor_progress=True)
69generation_time = time.time() - start_time
70print(f"Generation time: {generation_time:.2f} seconds")
71
72# Save audio
73fn = f"{os.path.basename(model_id)}_script.wav"
74processor.save_audio(audio, fn)
75print(f"Saved output to {fn}")processor.apply_chat_template:1import os
2import time
3from transformers import AutoProcessor, AutoModelForTextToWaveform
4
5model_id = "microsoft/VibeVoice-1.5B-hf"
6max_new_tokens = 400 # `None` to ensure full generation
7
8conversation = [
9 [
10 {
11 "role": "0",
12 "content": [
13 {
14 "type": "text",
15 "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.",
16 },
17 {
18 "type": "audio",
19 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav",
20 },
21 ],
22 },
23 {
24 "role": "1",
25 "content": [
26 {
27 "type": "text",
28 "text": "Thanks so much for having me, Linda.",
29 },
30 {
31 "type": "audio",
32 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Frank_man.wav",
33 },
34 ],
35 },
36 ],
37 [
38 {
39 "role": "0",
40 "content": [
41 {
42 "type": "text",
43 "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. I'm joined by our expert panel. Welcome Carter, Frank, and Maya.",
44 },
45 {
46 "type": "audio",
47 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav",
48 },
49 ],
50 },
51 {
52 "role": "1",
53 "content": [
54 {"type": "text", "text": "Hi Alice, it's great to be here. I'm Carter."},
55 {
56 "type": "audio",
57 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Carter_man.wav",
58 },
59 ],
60 },
61 {
62 "role": "2",
63 "content": [
64 {"type": "text", "text": "Hello, uh, I'm Frank. Good to be on."},
65 {
66 "type": "audio",
67 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Frank_man.wav",
68 },
69 ],
70 },
71 {
72 "role": "3",
73 "content": [
74 {"type": "text", "text": "And I'm Maya. Thanks for having me."},
75 {
76 "type": "audio",
77 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Maya_woman.wav",
78 },
79 ],
80 },
81 ],
82]
83
84# Load model
85processor = AutoProcessor.from_pretrained(model_id)
86model = AutoModelForTextToWaveform.from_pretrained(model_id, device_map="auto")
87
88# prepare inputs
89inputs = processor.apply_chat_template(
90 conversation, return_dict=True, tokenize=True, add_generation_prompt=True,
91).to(model.device, model.dtype)
92
93# Generate audio with a progress bar to track generation
94model.generation_config.max_new_tokens = max_new_tokens
95start_time = time.time()
96audio = model.generate(**inputs, monitor_progress=True)
97generation_time = time.time() - start_time
98print(f"Generation time: {generation_time:.2f} seconds")
99
100# Save audio
101output_dir = f"{os.path.basename(model_id)}_batch"
102processor.save_audio(audio, output_dir)
103print(f"Saved output to {output_dir}")1import os
2import soundfile as sf
3from transformers import pipeline
4
5model_id = "microsoft/VibeVoice-1.5B-hf"
6text = "Hello, nice to meet you. How are you?"
7pipe = pipeline("text-to-speech", model=model_id)
8
9# Generate!
10conversation = [
11 {
12 "role": "0",
13 "content": [
14 {"type": "text", "text": text},
15 {
16 "type": "audio",
17 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/voices/en-Alice_woman.wav",
18 },
19 ],
20 }
21]
22# optional kwargs for generation
23generate_kwargs = {"guidance_scale": 1.3, "num_diffusion_steps": 10}
24output = pipe(conversation, generate_kwargs=generate_kwargs)
25
26# Save to file
27fn = f"{os.path.basename(model_id)}_pipeline.wav"
28sf.write(fn, output["audio"], output["sampling_rate"])
29print(f"Saved output to {fn}")1from transformers import AutoProcessor, AutoModelForTextToWaveform
2
3model_id = "microsoft/VibeVoice-1.5B-hf"
4
5# Load model and processor
6processor = AutoProcessor.from_pretrained(model_id)
7model = AutoModelForTextToWaveform.from_pretrained(
8 model_id,
9 diffusion_loss_weight=0.75, # by default, equal weighting (0.5) of language modeling loss (CE) and diffusion loss is applied
10 device_map="auto"
11)
12model.train()
13
14# Prepare batch of 2
15conversation = [
16 [
17 {
18 "role": "0",
19 "content": [
20 {
21 "type": "text",
22 "text": "VibeVoice is this novel framework designed for generating expressive, long-form, multi-speaker, conversational audio.",
23 },
24 {
25 "type": "audio",
26 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
27 },
28 ],
29 }
30 ],
31 # NOTE: multiple speakers not supported yet
32 [
33 {
34 "role": "0",
35 "content": [
36 {
37 "type": "text",
38 "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. Thanks so much for having me, Alex. And you're absolutely right. This question always brings out some seriously strong feelings. 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. 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.",
39 },
40 {
41 "type": "audio",
42 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/example_output/VibeVoice-1.5B_output.wav",
43 },
44 ],
45 }
46 ],
47]
48
49# Process with apply_chat_template and output_labels=True for training
50inputs = processor.apply_chat_template(
51 conversation,
52 tokenize=True,
53 return_dict=True,
54 processor_kwargs={"output_labels": True},
55).to(model.device, model.dtype)
56
57# Forward pass
58outputs = model(**inputs, ddpm_batch_multiplier=2, num_diffusion_steps=2)
59print(f"Total loss: {outputs.loss.item():.4f}")
60
61# Backward pass
62outputs.loss.backward()torch.compile for faster inference. A few warmup runs are needed before the compiled model reaches full speed.1import os
2import time
3import torch
4from transformers import AutoModelForTextToWaveform, AutoProcessor, CompileConfig
5
6model_id = "microsoft/VibeVoice-1.5B-hf"
7num_warmup = 5
8max_new_tokens = 128
9
10torch.set_float32_matmul_precision("high")
11
12# Load processor + model
13processor = AutoProcessor.from_pretrained(model_id)
14model = AutoModelForTextToWaveform.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto").eval()
15
16# Prepare inputs
17conversation = [
18 [
19 {
20 "role": "0",
21 "content": [
22 {"type": "text", "text": "VibeVoice is a novel framework for generating expressive audio."},
23 {
24 "type": "audio",
25 "url": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
26 },
27 ],
28 }
29 ],
30] * 4 # batch size 4
31inputs = processor.apply_chat_template(
32 conversation, tokenize=True, return_dict=True, add_generation_prompt=True,
33).to(model.device, model.dtype)
34
35compile_config = CompileConfig(mode="default", dynamic=False)
36
37generate_kwargs = dict(
38 **inputs,
39 max_new_tokens=max_new_tokens,
40 cache_implementation="static",
41 compile_config=compile_config,
42)
43
44# Warmup
45print("Warming up...")
46warmup_start = time.time()
47with torch.inference_mode():
48 for _ in range(num_warmup):
49 torch.compiler.cudagraph_mark_step_begin()
50 _ = model.generate(**generate_kwargs)
51torch.cuda.synchronize()
52print(f"Warmup complete in {time.time() - warmup_start:.2f}s. Ready!")
53
54# Apply model
55with torch.inference_mode():
56 torch.compiler.cudagraph_mark_step_begin()
57 audio = model.generate(**generate_kwargs)
58output_folder = f"{os.path.basename(model_id)}_compiled_output"
59processor.save_audio(audio, output_folder)
60print(f"Saved output to {output_folder}")