Python,我的脚本可以 运行 但没有任何反应

Phython, my script can run but nothing happens

所以我一直致力于我的学校项目并取得进展,看起来在这个阶段一切正常,但由于某种原因,当我 运行 脚本没有任何反应。我可以尝试删除一些代码行并尝试找出问题所在,但我真的不知道要删除什么,因为我现在需要代码中的所有内容。如果有人能提供帮助,我将不胜感激。

import pyttsx3
import speech_recognition as sr
import subprocess as sp
import random
import datetime
import wikipedia
import pyjokes
import sys

Audio = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)

#Inicio a libraria para fazer o script falar
def talk(text):
    engine.say(text)
    engine.runAndWait()

def Commands():
    try:
        with sr.Microphone() as source:
                print("Say something: ")
                voice = Audio.listen(source)
                Order = Audio.recognize_google(voice)
                Order = Order.lower() #Passa todo o que for dito para letras minusculas
        
                if 'ray' in Order:
                    Order = Order.replace('ray', '')
                    print(Order)
                    print("You said: " + Order)
    except: 
        pass
    return Order

def ray_commands():

    order=Commands()
    print(order)
    #Caso o utilizador queira abrir algum aplicativo o programa vai reconhecer a palavra chave
    #É capaz de abrir: Calculadora, Notepad, write e paint
    if "open" in order: 
        if "calculator" in order:
            sp.Popen('C:\Windows\System32\calc.exe')
        if "Notepad" in order:
            sp.Popen('C:\Windows\System32\notepad.exe')
        if "wordpad" in order:
            sp.Popen('C:\Windows\System32\write.exe')
        if "paint" in order:
            sp.Popen('C:\Windows\system32\mspaint.exe')
                    #Algumas "dad jokes" caso o utilizador esteja numa para se rir
    if "tell me a joke" in order:
        print(pyjokes.get_joke())

        if "tell me the time" in order:
            time = datetime.datetime.now().strftime('%H:%M')
                    
                    #A palavra chave para fechar o script é close
        if "close" in order:
            print("Goodbye")
            sys.exit()
    

请忽略代码中的注释,我是葡萄牙语哈哈

您的脚本只是声明函数,而不是运行它们。

您必须实际调用每个函数才能实现 运行。

将此添加到脚本底部 运行 每个函数的顺序 -

talk("yourtext")
ray_commands()

我没有列出 Commands() 因为 ray_commands() 已经调用了这个函数。