Class: Itak::Transcriber

Inherits:
Object
  • Object
show all
Defined in:
lib/itak/transcriber.rb

Constant Summary collapse

PARAMS =
{
  language: "ja",
  temperature: 1.0
}

Instance Method Summary collapse

Constructor Details

#initialize(model: "large-v3-turbo-q8_0") ⇒ Transcriber

Returns a new instance of Transcriber.



10
11
12
13
# File 'lib/itak/transcriber.rb', line 10

def initialize(model: "large-v3-turbo-q8_0")
  Whisper.log_set proc {}, nil
  @whisper = Whisper::Context.new(model)
end

Instance Method Details

#run(src, params: {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/itak/transcriber.rb', line 15

def run(src, params: {})
  params = Whisper::Params.new(**PARAMS.merge(params))
  src = src[0] if src.ndim == 2 && src.shape[0] == 1
  @whisper
    .full(params, src.to_ndav)
    .each_segment
    .collect {|segment|
      "[%<start_time>s --> %<end_time>s]%<text>s" % {
        start_time: format_time(segment.start_time),
        end_time: format_time(segment.end_time),
        text: segment.text
      }
    }.join("\n\n")
end