add base device

pull/279/head
Ben Xu 7 months ago
parent 280983597c
commit 0f5c75ca1f

@ -2,7 +2,6 @@ from dotenv import load_dotenv
load_dotenv() # take environment variables from .env. load_dotenv() # take environment variables from .env.
import requests
import subprocess import subprocess
import os import os
import sys import sys
@ -13,7 +12,6 @@ from pynput import keyboard
import json import json
import traceback import traceback
import websockets import websockets
import websockets.sync.client
import queue import queue
from pydub import AudioSegment from pydub import AudioSegment
from pydub.playback import play from pydub.playback import play
@ -155,7 +153,6 @@ class Device:
async def play_audiosegments(self): async def play_audiosegments(self):
"""Plays them sequentially.""" """Plays them sequentially."""
print("play audiosegments called!!!")
mpv_command = ["mpv", "--no-cache", "--no-terminal", "--", "fd://0"] mpv_command = ["mpv", "--no-cache", "--no-terminal", "--", "fd://0"]
mpv_process = subprocess.Popen( mpv_process = subprocess.Popen(
@ -227,7 +224,7 @@ class Device:
stream.stop_stream() stream.stop_stream()
stream.close() stream.close()
print("Recording stopped.") print("Recording stopped.")
# self.playback_latency = time.time() self.playback_latency = time.time()
duration = wav_file.getnframes() / RATE duration = wav_file.getnframes() / RATE
if duration < 0.3: if duration < 0.3:
@ -333,7 +330,6 @@ class Device:
self.fetch_image_from_camera() self.fetch_image_from_camera()
async def message_sender(self, websocket): async def message_sender(self, websocket):
print("message sender running!!!")
while True: while True:
message = await asyncio.get_event_loop().run_in_executor( message = await asyncio.get_event_loop().run_in_executor(
None, send_queue.get None, send_queue.get
@ -356,7 +352,6 @@ class Device:
else: else:
print("\nHold the spacebar to start recording. Press CTRL-C to exit.") print("\nHold the spacebar to start recording. Press CTRL-C to exit.")
print("calling message sender")
asyncio.create_task(self.message_sender(websocket)) asyncio.create_task(self.message_sender(websocket))
while True: while True:
@ -417,7 +412,7 @@ class Device:
# See https://github.com/OpenInterpreter/01/issues/197 # See https://github.com/OpenInterpreter/01/issues/197
try: try:
ws = websockets.connect(WS_URL) ws = websockets.connect(WS_URL)
# await exec_ws_communication(ws) await exec_ws_communication(ws)
except Exception as e: except Exception as e:
logger.error(f"Error while attempting to connect: {e}") logger.error(f"Error while attempting to connect: {e}")
else: else:
@ -433,12 +428,10 @@ class Device:
await asyncio.sleep(2) await asyncio.sleep(2)
async def start_async(self): async def start_async(self):
print("start async called!!!!")
# Configuration for WebSocket # Configuration for WebSocket
WS_URL = f"ws://{self.server_url}" WS_URL = f"ws://{self.server_url}"
# Start the WebSocket communication # Start the WebSocket communication
await self.websocket_communication(WS_URL) asyncio.create_task(self.websocket_communication(WS_URL))
print("ws communication called!")
# Start watching the kernel if it's your job to do that # Start watching the kernel if it's your job to do that
if os.getenv("CODE_RUNNER") == "client": if os.getenv("CODE_RUNNER") == "client":
@ -446,7 +439,6 @@ class Device:
asyncio.create_task(put_kernel_messages_into_queue(send_queue)) asyncio.create_task(put_kernel_messages_into_queue(send_queue))
asyncio.create_task(self.play_audiosegments()) asyncio.create_task(self.play_audiosegments())
print("play audiosegments called!!")
# If Raspberry Pi, add the button listener, otherwise use the spacebar # If Raspberry Pi, add the button listener, otherwise use the spacebar
if current_platform.startswith("raspberry-pi"): if current_platform.startswith("raspberry-pi"):
@ -475,10 +467,8 @@ class Device:
on_press=self.on_press, on_release=self.on_release on_press=self.on_press, on_release=self.on_release
) )
listener.start() listener.start()
print("listener started!!!!!!!!")
def start(self): def start(self):
print("start client called!")
if os.getenv("TEACH_MODE") != "True": if os.getenv("TEACH_MODE") != "True":
asyncio.run(self.start_async()) asyncio.run(self.start_async())
p.terminate() p.terminate()

Loading…
Cancel
Save