Skip to content

Commit

Permalink
fix: use importlib to find model path
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Dec 28, 2023
1 parent 96e06ba commit 4ed0003
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cython/pocketsphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import collections
import importlib.util
import os
import signal
from contextlib import contextmanager
Expand Down Expand Up @@ -81,7 +82,10 @@ def get_model_path(subpath=None):
"""
model_path = pocketsphinx._ps_default_modeldir()
if model_path is None:
model_path = os.path.join(os.path.dirname(__file__), "model")
# Use importlib to find things (so editable installs work)
model_path = importlib.util.find_spec(
"pocketsphinx.model"
).submodule_search_locations[0]
if subpath is not None:
return os.path.join(model_path, subpath)
else:
Expand Down Expand Up @@ -181,6 +185,7 @@ class AudioFile(Pocketsphinx):
simple.
"""

def __init__(self, audio_file=None, **kwargs):
signal.signal(signal.SIGINT, self.stop)

Expand Down Expand Up @@ -239,6 +244,7 @@ def __init__(self, **kwargs):

try:
import sounddevice

assert sounddevice
except Exception as e:
# In case PortAudio is not present, for instance
Expand Down

0 comments on commit 4ed0003

Please sign in to comment.