Edit new session
This commit is contained in:
@@ -1,22 +1,42 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .config import GATEWAY_URL, AGENT, log
|
from .config import GATEWAY_URL, AGENT, AGENTS, log
|
||||||
from .audio import record
|
from .audio import record
|
||||||
from .tts import speak, stop_speaking
|
from .tts import speak, stop_speaking
|
||||||
from .llm import ask_agent_stream, is_reset_command
|
from .llm import ask_agent_stream, is_reset_command, VOICE_SESSION_KEY
|
||||||
|
|
||||||
WAKE_THRESHOLD = float(os.getenv("WAKE_THRESHOLD", "0.5"))
|
WAKE_THRESHOLD = float(os.getenv("WAKE_THRESHOLD", "0.5"))
|
||||||
|
|
||||||
|
|
||||||
def _handle_reset(text: str, agent_id: str) -> bool:
|
def _handle_reset(text: str, agent_id: str) -> bool:
|
||||||
"""Команда сброса — на сервере OpenClaw сессия рулится session_key, клиент только сообщает."""
|
"""Команда сброса — отправляет slash-команду /new в OpenClaw (без озвучки ответа)."""
|
||||||
if is_reset_command(text):
|
if not is_reset_command(text):
|
||||||
msg = "Начинаю новую сессию."
|
return False
|
||||||
print(f"🔄 {msg}")
|
|
||||||
speak(msg, agent_id)
|
cfg = AGENTS.get(agent_id, AGENTS["cosmo"])
|
||||||
return True
|
print("🔄 Отправляю /new в OpenClaw")
|
||||||
return False
|
try:
|
||||||
|
cfg["session"].post(
|
||||||
|
f"{cfg['gateway_url']}/v1/chat/completions",
|
||||||
|
headers={
|
||||||
|
"x-ocplatform-model": cfg["voice_model"],
|
||||||
|
"x-openclaw-session-key": cfg.get("session_key", VOICE_SESSION_KEY),
|
||||||
|
},
|
||||||
|
json={
|
||||||
|
"model": cfg["agent"],
|
||||||
|
"stream": False,
|
||||||
|
"messages": [{"role": "user", "content": "/new"}],
|
||||||
|
},
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
log.exception("Не удалось отправить /new")
|
||||||
|
|
||||||
|
msg = "Начинаю новую сессию."
|
||||||
|
print(f"🔄 {msg}")
|
||||||
|
speak(msg, agent_id)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _conversation_loop(agent_id: str, agent_name: str = "Cosmo"):
|
def _conversation_loop(agent_id: str, agent_name: str = "Cosmo"):
|
||||||
@@ -76,6 +96,7 @@ def run_with_porcupine():
|
|||||||
stream = audio.open(rate=16000, channels=1, format=pyaudio.paInt16,
|
stream = audio.open(rate=16000, channels=1, format=pyaudio.paInt16,
|
||||||
input=True, frames_per_buffer=1280)
|
input=True, frames_per_buffer=1280)
|
||||||
|
|
||||||
|
print("✅ Слушаю через OpenWakeWord...")
|
||||||
# print("\nСкажи 'Космо' или 'Люся'...\n") # TODO: после подключения Люси
|
# print("\nСкажи 'Космо' или 'Люся'...\n") # TODO: после подключения Люси
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -70,11 +70,11 @@ def _speak_elevenlabs(text: str, agent_id: str):
|
|||||||
return
|
return
|
||||||
|
|
||||||
voice_settings = VoiceSettings(
|
voice_settings = VoiceSettings(
|
||||||
stability=0.5, # ниже = живее интонация (для multilingual_v2)
|
stability=0.4, # ниже = живее интонация (для multilingual_v2)
|
||||||
similarity_boost=0.8,
|
similarity_boost=0.8,
|
||||||
style=0.0, # выше = эмоциональнее
|
style=0.1, # выше = эмоциональнее
|
||||||
use_speaker_boost=True,
|
use_speaker_boost=True,
|
||||||
speed=1.0
|
speed=1.1
|
||||||
)
|
)
|
||||||
|
|
||||||
audio_stream = client.text_to_speech.convert(
|
audio_stream = client.text_to_speech.convert(
|
||||||
|
|||||||
Reference in New Issue
Block a user