Skip to content

Fix "_init_model" resseting params of Command Prompt #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Changes from 4 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
14 changes: 10 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,8 @@ 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)
# Don't set the params to the default ones here, as it will overwrite the user's params
# 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 +243,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 +338,4 @@ def __del__(self):
Free up resources
:return: None
"""
pw.whisper_free(self._ctx)
pw.whisper_free(self._ctx)