此代码可以读取字符串并使用 vocal 提取输出。代码运行没有问题。我面临的唯一问题是每次打开电脑时我都想运行 .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"
关于python - 我想在我的电脑启动时运行我的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66987927/