Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa639ffae9 | |||
| 3d12032942 | |||
| 06b70afdce | |||
| 91cd9b02df | |||
| ba52d86754 | |||
| 4a0155413e | |||
| 6a6efe8dd6 | |||
| 08b6f95a67 | |||
| d2b60b53c4 | |||
| a7abfe44b4 | |||
| 3fb31e60ea | |||
| c03811cb87 |
+4
-2
@@ -72,7 +72,9 @@ weather:
|
|||||||
- возможен дождь сегодня?
|
- возможен дождь сегодня?
|
||||||
- прогноз погоды на сегодня
|
- прогноз погоды на сегодня
|
||||||
- погода
|
- погода
|
||||||
home_assistant:
|
home_assistant_execute:
|
||||||
- включи телевизор
|
- включи телевизор
|
||||||
- выключи телевизор
|
- выключи телевизор
|
||||||
- начни уборку
|
- начни уборку
|
||||||
|
home_assistant_get:
|
||||||
|
- тест
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
пылесос:
|
||||||
|
- entity_id:vacuum.roborock_vacuum_m1s
|
||||||
|
- state:находится в
|
||||||
|
- attributes.battery_level:а его уровень зарядки
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
|
import yaml
|
||||||
|
from fuzzywuzzy import process
|
||||||
|
|
||||||
from data import config
|
from data import config
|
||||||
|
|
||||||
@@ -7,6 +9,7 @@ class HomeAssistant:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.url = "http://192.168.0.112:9999/api"
|
self.url = "http://192.168.0.112:9999/api"
|
||||||
self.token = config.HOME_ASSISTANT_TOKEN
|
self.token = config.HOME_ASSISTANT_TOKEN
|
||||||
|
self.HA_CMD_LIST = yaml.safe_load(open('data/home_assistant_entities.yaml', encoding='utf8'))
|
||||||
|
|
||||||
def get_info(self, state):
|
def get_info(self, state):
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
@@ -15,6 +18,9 @@ class HomeAssistant:
|
|||||||
"Authorization": "Bearer " + self.token
|
"Authorization": "Bearer " + self.token
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
for entity in response.json():
|
||||||
|
if entity["entity_id"] == state:
|
||||||
|
return entity
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def send_process(self, command="выключи телевизор"):
|
def send_process(self, command="выключи телевизор"):
|
||||||
@@ -29,3 +35,33 @@ class HomeAssistant:
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def voice_to_name(self, voice: str) -> str:
|
||||||
|
words = voice.lower().split()
|
||||||
|
best_match = None
|
||||||
|
highest_score = 0
|
||||||
|
for word in words:
|
||||||
|
result, score = process.extractOne(word, self.HA_CMD_LIST.keys())
|
||||||
|
if score > highest_score:
|
||||||
|
highest_score = score
|
||||||
|
best_match = result
|
||||||
|
return best_match
|
||||||
|
|
||||||
|
def validate_info(self, name: str):
|
||||||
|
answer = name
|
||||||
|
entity_config = self.HA_CMD_LIST.get(name)
|
||||||
|
if entity_config:
|
||||||
|
# Создание словаря, разделяя каждый элемент конфигурации на ключ и значение
|
||||||
|
entity_details = {item.split(':')[0]: item.split(':')[1] for item in entity_config}
|
||||||
|
entity_id = entity_details.pop("entity_id", None)
|
||||||
|
if entity_id:
|
||||||
|
responses = self.get_info(entity_id)
|
||||||
|
for attribute_path, label in entity_details.items():
|
||||||
|
response = responses
|
||||||
|
try:
|
||||||
|
for attribute in attribute_path.split("."):
|
||||||
|
response = response[attribute]
|
||||||
|
answer += f" {label} {response}"
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
return answer
|
||||||
|
|||||||
+2
-2
@@ -11,7 +11,7 @@ from fuzzywuzzy import fuzz
|
|||||||
from pvrecorder import PvRecorder
|
from pvrecorder import PvRecorder
|
||||||
|
|
||||||
from data import config
|
from data import config
|
||||||
from modules.HomeAssistant import HomeAssistant
|
from modules import HomeAssistant
|
||||||
from utils import download_models, execute_cmd, play
|
from utils import download_models, execute_cmd, play
|
||||||
|
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ class Jarvis:
|
|||||||
self.recorder = None
|
self.recorder = None
|
||||||
self.CDIR = os.getcwd()
|
self.CDIR = os.getcwd()
|
||||||
self.VA_CMD_LIST = yaml.safe_load(open('data/commands.yaml', encoding='utf8'))
|
self.VA_CMD_LIST = yaml.safe_load(open('data/commands.yaml', encoding='utf8'))
|
||||||
self.home_assistant = HomeAssistant()
|
self.home_assistant = HomeAssistant.HomeAssistant()
|
||||||
self.porcupine = pvporcupine.create(
|
self.porcupine = pvporcupine.create(
|
||||||
access_key=config.PICOVOICE_TOKEN,
|
access_key=config.PICOVOICE_TOKEN,
|
||||||
keywords=['jarvis'],
|
keywords=['jarvis'],
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
from modules.HomeAssistant import HomeAssistant
|
|
||||||
|
|
||||||
home_assistant = HomeAssistant()
|
|
||||||
response = home_assistant.get_info("")
|
|
||||||
print(response.text)
|
|
||||||
|
|||||||
@@ -7,5 +7,9 @@ def execute_cmd(self, cmd: str, recognized_phrase: str, voice: str):
|
|||||||
self.play("off", True)
|
self.play("off", True)
|
||||||
self.porcupine.delete()
|
self.porcupine.delete()
|
||||||
exit(0)
|
exit(0)
|
||||||
elif cmd == 'home_assistant':
|
elif cmd == 'home_assistant_execute':
|
||||||
self.home_assistant.send_process(recognized_phrase)
|
self.home_assistant.send_process(recognized_phrase)
|
||||||
|
elif cmd == 'home_assistant_get':
|
||||||
|
entity_name = self.home_assistant.voice_to_name(voice)
|
||||||
|
entity_info = self.home_assistant.validate_info(entity_name)
|
||||||
|
print(entity_info)
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import time
|
|
||||||
|
|
||||||
import sounddevice as sd
|
|
||||||
import torch
|
|
||||||
|
|
||||||
language = 'ru'
|
|
||||||
model_id = 'ru_v3'
|
|
||||||
sample_rate = 48000 # 48000
|
|
||||||
speaker = 'aidar' # aidar, baya, kseniya, xenia, random
|
|
||||||
put_accent = True
|
|
||||||
put_yo = True
|
|
||||||
device = torch.device('cpu') # cpu или gpu
|
|
||||||
text = "Хауди Хо, друзья!!!"
|
|
||||||
|
|
||||||
model, _ = torch.hub.load(repo_or_dir='snakers4/silero-models',
|
|
||||||
model='silero_tts',
|
|
||||||
language=language,
|
|
||||||
speaker=model_id)
|
|
||||||
model.to(device)
|
|
||||||
|
|
||||||
|
|
||||||
def va_speak(what: str):
|
|
||||||
audio = model.apply_tts(text=what + "..",
|
|
||||||
speaker=speaker,
|
|
||||||
sample_rate=sample_rate,
|
|
||||||
put_accent=put_accent,
|
|
||||||
put_yo=put_yo)
|
|
||||||
|
|
||||||
sd.play(audio, sample_rate * 1.05)
|
|
||||||
time.sleep((len(audio) / sample_rate) + 0.5)
|
|
||||||
sd.stop()
|
|
||||||
Reference in New Issue
Block a user