From f82ad437f675356f61c5c6c69098311dee04e937 Mon Sep 17 00:00:00 2001 From: horhik Date: Mon, 16 Aug 2021 10:42:47 +0300 Subject: [PATCH] add voice assistant --- .../__pycache__/process_text.cpython-39.pyc | Bin 0 -> 254 bytes voice-assistant/config.json | 5 ++ voice-assistant/main.py | 49 ++++++++++++++++++ voice-assistant/process_text.py | 2 + 4 files changed, 56 insertions(+) create mode 100644 voice-assistant/__pycache__/process_text.cpython-39.pyc create mode 100644 voice-assistant/config.json create mode 100755 voice-assistant/main.py create mode 100644 voice-assistant/process_text.py diff --git a/voice-assistant/__pycache__/process_text.cpython-39.pyc b/voice-assistant/__pycache__/process_text.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b52cad37eaefd4736d75a18c80d6856edd0a1f3e GIT binary patch literal 254 zcmYe~<>g`kf1H z48+AOK%#~LsD{yRC6KtqQj%IxQUsC)6ThtVGxBp&fkaV8X10EEeoCr-K~a8IYH~@j zep!BIa;k1(adBpGNn&0JNFq74xHukUgkC}AEgob6kdeh8Co(V=fh_gYgwP1PAS`B} V+$|29-29Z%oK!oIuFpWs006f$GWY-h literal 0 HcmV?d00001 diff --git a/voice-assistant/config.json b/voice-assistant/config.json new file mode 100644 index 0000000..020cfc6 --- /dev/null +++ b/voice-assistant/config.json @@ -0,0 +1,5 @@ +{ + "Ну привет": { + "trigers": ["kek",] + } +} diff --git a/voice-assistant/main.py b/voice-assistant/main.py new file mode 100755 index 0000000..a5c0963 --- /dev/null +++ b/voice-assistant/main.py @@ -0,0 +1,49 @@ +#!/bin/python +import speech_recognition as sr +import pyttsx3 +from process_text import process_text +botname = "андрей" +text = 'какой-нибудь текст' +tts = pyttsx3.init() +rate = tts.getProperty('rate') #Скорость произношения +tts.setProperty('rate', rate+400) + +volume = tts.getProperty('volume') #Громкость голоса +tts.setProperty('volume', volume+0.9) + +voices = tts.getProperty('voices') + +# Задать голос по умолчанию +tts.setProperty('voice', 'en') + +#for voice in voices: +# print(voice.name) +# if voice.name == 'russian': +# tts.setProperty('voice', voice.id) + +def say(text): + tts.say(text) + tts.runAndWait() +def process_speech(text): + #if (text.find("слушай " + botname)): +# say("Привет сучка, что тебе надо?") +# else: + say(text) + +def record_volume(): + r = sr.Recognizer() + with sr.Microphone(device_index = 14) as source: + print('Настраиваюсь.') + r.adjust_for_ambient_noise(source, duration=0.5) #настройка посторонних шумов + print('Слушаю...') + audio = r.listen(source) + print('Услышала.') + try: + query = r.recognize_google(audio, language = 'ru-RU') + text = query.lower() + process_speech(text) + except: + print('Error') + +while True: + record_volume() diff --git a/voice-assistant/process_text.py b/voice-assistant/process_text.py new file mode 100644 index 0000000..7504fc3 --- /dev/null +++ b/voice-assistant/process_text.py @@ -0,0 +1,2 @@ +def process_text(text): + return(text)