Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pywhispercpp/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def get_params(self) -> dict:
for param in dir(self._params):
if param.startswith('__'):
continue
res[param] = getattr(self._params, param)
try:
res[param] = getattr(self._params, param)
except Exception:
# ignore callback functions
continue
return res

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

def _set_params(self, kwargs: dict) -> None:
"""
Expand All @@ -238,11 +241,12 @@ def _set_params(self, kwargs: dict) -> None:
def _transcribe(self, audio: np.ndarray, n_processors: int = None):
"""
Private method to call the whisper.cpp/whisper_full function

:param audio: numpy array of audio data
:param n_processors: if not None, it will run whisper.cpp/whisper_full_parallel with n_processors
:return:
"""

if n_processors:
pw.whisper_full_parallel(self._ctx, self._params, audio, audio.size, n_processors)
else:
Expand Down Expand Up @@ -332,4 +336,4 @@ def __del__(self):
Free up resources
:return: None
"""
pw.whisper_free(self._ctx)
pw.whisper_free(self._ctx)
Loading