openwakeword_test.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. if __name__ == '__main__':
  2. print("Starting...")
  3. from RealtimeSTT import AudioToTextRecorder
  4. detected = False
  5. say_wakeword_str = "Listening for wakeword 'samantha'."
  6. def on_wakeword_detected():
  7. global detected
  8. detected = True
  9. def on_recording_stop():
  10. print ("Transcribing...")
  11. def on_wakeword_timeout():
  12. global detected
  13. if not detected:
  14. print(f"Timeout. {say_wakeword_str}")
  15. detected = False
  16. def on_wakeword_detection_start():
  17. print(f"\n{say_wakeword_str}")
  18. def on_recording_start():
  19. print ("Recording...")
  20. def on_vad_detect_start():
  21. print()
  22. print()
  23. def text_detected(text):
  24. print(f">> {text}")
  25. with AudioToTextRecorder(
  26. spinner=False,
  27. model="large-v2",
  28. language="en",
  29. wakeword_backend="oww",
  30. wake_words_sensitivity=0.35,
  31. # openwakeword_model_paths="model_wake_word1.onnx,model_wake_word2.onnx",
  32. openwakeword_model_paths="suh_man_tuh.onnx,suh_mahn_thuh.onnx", # load these test models from https://huggingface.co/KoljaB/SamanthaOpenwakeword/tree/main and save in tests folder
  33. on_wakeword_detected=on_wakeword_detected,
  34. on_recording_start=on_recording_start,
  35. on_recording_stop=on_recording_stop,
  36. on_wakeword_timeout=on_wakeword_timeout,
  37. on_wakeword_detection_start=on_wakeword_detection_start,
  38. on_vad_detect_start=on_vad_detect_start,
  39. wake_word_buffer_duration=1,
  40. ) as recorder:
  41. while (True):
  42. recorder.text(text_detected)