add voice assistant
This commit is contained in:
commit
f82ad437f6
BIN
voice-assistant/__pycache__/process_text.cpython-39.pyc
Normal file
BIN
voice-assistant/__pycache__/process_text.cpython-39.pyc
Normal file
Binary file not shown.
5
voice-assistant/config.json
Normal file
5
voice-assistant/config.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"Ну привет": {
|
||||||
|
"trigers": ["kek",]
|
||||||
|
}
|
||||||
|
}
|
49
voice-assistant/main.py
Executable file
49
voice-assistant/main.py
Executable file
|
@ -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()
|
2
voice-assistant/process_text.py
Normal file
2
voice-assistant/process_text.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
def process_text(text):
|
||||||
|
return(text)
|
Loading…
Reference in a new issue