K
K
Kryptonit2020-08-21 22:13:35
Python
Kryptonit, 2020-08-21 22:13:35

Why is the python library not responding to speech?

I watched a video on creating a speech recognizer, a person did it on a poppy, I have win10, there are no errors, everything is installed, here is the code

import speech_recognition as sr
import os
import sys
import webbrowser
import pyttsx3

def talk(words):
    engine = pyttsx3.init()
    engine.say(words)
    engine.runAndWait()
talk("привет, я твой личный помощник, умею открывать некоторые нужные программы")

def command():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        talk('что открыть?')
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source, duration=1)
        audio = r.listen(source)

    try:
        mission = r.recognize_google(audio).lower()
        print('вы сказали'+ mission)
    except sr.UnknownValueError:
        talk('не распознано')
        mission = command()
    return mission

def makeMission(mission):
    if 'привет' in mission:
        talk('выполняю')
        url = 'http://egorkorsakov.ru/'
        webbrowser.open(url)
    elif 'stop' in mission:
        talk('cамоуничтожение запущено')
        sys.exit()
while True:
    makeMission(command())


True, there is a suspicion that the program does not have access to the microphone and this must be set manually somehow (the micro is connected to the computer and is working, but the program does not request access).
Please help figure it out...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Ternick, 2020-08-21
@Ternick

Well, everything works for me through the phone headphones connected to the laptop :)
1) To check access to the microphone, you need to:
1. Open the parameters.
2. Open privacy
3. Open microphone.
4. Check microphone availability:

img
imageda83a97058701f82.png

5. If you do not want to give access to the microphone to all applications, then you should go down to the very bottom and enable this item:
img
image67b2afd221998829.png

2) You need to check if you can hear :)
1. Go to the control panel.
2. Go to the "Sound" item and select your microphone.
3. Go to the "Record" tab.
4. Put a tick on the item "Listen from this device.", put a tick and check the audibility.
Well, in principle, everything that can be offered. Hope it helped in some way :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question