From a032cea8447ae72bca10eb9f2deea2aeeabe90a5 Mon Sep 17 00:00:00 2001 From: "balint.lendvai" Date: Thu, 16 Nov 2023 11:42:58 +0100 Subject: [PATCH] feat: grabs screenshot instead webcam sarcastic technical lead prompt --- .gitignore | 2 ++ README.md | 6 +++++- capture.py | 62 ++++++++++++++++++----------------------------------- narrator.py | 8 +++---- 4 files changed, 32 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index bff6c45..d91c5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /venv /frames /narration +/screeshots +.vscode diff --git a/README.md b/README.md index f7cf488..50028f3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ -# narrator +# sarcastic narrator +Sarcastic David Attenborough narrates what you are doing based on your screen + +Forked from this project: +https://github.com/cbh123/narrator David Attenborough narrates your life. https://twitter.com/charliebholtz/status/1724815159590293764 diff --git a/capture.py b/capture.py index c94dfa3..1061b7d 100644 --- a/capture.py +++ b/capture.py @@ -1,46 +1,26 @@ -import cv2 +from PIL import ImageGrab +import os import time -from PIL import Image -import numpy as np -# Folder -folder = "frames" +# Create a folder to store the screenshot if it doesn't exist +folder = "screenshots" +if not os.path.exists(folder): + os.makedirs(folder) -# Initialize the webcam -cap = cv2.VideoCapture(0) +# Constant filename for the screenshot +filename = os.path.join(folder, "screenshot.png") -# Check if the webcam is opened correctly -if not cap.isOpened(): - raise IOError("Cannot open webcam") +# Function to take a screenshot +def take_screenshot(filename): + # Capture the entire screen + screen = ImageGrab.grab() + # Save the image file + screen.save(filename) -# Wait for the camera to initialize and adjust light levels -time.sleep(2) - -while True: - ret, frame = cap.read() - if ret: - # Convert the frame to a PIL image - pil_img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) - - # Resize the image - max_size = 250 - ratio = max_size / max(pil_img.size) - new_size = tuple([int(x*ratio) for x in pil_img.size]) - resized_img = pil_img.resize(new_size, Image.LANCZOS) - - # Convert the PIL image back to an OpenCV image - frame = cv2.cvtColor(np.array(resized_img), cv2.COLOR_RGB2BGR) - - # Save the frame as an image file - print("📸 Say cheese! Saving frame.") - path = f"{folder}/frame.jpg" - cv2.imwrite(path, frame) - else: - print("Failed to capture image") - - # Wait for 2 seconds - time.sleep(2) - -# Release the camera and close all windows -cap.release() -cv2.destroyAllWindows() +try: + while True: + take_screenshot(filename) + print(f"Screenshot saved as {filename}") + time.sleep(5) # Wait for 5 seconds before taking the next screenshot +except KeyboardInterrupt: + print("Stopped taking screenshots") diff --git a/narrator.py b/narrator.py index 0435b47..ce87a9e 100644 --- a/narrator.py +++ b/narrator.py @@ -24,7 +24,8 @@ def encode_image(image_path): def play_audio(text): - audio = generate(text=text, voice="ENfvYmv6CRqDodDZTieQ", model="eleven_turbo_v2") + // voice param will be your Voice_id coming from the Elevenlabs API + audio = generate(text=text, voice="ELEVENLABS_SELECTED_VOICE_ID", model="eleven_turbo_v2") unique_id = base64.urlsafe_b64encode(os.urandom(30)).decode("utf-8").rstrip("=") dir_path = os.path.join("narration", unique_id) @@ -59,8 +60,7 @@ def analyze_image(base64_image, script): { "role": "system", "content": """ - You are Sir David Attenborough. Narrate the picture of the human as if it is a nature documentary. - Make it snarky and funny. Don't repeat yourself. Make it short. If I do anything remotely interesting, make a big deal about it! + You are a senior frontend technical lead whos task is to sarcastically review other programmers pure code snippets on screenshots you get. be short, harsh, and very sarcastic. Roast me in 5-8 sentences in the response. """, }, ] @@ -77,7 +77,7 @@ def main(): while True: # path to your image - image_path = os.path.join(os.getcwd(), "./frames/frame.jpg") + image_path = os.path.join(os.getcwd(), "./screenshots/screenshot.png") # getting the base64 encoding base64_image = encode_image(image_path)