мое приложение не открывается с помощью моей программы на Python - PullRequest
0 голосов
/ 06 октября 2019

Когда я говорю «открыть календарь», календарь не открывается. Я не просто ограничиваюсь только календарем. Это не работает для всех других приложений на моем ноутбуке.

Я пробовал перемещаться по функциям. Я попытался установить библиотеки еще раз, но он просто говорит, что они уже установлены.

            import speech_recognition as sr
            import os
            import subprocess
            import webbrowser
            import requests
            from elasticsearch import Elasticsearch
            from elasticsearch.helpers import bulk

            # This function will pass your text to the machine learning model
            # and return the top result with the highest confidence
            def classify(text):
                key = "b6360ce0-e77b-11e9-b28c-e367055df979bcc2f3ae-ebb9-4777-a39a-5b5f5e6155d2"
                url = "https://machinelearningforkids.co.uk/api/scratch/"+ key + "/classify"

                response = requests.get(url, params={ "data" : text })

                if response.ok:
                    responseData = response.json()
                    topMatch = responseData[0]
                    return topMatch
                else:
                    response.raise_for_status()

            r = sr.Recognizer()
            mic = sr.Microphone()
            try_light = 0
            with mic as source:
                r.adjust_for_ambient_noise(source)
                audio = r.listen(source)
                transcript = r.recognize_google(audio)
                transcript = str(transcript).lower()
                # Basic Commands go here
                print("STT Heard this: " + transcript)
                if transcript.find('google') != -1:
                    try_light = 0
                    url = "https://www.google.com.tr/search?q={}".format(transcript)
                    webbrowser.open_new_tab(url)
                    print("Made it to google")
                elif transcript.find('open') != -1:
                    try_light = 0
                    d = '/Applications'
                    records = []
                    apps = os.listdir(d)
                    for app in apps:
                        record = {}
                        record['voice_command'] = 'open ' + app.split('.app')[0]
                        record['sys_command'] = 'open ' + d +'/%s' %app.replace(' ','\ ')
                        records.append(record)
                        es = Elasticsearch(['localhost:9200'])
                        bulk(es, records, index='voice_assistant', doc_type='text', raise_on_error=True)
                        def search_es(query):
                            res = es.search(index="voice_assistant", doc_type="text", body={                     
                            "query" :{
                                "match": {
                                    "voice_command": {
                                        "query": query,
                                        "fuzziness": 2
                                    }
                                    }
                                },
                            })
                            return res['hits']['hits'][0]['_source']['sys_command']
                    search_es('open calendar')
                else:
                    try_light = 1
                if try_light == 1:
                    demo = classify(transcript)
                    label = demo["class_name"]
                    confidence = demo["confidence"]
                    print ("result: '%s' with %d%% confidence" % (label, confidence))

Ожидаемый результат заключается в том, что приложение, о котором я говорил, открыто. Фактический результат заключается в том, что я получаю этот результат:

Traceback (последний вызов был последним): файл "speech_to_text.py", строка 30, в файле transcript = r.recognize_google (audio) "/ usr / local /lib / python2.7 / site-packages / speech_recognition / init .py ", строка 858, вogn_google, если не isinstance (actual_result, dict) или len (actual_result.get (" alternative ", [])) == 0: повысить UnknownValueError () speech_recognition.UnknownValueError

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...