Skip to content

Commit

Permalink
Fix Windows DLL loading (chidiwilliams#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Nov 13, 2022
1 parent 59d491a commit 7f0c206
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches:
- master
- main
tags:
- '*'
pull_request:
Expand Down
5 changes: 4 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from __version__ import VERSION
from transcriber import FileTranscriber, OutputFormat, RecordingTranscriber
from whispr import Task
from whispr import LOADED_WHISPER_DLL, Task

APP_NAME = 'Buzz'

Expand Down Expand Up @@ -553,6 +553,8 @@ def __init__(self, parent: Optional[QWidget], *args):
super().__init__('Buzz', 'Buzz', parent, *args)

def enable_ggml_inference(self):
if LOADED_WHISPER_DLL is False:
return False
return self.value(self.ENABLE_GGML_INFERENCE, False)


Expand Down Expand Up @@ -804,6 +806,7 @@ def __init__(self, title: str, w: int, h: int, parent: Optional[QWidget], *args)
bool(self.settings.enable_ggml_inference()))
enable_ggml_inference_action.triggered.connect(
self.on_toggle_enable_ggml_inference)
enable_ggml_inference_action.setDisabled(LOADED_WHISPER_DLL is False)

settings_menu = menu.addMenu("&Settings")
settings_menu.addAction(enable_ggml_inference_action)
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
os.path.abspath(__file__)))
os.environ["PATH"] += os.pathsep + app_dir

# Add the app directory to the DLL list: https://stackoverflow.com/a/64303856
os.add_dll_directory(app_dir)

if __name__ == "__main__":
# Fixes opening new window when app has been frozen on Windows:
# https://stackoverflow.com/a/33979091
Expand Down
14 changes: 12 additions & 2 deletions whispr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@
from tqdm import tqdm
from whisper import Whisper

import whisper_cpp
from conn import pipe_stderr

# Catch exception from whisper.dll not getting loaded.
# TODO: Remove flag and try-except when issue with loading
# the DLL in some envs is fixed.
LOADED_WHISPER_DLL = False
try:
import whisper_cpp
LOADED_WHISPER_DLL = True
except ImportError:
logging.exception('')


class Stopped(Exception):
pass
Expand All @@ -41,7 +50,8 @@ class Task(enum.Enum):
def whisper_cpp_params(
language: str, task: Task, word_level_timings: bool,
print_realtime=False, print_progress=False,):
params = whisper_cpp.whisper_full_default_params(whisper_cpp.WHISPER_SAMPLING_GREEDY)
params = whisper_cpp.whisper_full_default_params(
whisper_cpp.WHISPER_SAMPLING_GREEDY)
params.print_realtime = print_realtime
params.print_progress = print_progress
params.language = whisper_cpp.String(language.encode('utf-8'))
Expand Down

0 comments on commit 7f0c206

Please sign in to comment.