Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f1aa07507 | |||
| 6021db52aa | |||
| a2375e6daf | |||
| 8504126d4a | |||
| 4dc4ffa58c | |||
| 26b38811cc | |||
| 1d63461e35 | |||
| 5f1e2e67a4 | |||
| c23b1d42bf | |||
| b2866d073c | |||
| a889c68e40 |
+2
-4
@@ -72,9 +72,7 @@ weather:
|
|||||||
- возможен дождь сегодня?
|
- возможен дождь сегодня?
|
||||||
- прогноз погоды на сегодня
|
- прогноз погоды на сегодня
|
||||||
- погода
|
- погода
|
||||||
home_assistant_execute:
|
home_assistant:
|
||||||
- включи телевизор
|
- включи телевизор
|
||||||
- выключи телевизор
|
- выключи телевизор
|
||||||
- начни уборку
|
- начни уборку
|
||||||
home_assistant_get:
|
|
||||||
- тест
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
пылесос:
|
|
||||||
- entity_id:vacuum.roborock_vacuum_m1s
|
|
||||||
- state:находится в
|
|
||||||
- attributes.battery_level:а его уровень зарядки
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
import requests
|
import requests
|
||||||
import yaml
|
|
||||||
from fuzzywuzzy import process
|
|
||||||
|
|
||||||
from data import config
|
from data import config
|
||||||
|
|
||||||
@@ -9,7 +7,6 @@ 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(
|
||||||
@@ -18,9 +15,6 @@ 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="выключи телевизор"):
|
||||||
@@ -35,33 +29,3 @@ 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 import HomeAssistant
|
from modules.HomeAssistant 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.HomeAssistant()
|
self.home_assistant = HomeAssistant()
|
||||||
self.porcupine = pvporcupine.create(
|
self.porcupine = pvporcupine.create(
|
||||||
access_key=config.PICOVOICE_TOKEN,
|
access_key=config.PICOVOICE_TOKEN,
|
||||||
keywords=['jarvis'],
|
keywords=['jarvis'],
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from modules.HomeAssistant import HomeAssistant
|
||||||
|
|
||||||
|
home_assistant = HomeAssistant()
|
||||||
|
response = home_assistant.get_info("")
|
||||||
|
print(response.text)
|
||||||
|
|||||||
@@ -7,9 +7,5 @@ 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_execute':
|
elif cmd == 'home_assistant':
|
||||||
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)
|
|
||||||
|
|||||||
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
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