P
P
Python Newbie2021-08-05 20:55:19
Python
Python Newbie, 2021-08-05 20:55:19

How to make voice response in python voice assistant?

hello

i wrote

the code
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()
which recognizes speech.

How do I make voice responses?
Please tell me the best way.

I have python 3.8
windows 10 x64

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-08-05
@Levman5

Okay Google, python text to speech .

A
Agrael313 Zashefrovano, 2021-10-14
@Lazarusnode13

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)

and everything is ok))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question