如何检查是否有声音,如果有,则通过警报声音提醒用户?

时间:2019-09-15 06:09:19

标签: python-3.x raspberry-pi3 voice-recognition espeak

通过Web应用程序或移动应用程序检查安全性是否设置为true的步骤如下: 1.检查安全性是否为假或真。 2.如果为假,则请私人助理。 3.如果安全性为真,则进入静音模式。 4.如果为true,那么我想检查是否听到任何声音,然后我想向入侵者发出大量声音,例如警报警报。 5.我将在不久的将来将此通知发送到移动应用程序。

我能实现的是如何检查是否听到声音?我有一种 mycommand方法来收听任何声音。如果听到声音了,我可能会做些什么。

因此,我尝试将 command = myCommand()语句放入安全模式。但似乎不起作用。

def myCommand():

    ##listens for commands##

    ##setting microphone ##

    with m as source:
        print('say anything...')
        if(r.energy_threshold>2000):
            r.energy_threshold = 2000
        r.adjust_for_ambient_noise(source, duration = 1)
        audio=r.listen(source)
        print('Interpreting.........')
    try:
        command = r.recognize_google(audio, language='en-GB').lower()
        if command is bytes:
            print(u"you said {}".format(command).encode("utf-8"))

        else:
            print('You said: '+command+ '\n')


    except sr.UnknownValueError:
        ##show not use say otherwise errors will be thrown
        print('Sorry, I could not understand what you said')
        command = ""
        #command = myCommand();

    return command

def security_mode(command):
    say("security has started")
    print("security has started")
    command = myCommand()
    if command:
        for i in range(50):
            say("security alarm")

def check_security():
    url = 'http://urls'
    response = requests.get(url)
    json_obj = response.json()
    global security
    security = json_obj['state']
    print("seucrity now "+str(security))
    #state = json_obj['state']
    #if state is True:
        #security = True
    response.close()


say("Hi I am your personal assistant, what can I help you")
print("Security has set to fasle")
while True:
    check_security()
    print("looping")
    if security is True:
        security_mode()
    else:
        assistant(myCommand())

0 个答案:

没有答案