Voicebox developer on retainer: infilling mode produces voice blending artifact when the gap to fill is adjacent to a speaker transition — flow-matching optimal transport path averages left and right audio context conditioning signals when right context starts a different speaker’s voice — right-context conditioning mask on diarization-detected speaker transitions eliminates voice blend — 3 weeks — Voicebox developer on monthly retainer

Voicebox (meta-research/voicebox) flow-matching-based TTS with in-context generation and audio infilling • Python 3.11; PyTorch 2.1.x • multi-speaker podcast post-production audio repair service • produces acoustically seamless synthesis for single-speaker segment infilling; generates a gradual voice blending artifact — infilled audio cross-fades from left-context speaker voice to right-context speaker voice across the gap — when the infilling gap is positioned immediately adjacent to a speaker transition in the surrounding audio; single-speaker gaps unaffected regardless of duration; developer checks Voicebox flow-matching conditioning, infilling context encoding, and speaker diarization integration for 3 weeks • root cause: Voicebox infilling conditions on both left audio context and right audio context as boundary conditions for the flow-matching optimal transport path; when right context begins a new speaker’s voice, the OT path receives two contradictory voice conditioning signals; generated audio blends both signals proportionally based on temporal proximity to each boundary • fix: integrate speaker diarization to detect speaker transitions at the right boundary; mask right-context voice conditioning when a speaker transition is detected, using only left-context conditioning for the infilled segment • infilling voice blend rate on speaker-transition-adjacent gaps: 100% → 0% • speaker cosine similarity within infilled segment: 0.69 → 0.91 at segment end • MOS: 3.7 → 4.0 • 1.5h retainer engagement

Greenfield Voicebox Ltd. built a podcast audio repair service using Voicebox’s infilling capability to replace damaged, noisy, or mispronounced audio segments in podcast recordings. The service processed multi-speaker podcast episodes: for a flagged segment in the audio, the system extracted surrounding context, used Voicebox to generate a replacement with matching acoustic properties, and spliced the repaired segment back into the original recording. The main value proposition was seamless repair — repaired segments should sound indistinguishable from the surrounding original audio.

Several weeks after launch, quality control reviews identified an artifact: some repaired segments sounded like two different voices blending together across the segment — starting with the left speaker’s voice and gradually transitioning to a different voice by the segment end. The artifact made the repaired segments obvious rather than seamless. When the team analyzed which segments exhibited the blend, a consistent pattern emerged: every affected repair was at a gap immediately adjacent to a speaker transition in the podcast — specifically where the right context (audio after the gap) began with a new speaker. Single-speaker gaps, even very long ones, were always clean. After three weeks of investigation including flow-matching conditioning analysis, context encoding review, and boundary condition testing, the team engaged a Voicebox retainer developer who identified the OT path conditioning blend mechanism as the root cause.

The diagnostic code that confirmed the voice blend and its speaker-transition-adjacency dependence:

# Greenfield Voicebox Ltd. — Voicebox speaker-transition-adjacent infilling diagnostic
# Voicebox (meta-research/voicebox) flow-matching TTS with infilling
# Python 3.11, PyTorch 2.1.x
# Deployment: multi-speaker podcast post-production audio repair

import numpy as np
import torch
import torchaudio
import resemblyzer
from voicebox import VoiceboxInfiller  # meta-research/voicebox

infiller = VoiceboxInfiller.from_pretrained('facebook/voicebox-en')

def measure_voice_shift_within_segment(
    infilled_audio: np.ndarray,
    left_reference: np.ndarray,
    sr: int = 16000,
) -> tuple[float, float]:
    """
    Measure speaker cosine similarity between reference (left context speaker)
    and the first 25% and last 25% of the infilled segment.
    Returns (similarity_at_start, similarity_at_end).
    Voice blend present if end similarity significantly lower than start.
    """
    encoder = resemblyzer.VoiceEncoder()
    ref_embed = encoder.embed_utterance(left_reference.astype(np.float32))
    quarter = len(infilled_audio) // 4
    start_seg = infilled_audio[:quarter]
    end_seg = infilled_audio[-quarter:]
    sim_start = float(np.dot(ref_embed, encoder.embed_utterance(start_seg.astype(np.float32))) /
                      (np.linalg.norm(ref_embed) *
                       np.linalg.norm(encoder.embed_utterance(start_seg.astype(np.float32)))))
    sim_end = float(np.dot(ref_embed, encoder.embed_utterance(end_seg.astype(np.float32))) /
                    (np.linalg.norm(ref_embed) *
                     np.linalg.norm(encoder.embed_utterance(end_seg.astype(np.float32)))))
    return sim_start, sim_end

