audio_recorder_tester.py 850 B

12345678910111213141516171819202122232425262728293031
  1. from RealtimeSTT import AudioToTextRecorder
  2. def recording_started():
  3. print(" >> recording started... ", end="", flush=True)
  4. def recording_finished():
  5. print("recording finished...")
  6. recorder = AudioToTextRecorder(language="de", on_recording_started=recording_started, on_recording_finished=recording_finished)
  7. # usage 1:
  8. # automatic detection of speech start and end, waits for text to be returned
  9. print ("Say something...")
  10. print (f'TEXT: "{recorder.text()}"')
  11. print()
  12. # usage 2:
  13. # manual trigger of speech start and end
  14. print("Tap space when you're ready.")
  15. import keyboard, time
  16. keyboard.wait('space')
  17. while keyboard.is_pressed('space'): time.sleep(0.1)
  18. recorder.start()
  19. print("tap space when you're done... ", end="", flush=True)
  20. while not keyboard.is_pressed('space'): time.sleep(0.1)
  21. print (f'TEXT: "{recorder.stop().text()}"')