a new start

pull/6/head
killian 11 months ago
parent 70f1667bcc
commit f255865000

@ -12,10 +12,13 @@ import queue
import os import os
from threading import Thread from threading import Thread
import uvicorn import uvicorn
import re
from fastapi import FastAPI from fastapi import FastAPI
from threading import Thread from threading import Thread
from starlette.websockets import WebSocket from starlette.websockets import WebSocket
from create_interpreter import create_interpreter from create_interpreter import create_interpreter
from stt import stt
from tts import tts
# Create interpreter # Create interpreter
interpreter = create_interpreter() interpreter = create_interpreter()
@ -27,12 +30,18 @@ conversation_history_path = os.path.join(script_dir, 'conversations', 'user.json
to_user = queue.Queue() to_user = queue.Queue()
to_assistant = queue.Queue() to_assistant = queue.Queue()
# This is so we only say() full sentences
accumulated_text = ""
def is_full_sentence(text):
return text.endswith(('.', '!', '?'))
def split_into_sentences(text):
return re.split(r'(?<=[.!?])\s+', text)
app = FastAPI() app = FastAPI()
@app.post("/computer") @app.post("/computer")
async def read_computer(item: dict): async def read_computer(item: dict):
to_assistant.put(item) to_assistant.put(item)
return {"message": "Item added to queue"}
@app.websocket("/user") @app.websocket("/user")
async def websocket_endpoint(websocket: WebSocket): async def websocket_endpoint(websocket: WebSocket):
@ -75,12 +84,29 @@ def queue_listener():
with open(conversation_history_path, 'w') as file: with open(conversation_history_path, 'w') as file:
json.dump(messages, file) json.dump(messages, file)
accumulated_text = ""
for chunk in interpreter.chat(messages): for chunk in interpreter.chat(messages):
# Send it to the interface # Send it to the user
to_user.put(chunk) to_user.put(chunk)
# Stream audio chunks # Speak full sentences out loud
accumulated_text += chunk["content"]
sentences = split_into_sentences(accumulated_text)
if is_full_sentence(sentences[-1]):
for sentence in sentences:
for audio_chunk in tts(sentence):
to_user.put(audio_chunk)
accumulated_text = ""
else:
for sentence in sentences[:-1]:
for audio_chunk in tts(sentence):
to_user.put(audio_chunk)
accumulated_text = sentences[-1]
if chunk["type"] == "message" and "content" in sentence:
sentence += chunk.get("content")
# If we have a new message, save our progress and go back to the top # If we have a new message, save our progress and go back to the top
if not to_assistant.empty(): if not to_assistant.empty():

@ -6,17 +6,15 @@ sudo apt-get update
sudo apt-get install redis-server sudo apt-get install redis-server
pip install -r requirements.txt pip install -r requirements.txt
# START REDIS ### COMPUTER
redis-cli -h localhost -p 6379 rpush to_interface ""
redis-cli -h localhost -p 6379 rpush to_core ""
# START KERNEL WATCHER
### CORE python computer/kernel_watcher.py &
# START KERNEL WATCHER # START RUN ENDPOINT
python core/kernel_watcher.py & python computer/run.py
# START SST AND TTS SERVICES # START SST AND TTS SERVICES
@ -28,18 +26,12 @@ python core/kernel_watcher.py &
# (disabled, we'll start with hosted services) # (disabled, we'll start with hosted services)
# python core/llm/start.py & # python core/llm/start.py &
# START CORE # START ASSISTANT
python core/start_core.py &
### INTERFACE
# START INTERFACE python assistant/assistant.py &
python interface/interface.py & ### USER
# START DISPLAY # START USER
# (this should be changed to run it in fullscreen / kiosk mode) python user/user.py &
open interface/display.html
Loading…
Cancel
Save