test_transcriber.py 857 B

123456789101112131415161718192021222324252627282930313233
  1. """Tests for the Whisper segment confidence gate."""
  2. from stt_daemon.transcriber import accept_segment
  3. class _Seg:
  4. def __init__(self, text="hello", no_speech_prob=0.1, avg_logprob=-0.3):
  5. self.text = text
  6. self.no_speech_prob = no_speech_prob
  7. self.avg_logprob = avg_logprob
  8. def test_accepts_confident_speech():
  9. assert accept_segment(_Seg(), 0.6, -1.0)
  10. def test_rejects_high_no_speech_prob():
  11. assert not accept_segment(_Seg(no_speech_prob=0.9), 0.6, -1.0)
  12. def test_rejects_low_avg_logprob():
  13. assert not accept_segment(_Seg(avg_logprob=-1.5), 0.6, -1.0)
  14. def test_threshold_boundary_is_accepted():
  15. assert accept_segment(_Seg(no_speech_prob=0.6, avg_logprob=-1.0), 0.6, -1.0)
  16. def test_missing_attributes_default_to_accept():
  17. class Bare:
  18. text = "x"
  19. assert accept_segment(Bare(), 0.6, -1.0)