whisper.cpp 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/whisper/model.rb +9 -20
- data/lib/whisper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1b91cc9ac6e7682429f261d3e9b283c4c34ef246a2e88d07f1c294d145d1f4
|
4
|
+
data.tar.gz: be2a0ff1c4eda542685c209e6c64b7f3f3f902c4353534747922ea89c42ef24d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c992abd9e3e9b48d6b31cfa6489b5b09489781d251c2d3ca24d4932fca579b7d19b7483a1d72aefe77ac0655d5d5af19708bf6342cf6e5d4922d3663b1244acc
|
7
|
+
data.tar.gz: 8890fa1e7653f8690c3686a7751e597958c06adfaa3a0b3a3e74c947920f1da2014ada7eebe4fd78e85cc2a74fe235b244c43817937072ffe3b7c75792567ec1
|
data/lib/whisper/model.rb
CHANGED
@@ -8,6 +8,7 @@ module Whisper
|
|
8
8
|
def initialize(model_path)
|
9
9
|
@model_path = model_path
|
10
10
|
@ctx = nil
|
11
|
+
init_whisper_context
|
11
12
|
end
|
12
13
|
|
13
14
|
def transcribe_from_file(audio_file_path, format: 'plaintext', **params)
|
@@ -17,8 +18,6 @@ module Whisper
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def transcribe_from_audio_data(audio_data, format: 'plaintext', **params)
|
20
|
-
init_whisper_context(params)
|
21
|
-
|
22
21
|
# Prepare full params
|
23
22
|
full_params = default_full_params(params)
|
24
23
|
|
@@ -49,19 +48,13 @@ module Whisper
|
|
49
48
|
|
50
49
|
private
|
51
50
|
|
52
|
-
def init_whisper_context
|
51
|
+
def init_whisper_context params = {}
|
53
52
|
return unless @ctx.nil?
|
54
53
|
|
55
54
|
ctx_params = Whisper.whisper_context_default_params
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
user_ctx_params.each do |key, value|
|
60
|
-
if ctx_params.members.include?(field)
|
61
|
-
ctx_params[key] = value
|
62
|
-
else
|
63
|
-
warn "Unknown context_param field: #{field}"
|
64
|
-
end
|
56
|
+
params.select{ |k, _| ctx_params.members.include? k }.each do |key, value|
|
57
|
+
ctx_params[key] = value
|
65
58
|
end
|
66
59
|
ctx_params[:gpu_device] = ENV['WHISPER_GPU']&.to_i || 0
|
67
60
|
|
@@ -70,22 +63,18 @@ module Whisper
|
|
70
63
|
raise 'Failed to initialize Whisper model' if @ctx.null?
|
71
64
|
end
|
72
65
|
|
73
|
-
def default_full_params
|
66
|
+
def default_full_params params = {}
|
74
67
|
# Get default full params
|
75
68
|
strategy = params.fetch(:sampling_strategy, Whisper::WHISPER_SAMPLING_GREEDY)
|
76
69
|
full_params = Whisper.whisper_full_default_params(strategy)
|
77
70
|
|
78
|
-
|
71
|
+
# Set translate to false to prevent translation to English
|
79
72
|
full_params[:translate] = false
|
73
|
+
full_params[:language] = FFI::MemoryPointer.from_string 'auto'
|
80
74
|
|
81
75
|
# Set user-provided full params
|
82
|
-
|
83
|
-
|
84
|
-
if full_params.members.include?(field)
|
85
|
-
full_params[key] = value
|
86
|
-
else
|
87
|
-
warn "Unknown full_param field: #{field}"
|
88
|
-
end
|
76
|
+
params.select{ |k, _| full_params.members.include? k }.each do |key, value|
|
77
|
+
full_params[key] = value
|
89
78
|
end
|
90
79
|
|
91
80
|
full_params
|
data/lib/whisper/version.rb
CHANGED