forked from Swayy03/AveryAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenabled.py
77 lines (56 loc) · 1.89 KB
/
enabled.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import cv2
import time
import pyttsx3
from gradio_client import Client, handle_file
import tempfile
import os
# Initialize the TTS engine
engine = pyttsx3.init()
# Function to convert text to speech
def text_to_speech(text):
rate = engine.getProperty('rate')
engine.setProperty('rate', rate - 15 ) # Slows down the speech
# You can adjust the volume (optional)
volume = engine.getProperty('volume')
engine.setProperty('volume', 1.0) # Maximum volume
# You can set the voice type (optional, male/female)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.say(text)
engine.runAndWait()
# Initialize the Gradio client
client = Client("vikhyatk/moondream2")
# Function to process the image and get a description
def process_image(image_path):
result = client.predict(
img=handle_file(image_path),
prompt="Describe this image.",
api_name="/answer_question"
)
return result
def main():
# Set up the camera
cap = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
# Save the frame as a temporary file
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
temp_file_path = temp_file.name
cv2.imwrite(temp_file_path, frame)
# Process the image using Gradio API
description = process_image(temp_file_path)
print(f"Description: {description}")
# Convert the description to speech
text_to_speech(description)
# Clean up the temporary file
os.remove(temp_file_path)
# Wait for 10 seconds before capturing the next image
# Release the camera and close all windows
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()