Adjust args microphone stream example, util function bugfix [skip ci]

This commit is contained in:
dscripka 2023-06-13 21:23:57 -04:00
parent c8833f12b2
commit cdd1e529ab
2 changed files with 29 additions and 4 deletions

View file

@ -27,6 +27,20 @@ parser.add_argument(
default=1280,
required=True
)
parser.add_argument(
"--model_path",
help="The path of a specific model to load",
type=str,
default="",
required=False
)
parser.add_argument(
"--inference_framework",
help="The inference framework to use (either 'onnx' or 'tflite'",
type=str,
default='tflite',
required=False
)
args=parser.parse_args()
@ -39,7 +53,12 @@ audio = pyaudio.PyAudio()
mic_stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
# Load pre-trained openwakeword models
owwModel = Model()
if args.model_path != "":
owwModel = Model(wakeword_models=[args.model_path], inference_framework=args.inference_framework)
else:
owwModel = Model(inference_framework=args.inference_framework)
n_models = len(owwModel.models.keys())
# Run capture loop continuosly, checking for wakewords
if __name__ == "__main__":
@ -48,7 +67,7 @@ if __name__ == "__main__":
print("#"*100)
print("Listening for wakewords...")
print("#"*100)
print("\n"*13)
print("\n"*(n_models*3))
while True:
# Get audio
@ -73,5 +92,5 @@ if __name__ == "__main__":
"""
# Print results table
print("\033[F"*14)
print("\033[F"*(4*n_models+1))
print(output_string_header, " ", end='\r')

View file

@ -438,6 +438,7 @@ def bulk_predict(
wakeword_models: List[str],
prediction_function: str = 'predict_clip',
ncpu: int = 1,
inference_framework = "tflite",
**kwargs
):
"""
@ -445,10 +446,14 @@ def bulk_predict(
Args:
input_paths (List[str]): The list of input file to predict
wakeword_model_path (List[str])): The paths to the wakeword ONNX model files
wakeword_models (List[str])): The paths to the wakeword model files
prediction_function (str): The name of the method used to predict on the input audio files
(default is the `predict_clip` method)
ncpu (int): How many processes to create (up to max of available CPUs)
inference_framework (str): The inference framework to use when for model prediction. Options are
"tflite" or "onnx". The default is "tflite" as this results in better
efficiency on common platforms (x86, ARM64), but in some deployment
scenarios ONNX models may be preferable.
kwargs (dict): Any other keyword arguments to pass to the model initialization or
specified prediction function
@ -472,6 +477,7 @@ def bulk_predict(
if key in openwakeword.Model.__init__.__code__.co_varnames}
oww = openwakeword.Model(
wakeword_models=wakeword_models,
inference_framework=inference_framework,
**filtered_kwargs
)
mdls.append(oww)