Skip to content

Commit 432622f

Browse files
fix(desktop): cushion Pocket playback underruns
Signed-off-by: John Tennant <[email protected]>
1 parent a558d9f commit 432622f

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

  • desktop/src-tauri/src/huddle

‎desktop/src-tauri/src/huddle/tts.rs‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ fn tts_worker(
550550
&mut first_append,
551551
audio,
552552
silence_buf_len,
553-
model_chunk_index == 0,
553+
model_chunk_index == 0 || player.empty(),
554554
ends_playback_chunk,
555555
);
556556

@@ -699,13 +699,12 @@ fn apply_fade_out(samples: &mut [f32]) {
699699
}
700700
}
701701

702-
/// Build the single buffer appended to the rodio `Player` for one synthesised
703-
/// sentence.
702+
/// Build one buffer appended to the rodio `Player` for a synthesis unit.
704703
///
705-
/// Every sentence chunk gets a short lead-in pad immediately before its audio.
706-
/// This matters for chunks that start with soft first phonemes (`I'm`, `I've`):
707-
/// the synthesized buffer can begin with speech within the first millisecond,
708-
/// so the playback layer must provide the device/mixer cushion.
704+
/// Every playback boundary gets a short lead-in pad immediately before its
705+
/// audio. This matters for chunks that start with soft first phonemes (`I'm`,
706+
/// `I've`): the synthesized buffer can begin with speech within the first
707+
/// millisecond, so the playback layer must provide the device/mixer cushion.
709708
/// To keep the audible gap unchanged, the trailing silence after this chunk is
710709
/// shortened by the same amount (`silence_buf_len - SENTENCE_LEAD_IN_SAMPLES`):
711710
/// sentence N contributes 80 ms of post-speech silence and sentence N+1
@@ -716,15 +715,15 @@ fn apply_fade_out(samples: &mut [f32]) {
716715
/// tracked source per synthesized sentence, avoiding source-boundary/drain
717716
/// regressions from enqueueing the lead-in, audio, and tail as separate sounds.
718717
///
718+
/// A playback chunk may contain several model-sized synthesis units. Only the
719+
/// first unit receives the onset cushion and only the last receives the
720+
/// remaining gap. If playback underruns while the next unit is synthesized,
721+
/// that unit becomes a new playback boundary and receives a fresh cushion.
722+
///
719723
/// `first_append` is flipped on the first call after the player goes idle.
720724
/// The worker uses it in the idle branch of the main loop to distinguish
721725
/// "never queued anything since last drain" from "drained after speaking",
722726
/// which controls when `tts_active` is released and the lead-in re-armed.
723-
/// Add silence only at the outer playback boundary.
724-
///
725-
/// A playback chunk may contain several model-sized synthesis units. The first
726-
/// unit receives the onset cushion, the last receives the remaining gap, and
727-
/// intermediate units stay sample-contiguous.
728727
fn build_sentence_append_buffer(
729728
first_append: &mut bool,
730729
audio: Vec<f32>,

0 commit comments

Comments
 (0)