-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (38 loc) · 1.37 KB
/
main.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
from camera_processing import *
from audio_processing import *
from pulse import *
import threading
import time
import subprocess
from gpiozero import Button
import warnings
import pulsectl
import requests
API_BASE_URL = "https://admittedly-wired-halibut.ngrok-free.app"
warnings.simplefilter('ignore')
button1 = Button(2)
button2 = Button(4)
volume_control = VolumeControl(button2)
volume_control.start()
while True:
if button1.is_pressed:
image_path = capture_surroundings()
with open(image_path, 'rb') as image_file:
files = {'file': (image_path, image_file, 'image/jpeg')}
response = requests.post(f"{API_BASE_URL}/object-detection/", files=files)
if response.status_code != 422:
audio_file_path = "audio.mp3"
with open(audio_file_path, "wb") as audio_file:
audio_file.write(response.content)
play_audio(audio_file_path)
else:
query = take_command()
payload = {"query": query}
headers = {"Content-Type": "application/json"}
response = requests.post(f"{API_BASE_URL}/voice-assistant/", json=payload, headers=headers)
audio_file_path = "audio.mp3"
with open(audio_file_path, "wb") as audio_file:
audio_file.write(response.content)
play_audio(audio_file_path)
volume_control.stop()
volume_control.join()