Commit 4d626bb
committed
fix(vad): stop fragmenting live speech and correct the flush timestamp
Two defects in the VAD path that together produced short, silence-heavy audio
clips and one corrupt segment per recording.
1. Live redemption time was 400ms
`pipeline.rs` passed 400ms while `import.rs` and `retranscription.rs` both use
2000ms, so live recording and offline re-transcription of the same audio
segmented completely differently. The platform ternary was also dead
(`if macos { 400 } else { 400 }`), and `vad.rs` carried a comment claiming the
pipeline already passed 2000ms.
Redemption time decides how long a silence must be before a speech segment is
closed, and every segment becomes its own ASR request. At 400ms a 26-minute
meeting was split into 322 requests with a median length of 3.5s. Whisper is a
fixed 30-second-window model: below that it zero-pads the window and falls back
on its language-model prior, which was trained on web subtitles, so short clips
return memorised boilerplate ("subscribe to the channel", "thank you") rather
than speech. On a real recording 47% of segment boundaries sat in the
0.42-0.75s range, i.e. mid-sentence breaths a longer redemption simply bridges.
Now uses a named constant kept equal to the offline paths. Costs up to ~1.6s of
additional live-transcript latency at the end of each utterance.
2. `speech_start_sample` double-counted the session position
It was computed as `processed_samples + timestamp_ms`, but silero's
`timestamp_ms` is already session-absolute (`processed_duration()` minus
`pre_speech_pad`), so the two absolute values were summed and the start position
came out at roughly 2x the truth. The error grows with how late in the session
the utterance begins.
The only reader is the force-end branch in `flush()`, so it surfaced once per
recording, on the final segment: a phantom row timestamped past the end of the
audio, which sorted to the end of the stored transcript. Observed on a 1539.7s
recording as a segment starting at 3083.1s.
Adds two regression tests, both verified to fail before the change and pass
after. They use a leading-silence-then-speech fixture because the force-end path
only runs when recording stops mid-utterance, and the error is only large enough
to violate the invariant when speech starts late.
Also promotes VAD_SAMPLE_RATE to a module constant, since every sample count and
timestamp in the module is expressed in it.1 parent 7c94aa6 commit 4d626bb
2 files changed
Lines changed: 144 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| |||
719 | 728 | | |
720 | 729 | | |
721 | 730 | | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
730 | 754 | | |
731 | | - | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
732 | 759 | | |
733 | 760 | | |
734 | 761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
236 | 238 | | |
237 | 239 | | |
238 | 240 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
244 | 251 | | |
245 | 252 | | |
246 | 253 | | |
| |||
594 | 601 | | |
595 | 602 | | |
596 | 603 | | |
597 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
598 | 647 | | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
0 commit comments