You've already forked Irene-Voice-Assistant
mirror of
https://github.com/janvarev/Irene-Voice-Assistant.git
synced 2025-11-26 22:50:58 +02:00
v2.1
- добавлен STT через SpeechRecognition - поправлено ридми, чтобы это отразить - поправлен plugin_timer.py для работы с числами - откомментирован plugin_greetings.py
This commit is contained in:
20
README.md
20
README.md
@@ -34,7 +34,8 @@
|
||||
|
||||
### Активные плагины/скиллы (уже в папке plugins)
|
||||
|
||||
Для каждого плагина написано, требуется ли онлайн
|
||||
Для каждого плагина написано, требуется ли онлайн.
|
||||
Для отключения удалите из папки
|
||||
|
||||
**plugin_greetings.py** - приветствие (оффлайн). Пример команды: "ирина, привет"
|
||||
|
||||
@@ -100,6 +101,23 @@
|
||||
* Подключить собственный TTS можно плагином. Как примеры, смотрите plugins_tts_console.py, plugins_tts_pyttsx.py.
|
||||
* Также, создав собственный **runvoice_** файл, можно, при желании, подключить свойт Speech-To-Text движок.
|
||||
|
||||
### Speech-to-Text через SpeechRecognition
|
||||
|
||||
SpeechRecognition - классический движок для запуска распознавания через Google и ряд других сервисов.
|
||||
Для запуска этого распознавания запустите систему через файл **runvaspeechrecognition.py**.
|
||||
|
||||
Для работы потребуется:
|
||||
|
||||
`pip install PyAudio`
|
||||
|
||||
`pip install SpeechRecognition`
|
||||
|
||||
Если есть проблемы с установкой PyAudio, прочтите детали [у EnjiRouz](https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/README.md)
|
||||
|
||||
**Особенности:** распознавание числительных. Одна и та же фраза распознается так:
|
||||
* VOSK: таймер десять секунд
|
||||
* SpeechRecognition (Google): таймер 10 секунд
|
||||
|
||||
### Благодарности
|
||||
|
||||
@EnjiRouz за проект голосового ассистента: https://github.com/EnjiRouz/Voice-Assistant-App, который стал основой (правда, был очень сильно переработан)
|
||||
|
||||
@@ -6,24 +6,23 @@ from vacore import VACore
|
||||
|
||||
# функция на старте
|
||||
def start(core:VACore):
|
||||
manifest = {
|
||||
"name": "Привет",
|
||||
"version": "1.0",
|
||||
"require_online": False,
|
||||
manifest = { # возвращаем настройки плагина - словарь
|
||||
"name": "Привет", # имя
|
||||
"version": "1.0", # версия
|
||||
"require_online": False, # требует ли онлайн?
|
||||
|
||||
"commands": {
|
||||
"commands": { # набор скиллов. Фразы скилла разделены | . Если найдены - вызывается функция
|
||||
"привет|доброе утро": play_greetings,
|
||||
}
|
||||
}
|
||||
return manifest
|
||||
|
||||
def play_greetings(core:VACore, phrase: str):
|
||||
"""
|
||||
Проигрывание случайной приветственной речи
|
||||
"""
|
||||
def play_greetings(core:VACore, phrase: str): # в phrase находится остаток фразы после названия скилла,
|
||||
# если юзер сказал больше
|
||||
# в этом плагине не используется
|
||||
# Проигрывание случайной приветственной речи
|
||||
greetings = [
|
||||
"И тебе привет!",
|
||||
"Рада тебя видеть!",
|
||||
]
|
||||
|
||||
core.play_voice_assistant_speech(greetings[random.randint(0, len(greetings) - 1)])
|
||||
|
||||
@@ -63,6 +63,12 @@ def set_timer(core:VACore, phrase:str):
|
||||
set_timer_real(core,i,txt)
|
||||
return
|
||||
|
||||
txt3 = str(i) + " секунд "
|
||||
if phrase.startswith(txt3):
|
||||
#print(txt,txt2)
|
||||
set_timer_real(core,i,txt)
|
||||
return
|
||||
|
||||
# ставим минуты?
|
||||
for i in range(1,100):
|
||||
txt = num_to_text.num2text(i, female_units_min) + " "
|
||||
@@ -75,6 +81,12 @@ def set_timer(core:VACore, phrase:str):
|
||||
set_timer_real(core,i*60,txt)
|
||||
return
|
||||
|
||||
txt3 = str(i) + " минут "
|
||||
if phrase.startswith(txt3):
|
||||
#print(txt,txt2)
|
||||
set_timer_real(core,i*60,txt)
|
||||
return
|
||||
|
||||
# без указания единиц измерения - ставим минуты
|
||||
for i in range(1,100):
|
||||
txt = num_to_text.num2text(i, female_units_min) + " "
|
||||
@@ -83,6 +95,12 @@ def set_timer(core:VACore, phrase:str):
|
||||
set_timer_real(core,i*60,txt)
|
||||
return
|
||||
|
||||
txt3 = str(i)
|
||||
if phrase.startswith(txt3):
|
||||
#print(txt,txt2)
|
||||
set_timer_real(core,i*60,txt)
|
||||
return
|
||||
|
||||
# спецкейс под одну минуту
|
||||
if phrase.startswith("один ") or phrase.startswith("одна ") or phrase.startswith("одну "):
|
||||
txt = num_to_text.num2text(1, female_units_min)
|
||||
|
||||
84
runvaspeechrecognition.py
Normal file
84
runvaspeechrecognition.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# you need to install:
|
||||
# pip install PyAudio
|
||||
# pip install SpeechRecognition
|
||||
|
||||
# if you have problems with PyAudio install, check this:
|
||||
# https://github.com/EnjiRouz/Voice-Assistant-App/blob/master/README.md
|
||||
|
||||
import speech_recognition
|
||||
import traceback
|
||||
from vacore import VACore
|
||||
|
||||
# most from @EnjiRouz code: https://habr.com/ru/post/529590/
|
||||
|
||||
|
||||
def record_and_recognize_audio(*args: tuple):
|
||||
"""
|
||||
Запись и распознавание аудио
|
||||
"""
|
||||
with microphone:
|
||||
recognized_data = ""
|
||||
|
||||
try:
|
||||
#print("Listening...")
|
||||
audio = recognizer.listen(microphone, 5, 5)
|
||||
|
||||
except speech_recognition.WaitTimeoutError:
|
||||
print("Can you check if your microphone is on, please?")
|
||||
return
|
||||
|
||||
# использование online-распознавания через Google
|
||||
try:
|
||||
#print("Started recognition...")
|
||||
recognized_data = recognizer.recognize_google(audio, language="ru").lower()
|
||||
|
||||
except speech_recognition.UnknownValueError:
|
||||
pass
|
||||
|
||||
# в случае проблем с доступом в Интернет происходит выброс ошибки
|
||||
except speech_recognition.RequestError:
|
||||
print("Check your Internet Connection, please")
|
||||
|
||||
return recognized_data
|
||||
|
||||
# ------------------- vosk ------------------
|
||||
if __name__ == "__main__":
|
||||
# инициализация инструментов распознавания и ввода речи
|
||||
recognizer = speech_recognition.Recognizer()
|
||||
microphone = speech_recognition.Microphone()
|
||||
|
||||
with microphone:
|
||||
# регулирование уровня окружающего шума
|
||||
recognizer.adjust_for_ambient_noise(microphone, duration=2)
|
||||
|
||||
# initing core
|
||||
core = VACore()
|
||||
#core.init_plugin("core")
|
||||
#core.init_plugins(["core"])
|
||||
core.init_with_plugins()
|
||||
|
||||
while True:
|
||||
# старт записи речи с последующим выводом распознанной речи
|
||||
voice_input_str = record_and_recognize_audio()
|
||||
|
||||
if voice_input_str != "":
|
||||
#print("Input: ",voice_input)
|
||||
if core.logPolicy == "all":
|
||||
print("Input: ",voice_input_str)
|
||||
|
||||
try:
|
||||
voice_input = voice_input_str.split(" ")
|
||||
#callname = voice_input[0]
|
||||
for ind in range(len(voice_input)):
|
||||
callname = voice_input[ind]
|
||||
if callname in core.voiceAssNames: # найдено имя ассистента
|
||||
if core.logPolicy == "cmd":
|
||||
print("Input (cmd): ",voice_input_str)
|
||||
|
||||
command_options = " ".join([str(input_part) for input_part in voice_input[(ind+1):len(voice_input)]])
|
||||
core.execute_next(command_options, None)
|
||||
break
|
||||
except Exception as err:
|
||||
print(traceback.format_exc())
|
||||
|
||||
core._update_timers()
|
||||
Reference in New Issue
Block a user