Skip to content

Commit

Permalink
[BUGFIX] signal only works in main thread of the main interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharrnah committed Dec 12, 2022
1 parent bd02562 commit e629b41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Models/languageClassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@
}
}

model = None

def classify(text):

def download_model():
pretrained_lang_model_file = Path(ct_model_path / "lid218e.bin")
if not pretrained_lang_model_file.exists():
if not pretrained_lang_model_file.is_file():
print(f"Downloading LID (language identification) model...")
downloader.download_extract(MODEL_LINKS["lid218e"]["urls"], str(ct_model_path.resolve()), MODEL_LINKS["lid218e"]["checksum"])

model = fasttext.load_model(str(pretrained_lang_model_file.resolve()))

def classify(text):
global model
pretrained_lang_model_file = Path(ct_model_path / "lid218e.bin")
if not pretrained_lang_model_file.is_file():
print(f"Error: LID (language identification model missing.")
return ""

if model is None:
print(f"Loading LID (language identification) model...")
model = fasttext.load_model(str(pretrained_lang_model_file.resolve()))

text = text.replace("\n", " ")
predictions = model.predict(text, k=1)
Expand Down
8 changes: 8 additions & 0 deletions audioWhisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import settings
import remote_opener
from Models.TextTranslation import texttranslate
from Models import languageClassification
from Models.LLM import flanLanguageModel
import pyaudiowpatch as pyaudio
from whisper import available_models, audio as whisper_audio

Expand Down Expand Up @@ -165,6 +167,12 @@ def main(ctx, devices, device_index, sample_rate, dynamic_energy, open_browser,
print(e)
pass

# Load language identification dependencies
languageClassification.download_model()

# Load FLAN-T5 dependencies
flanLanguageModel.init()

# load the speech recognizer and set the initial energy threshold and pause threshold
r = sr.Recognizer()
r.energy_threshold = energy
Expand Down

0 comments on commit e629b41

Please sign in to comment.