File size: 2,572 Bytes
1ee7297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require_relative "helper"

class TestVADParams < TestBase
  PARAM_NAMES = [
    :threshold,
    :min_speech_duration_ms,
    :min_silence_duration_ms,
    :max_speech_duration_s,
    :speech_pad_ms,
    :samples_overlap
  ]

  def setup
    @params = Whisper::VAD::Params.new
  end

  def test_new
    params = Whisper::VAD::Params.new
    assert_kind_of Whisper::VAD::Params, params
  end

  def test_threshold
    assert_in_delta @params.threshold, 0.5
    @params.threshold = 0.7
    assert_in_delta @params.threshold, 0.7
  end

  def test_min_speech_duration
    pend
  end

  def test_min_speech_duration_ms
    assert_equal 250, @params.min_speech_duration_ms
    @params.min_speech_duration_ms = 500
    assert_equal 500, @params.min_speech_duration_ms
  end

  def test_min_silence_duration_ms
    assert_equal 100, @params.min_silence_duration_ms
    @params.min_silence_duration_ms = 200
    assert_equal 200, @params.min_silence_duration_ms
  end

  def test_max_speech_duration
    pend
  end

  def test_max_speech_duration_s
    assert @params.max_speech_duration_s >= 10e37 # Defaults to FLT_MAX
    @params.max_speech_duration_s = 60.0
    assert_equal 60.0, @params.max_speech_duration_s
  end

  def test_speech_pad_ms
    assert_equal 30, @params.speech_pad_ms
    @params.speech_pad_ms = 50
    assert_equal 50, @params.speech_pad_ms
  end

  def test_samples_overlap
    assert_in_delta @params.samples_overlap, 0.1
    @params.samples_overlap = 0.5
    assert_in_delta @params.samples_overlap, 0.5
  end

  def test_equal
    assert_equal @params, Whisper::VAD::Params.new
  end

  def test_new_with_kw_args
    params = Whisper::VAD::Params.new(threshold: 0.7)
    assert_in_delta params.threshold, 0.7
    assert_equal 250, params.min_speech_duration_ms
  end

  def test_new_with_kw_args_non_existent
    assert_raise ArgumentError do
      Whisper::VAD::Params.new(non_existent: "value")
    end
  end

  data(PARAM_NAMES.collect {|param| [param, param]}.to_h)
  def test_new_with_kw_args_default_values(param)
    default_value = @params.send(param)
    value = default_value + 1
    params = Whisper::VAD::Params.new(param => value)
    if Float === value
      assert_in_delta value, params.send(param)
    else
      assert_equal value, params.send(param)
    end

    PARAM_NAMES.reject {|name| name == param}.each do |name|
      expected = @params.send(name)
      actual = params.send(name)
      if Float === expected
        assert_in_delta expected, actual
      else
        assert_equal expected, actual
      end
    end
  end
end