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
- поддержки работы с контекстом (см. справку) - демо-игра работы с контекстом Больше-меньше и Больше-меньше альтернативная (два стиля) - базовые реализации используют работы с контекстом - runva_webapi.py - теперь вызовы core._update_timers делаются через периодичпеские вызовы HTTP, и через таймер. Webapi стало значительно устойчивей - справка содержит информацию о контексте
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
# 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 != "":
|
|
core.run_input_str(voice_input_str)
|
|
|
|
|
|
core._update_timers() |