Answer the question
In order to leave comments, you need to log in
How to make voice response in python voice assistant?
hello
i wrote
import speech_recognition as sr
def record_volume():
r = sr.Recognizer()
with sr.Microphone(device_index = 1) 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()
print(f'Вы сказали: {query.lower()}')
except:
print('Error')
while True:
record_volume()
Answer the question
In order to leave comments, you need to log in
You can use JSON, write:
For example body.json
{
"hello": ["hello", "hello", "hello to you too"],
"how are you": ["fine", "just class"]
}
save all this case in JSON format, then in Python open:
answer = open("body.json", "r")
answering = json.load(answer)
randanwers = random.choice(answering["привет"]
print(randanswers)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question