Skip to content

Commit 2cdf91a

Browse files
authored
Merge pull request #99 from SirDaXll/main
Fix "_init_model" resseting params of Command Prompt
2 parents 7030ec9 + e9cf94b commit 2cdf91a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pywhispercpp/model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ def get_params(self) -> dict:
166166
for param in dir(self._params):
167167
if param.startswith('__'):
168168
continue
169-
res[param] = getattr(self._params, param)
169+
try:
170+
res[param] = getattr(self._params, param)
171+
except Exception:
172+
# ignore callback functions
173+
continue
170174
return res
171175

172176
@staticmethod
@@ -224,7 +228,6 @@ def _init_model(self) -> None:
224228
logger.info("Initializing the model ...")
225229
with utils.redirect_stderr(to=self.redirect_whispercpp_logs_to):
226230
self._ctx = pw.whisper_init_from_file(self.model_path)
227-
self._params = pw.whisper_full_default_params(pw.whisper_sampling_strategy.WHISPER_SAMPLING_GREEDY)
228231

229232
def _set_params(self, kwargs: dict) -> None:
230233
"""
@@ -238,11 +241,12 @@ def _set_params(self, kwargs: dict) -> None:
238241
def _transcribe(self, audio: np.ndarray, n_processors: int = None):
239242
"""
240243
Private method to call the whisper.cpp/whisper_full function
241-
244+
242245
:param audio: numpy array of audio data
243246
:param n_processors: if not None, it will run whisper.cpp/whisper_full_parallel with n_processors
244247
:return:
245248
"""
249+
246250
if n_processors:
247251
pw.whisper_full_parallel(self._ctx, self._params, audio, audio.size, n_processors)
248252
else:
@@ -332,4 +336,4 @@ def __del__(self):
332336
Free up resources
333337
:return: None
334338
"""
335-
pw.whisper_free(self._ctx)
339+
pw.whisper_free(self._ctx)

0 commit comments

Comments
 (0)