[Narrator] small refactor for clarity.

This commit is contained in:
Ray Smets 2023-11-24 09:47:24 -08:00
parent 604c2b5624
commit d3d540577e
1 changed files with 18 additions and 19 deletions

View File

@ -25,25 +25,6 @@ script = []
narrator = "Sir David Attenborough"
def on_press(key):
if key == keyboard.Key.space:
# When space bar is pressed, run the main function which analyzes the image and generates the audio
_main()
def on_release(key):
if key == keyboard.Key.esc:
# Stop listener
return False
# Create a listener
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
# Start the listener
listener.start()
def encode_image(image_path):
while True:
try:
@ -152,6 +133,24 @@ def main():
time.sleep(5)
def on_press(key):
if key == keyboard.Key.space:
# When space bar is pressed, run the main function which analyzes the image and generates the audio
_main()
def on_release(key):
if key == keyboard.Key.esc:
# Stop listener
return False
# Create a listener
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
# Start the listener
listener.start()
if isPhotoBooth:
print(f"Press the spacebar to trigger {narrator}")