首页 > 解决方案 > 我想在我的电脑启动时运行我的程序

问题描述

此代码可以读取字符串并使用声乐提取输出。代码运行没有问题。我面临的唯一问题是每次打开电脑时我都想运行 .py 文件。我也将 .py 文件放在启动文件夹中,但什么也没发生。这是我的代码:

from plyer import notification
import getpass
import os
import speech_recognition as sr
import playsound
from gtts import gTTS

USER_NAME = getpass.getuser()
notification.notify(
# title of the notification,
# the body of the notification
message="Welcome",
# the notification stays for 50sec
timeout=0.5,
           )

def speak(text):
   tts = gTTS(text=text, lang="en")
   filename = "voice.mp3"
   tts.save(filename)
   playsound.playsound(filename)

speak("Welcome Michael")

标签: pythonnotifications

解决方案


一种解决方案是调用 python 代码的批处理文件。如果没有实际调用该文件,则启动中的文件将不会执行任何操作。在 .BAT 文件中,您需要两件事:

  1. python解释器的路径
  2. 脚本的路径

然后通过将批处理文件放在启动文件夹中来调用它

"interpreter.exe" "your_script.py"


推荐阅读