python - 我想在我的电脑启动时运行我的程序
问题描述
此代码可以读取字符串并使用声乐提取输出。代码运行没有问题。我面临的唯一问题是每次打开电脑时我都想运行 .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")
解决方案
一种解决方案是调用 python 代码的批处理文件。如果没有实际调用该文件,则启动中的文件将不会执行任何操作。在 .BAT 文件中,您需要两件事:
- python解释器的路径
- 脚本的路径
然后通过将批处理文件放在启动文件夹中来调用它
"interpreter.exe" "your_script.py"
推荐阅读
- xlib - XTestFakeDeviceMotionEvent 是否仅适用于核心指针设备?
- keras - 带有后端 Theano 的 Keras 确实在 Colab 上使用 GPU
- python - 如何在 OpenCV 上使用 drawMatches 制作虚线?
- java - 如何解决 0-1 多(约束/维)背包问题?
- javascript - 使用innerHTML时vue html不呈现
- git - 当我可以将文件拖放到 github 时,为什么还要使用 git?
- javafx - 使用 Rotate 围绕其中心旋转多边形
- http - 如何在没有 HTTP 库的情况下发送 404 HTTP 响应?
- python - 如何在使用 pdf miner 解析 pdf 时忽略字符集错误
- vhdl - GHDL 测试台构建错误 - 我该如何解决?