# Load test audio segments
left_speaker_audio, sr = torchaudio.load('speaker_a_context.wav')   # speaker A, left of gap
right_same_audio, _    = torchaudio.load('speaker_a_right.wav')     # speaker A, right of gap
right_new_audio, _     = torchaudio.load('speaker_b_context.wav')   # speaker B, right of gap

test_cases = [
    (right_same_audio, False, "single-speaker gap (A | gap | A) — no blend expected"),
    (right_new_audio,  True,  "speaker-transition gap (A | gap | B) — blend expected"),
]

for right_context, expect_blend, desc in test_cases:
    with torch.no_grad():
        infilled = infiller.infill(
            text="The recording was interrupted here.",
            left_context=left_speaker_audio,
            right_context=right_context,
            duration_seconds=2.0,
        )
    sim_start, sim_end = measure_voice_shift_within_segment(
        infilled.numpy(), left_speaker_audio.numpy()[0]
    )
    blend_detected = (sim_start - sim_end) > 0.10
    status = "BLEND" if blend_detected else "clean"
    print(f"[{status:5s}] {desc}")
    print(f"       speaker cosine at start: {sim_start:.3f}")
    print(f"       speaker cosine at end:   {sim_end:.3f}")
    print(f"       shift magnitude:         {sim_start - sim_end:.3f}")

# Output:
# [clean] single-speaker gap (A | gap | A) — no blend expected
#         speaker cosine at start: 0.912
#         speaker cosine at end:   0.908
#         shift magnitude:         0.004  ← consistent voice (< 0.10 threshold)
# [BLEND] speaker-transition gap (A | gap | B) — blend expected
#         speaker cosine at start: 0.908
#         speaker cosine at end:   0.693
#         shift magnitude:         0.215  ← VOICE BLEND CONFIRMED

Why Voicebox’s flow-matching optimal transport path produces a voice blending artifact when infilling near a speaker transition

Voicebox generates audio using a flow-matching model that learns to transform Gaussian noise into realistic speech via an optimal transport path. The infilling mode adapts this process by conditioning the OT path on both the left audio context and the right audio context as boundary constraints: the generated segment must connect acoustically from the left boundary to the right boundary. This bilateral conditioning is what gives Voicebox its seamless infilling quality for single-speaker content — the generated audio inherits acoustic properties from both surrounding boundaries and transitions smoothly between them.

The bilateral conditioning mechanism introduces a problem in multi-speaker contexts. When the gap to be filled is positioned immediately before a speaker transition, the right audio context begins with a different speaker’s voice than the left context. The flow-matching model receives two distinct voice conditioning signals as boundary constraints: the left context encodes speaker A’s pitch range, speaking rate, formant structure, and voice quality; the right context encodes speaker B’s corresponding acoustic characteristics. The OT path in the flow-matching process is computed as a weighted blend of both boundary conditions, with weights proportional to the temporal proximity to each boundary. At the start of the generated segment, the left context conditioning dominates — the voice sounds like speaker A. As the generated segment progresses toward its end, the right context conditioning gains weight — the voice progressively shifts toward speaker B. The result is an audible voice morph across the infilled segment: a cross-fade between two distinct speaker identities within what should be a single speaker’s coherent utterance.

# Fix: integrate speaker diarization and mask right-context conditioning
# on detected speaker transitions

import pyannote.audio  # speaker diarization
import torch
import torchaudio
from voicebox import VoiceboxInfiller

infiller = VoiceboxInfiller.from_pretrained('facebook/voicebox-en')
diarizer = pyannote.audio.Pipeline.from_pretrained(
    'pyannote/speaker-diarization-3.1',
    use_auth_token='YOUR_HF_TOKEN'
)

TRANSITION_DETECTION_THRESHOLD_S = 0.5  # check first 0.5s of right context


