From 4fda47955bd3cf8bbd509648457bc0bb3c6c5103 Mon Sep 17 00:00:00 2001 From: Menonro Date: Wed, 20 Mar 2024 17:11:32 +0600 Subject: [PATCH 1/3] Hiding the ffmpeg popup that appears momentarily On Windows there is a problem due to which FFMPEG running in the background becomes small for a second during startup. Context: "Whisper" is used in conjunction with FastAPI and uvicorn. The service is started using pm2. The problem does not exist if you run it manually from a regular console using "python main.py" Demonstration of the problem before and after https://youtu.be/IsEavmzQOv8 --- whisper/audio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/whisper/audio.py b/whisper/audio.py index cf6c66ad9..0a5032e2c 100644 --- a/whisper/audio.py +++ b/whisper/audio.py @@ -1,6 +1,6 @@ import os from functools import lru_cache -from subprocess import CalledProcessError, run +from subprocess import CalledProcessError, run, CREATE_NO_WINDOW from typing import Optional, Union import numpy as np @@ -55,7 +55,7 @@ def load_audio(file: str, sr: int = SAMPLE_RATE): ] # fmt: on try: - out = run(cmd, capture_output=True, check=True).stdout + out = run(cmd, capture_output=True, check=True, creationflags=CREATE_NO_WINDOW).stdout except CalledProcessError as e: raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e From 2566f688eed1c60e40ec6bfbd863a225c73963db Mon Sep 17 00:00:00 2001 From: Menonro Date: Wed, 20 Mar 2024 17:41:05 +0600 Subject: [PATCH 2/3] Hiding a window is now only for Windows systems --- whisper/audio.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/whisper/audio.py b/whisper/audio.py index 0a5032e2c..72e1a1f15 100644 --- a/whisper/audio.py +++ b/whisper/audio.py @@ -55,7 +55,10 @@ def load_audio(file: str, sr: int = SAMPLE_RATE): ] # fmt: on try: - out = run(cmd, capture_output=True, check=True, creationflags=CREATE_NO_WINDOW).stdout + creationflags = None + if os.name == 'nt': + creationflags = CREATE_NO_WINDOW + out = run(cmd, capture_output=True, check=True, creationflags=creationflags).stdout except CalledProcessError as e: raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e From 144640ded4aa2ce62e0519b58b855989a2a64f26 Mon Sep 17 00:00:00 2001 From: Menonro Date: Wed, 20 Mar 2024 21:57:31 +0600 Subject: [PATCH 3/3] Fixed incorrect import on non-Windows systems --- whisper/audio.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/whisper/audio.py b/whisper/audio.py index 72e1a1f15..dec4800d2 100644 --- a/whisper/audio.py +++ b/whisper/audio.py @@ -1,6 +1,6 @@ import os from functools import lru_cache -from subprocess import CalledProcessError, run, CREATE_NO_WINDOW +from subprocess import CalledProcessError, run from typing import Optional, Union import numpy as np @@ -57,6 +57,7 @@ def load_audio(file: str, sr: int = SAMPLE_RATE): try: creationflags = None if os.name == 'nt': + from subprocess import CREATE_NO_WINDOW creationflags = CREATE_NO_WINDOW out = run(cmd, capture_output=True, check=True, creationflags=creationflags).stdout except CalledProcessError as e: