openwakeword_test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. if __name__ == '__main__':
  2. print("Starting...")
  3. from RealtimeSTT import AudioToTextRecorder
  4. import logging
  5. detected = False
  6. say_wakeword_str = "Listening for wakeword 'samantha'."
  7. def on_wakeword_detected():
  8. global detected
  9. detected = True
  10. def on_recording_stop():
  11. print ("Transcribing...")
  12. def on_wakeword_timeout():
  13. global detected
  14. if not detected:
  15. print(f"Timeout. {say_wakeword_str}")
  16. detected = False
  17. def on_wakeword_detection_start():
  18. print(f"\n{say_wakeword_str}")
  19. def on_recording_start():
  20. print ("Recording...")
  21. def on_vad_detect_start():
  22. print()
  23. print()
  24. def text_detected(text):
  25. print(f">> {text}")
  26. with AudioToTextRecorder(
  27. spinner=False,
  28. model="large-v2",
  29. language="en",
  30. wakeword_backend="oww",
  31. wake_words_sensitivity=0.35,
  32. # openwakeword_model_paths="model_wake_word1.onnx,model_wake_word2.onnx",
  33. 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
  34. on_wakeword_detected=on_wakeword_detected,
  35. on_recording_start=on_recording_start,
  36. on_recording_stop=on_recording_stop,
  37. on_wakeword_timeout=on_wakeword_timeout,
  38. on_wakeword_detection_start=on_wakeword_detection_start,
  39. on_vad_detect_start=on_vad_detect_start,
  40. wake_word_buffer_duration=1,
  41. ) as recorder:
  42. while (True):
  43. recorder.text(text_detected)