def detect_speaker_transition_at_right_boundary(
    left_context: torch.Tensor,
    right_context: torch.Tensor,
    sr: int = 16000,
    check_duration_s: float = TRANSITION_DETECTION_THRESHOLD_S,
) -> bool:
    """
    Detect whether the right context begins with a different speaker than
    the left context, using pyannote speaker diarization.
    Returns True if a speaker transition is detected at the right boundary.
    """
    # Concatenate left + right context with a marker gap for diarization
    gap_frames = int(sr * 0.1)  # 100ms marker gap
    combined = torch.cat([
        left_context,
        torch.zeros(1, gap_frames),
        right_context[:, :int(sr * check_duration_s)]
    ], dim=-1)
    torchaudio.save('/tmp/diarize_check.wav', combined, sr)
    diarization = diarizer('/tmp/diarize_check.wav')
    # Check if the speaker label changes across the gap
    left_duration = left_context.shape[-1] / sr
    right_start = left_duration + 0.1  # after marker gap
    speakers_at_boundary = set()
    for turn, _, speaker in diarization.itertracks(yield_label=True):
        if turn.end >= left_duration - 0.3 and turn.start <= left_duration:
            speakers_at_boundary.add(('left', speaker))
        if turn.start <= right_start + 0.3 and turn.end >= right_start:
            speakers_at_boundary.add(('right', speaker))
    left_speakers = {spk for side, spk in speakers_at_boundary if side == 'left'}
    right_speakers = {spk for side, spk in speakers_at_boundary if side == 'right'}
    return len(left_speakers & right_speakers) == 0  # no overlap = transition


def speaker_aware_infill(
    text: str,
    left_context: torch.Tensor,
    right_context: torch.Tensor,
    duration_seconds: float,
    sr: int = 16000,
) -> torch.Tensor:
    """
    Infill audio with speaker-aware right-context conditioning mask.
    If speaker diarization detects a transition at the right boundary,
    mask right-context conditioning to prevent voice blending.
    """
    transition_detected = detect_speaker_transition_at_right_boundary(
        left_context, right_context, sr
    )
    if transition_detected:
        # Mask right context — infill using only left context conditioning
        with torch.no_grad():
            return infiller.infill(
                text=text,
                left_context=left_context,
                right_context=None,         # mask right context
                duration_seconds=duration_seconds,
            )
    else:
        # Standard bilateral infilling — no transition, both contexts safe
        with torch.no_grad():
            return infiller.infill(
                text=text,
                left_context=left_context,
                right_context=right_context,
                duration_seconds=duration_seconds,
            )


# --- Results after speaker-aware infilling fix ---
#
# Speaker cosine similarity shift within infilled segment (AFTER fix):
#   Before fix (transition gap, bilateral conditioning):
#     Start similarity: 0.908   End similarity: 0.693   Shift: 0.215  — BLEND
#   After fix (transition gap, left-context only):
#     Start similarity: 0.912   End similarity: 0.904   Shift: 0.008  — CLEAN
#
# MOS evaluation (10 listeners, 40 transition-adjacent infilling cases):
#   Before fix: MOS 3.7 (σ=0.5) — "voice shifts mid-sentence, two voices mixed"
#   After fix:  MOS 4.0 (σ=0.3) — "natural repair, consistent voice throughout"
#
# Infilling voice blend rate on speaker-transition-adjacent gaps:
#   Before fix: 100% of transition-adjacent gaps produced audible blend
#   After fix:    0% — all gaps voice-consistent throughout
#
# Regression check on single-speaker gaps (no transition):
#   diarization returns no transition → bilateral conditioning used (unchanged)
#   Speaker cosine similarity: 0.912 → 0.912 (identical path)
#   MOS: 4.1 → 4.1 (unchanged)
#
# Diarization overhead: ~0.4 seconds per gap (pyannote 3.1 on GPU)
# Acceptable for post-production use case; can be parallelized with text prep.

print("Fix: speaker diarization + right-context conditioning mask on transitions.")
print("Voice blend rate on speaker-transition-adjacent gaps: 100% → 0%.")
print("Speaker cosine at segment end: 0.69 → 0.91; MOS: 3.7 → 4.0; 1.5h")

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →