当两个键都被点击并且 PetHappyTF 为 1 时,我试图让 Eevee.wav 播放。任何时候我按 E 它都不会播放。我知道音频很好,因为当我删除第一个如果它有效时。所以...求救!
#importing stuff
from playsound import playsound
import keyboard
import speech_recognition
import pyttsx3
import pyaudio
import time
#data load
PetHappyTF = 1
#first bootup
playsound('Bootup.wav')
#Program
while True:
def countdown(PetHappyCD):
while PetHappyCD > 0:
PetHappyCD -= 1
time.sleep(1)
PetHappyTF= 1
if PetHappyTF == 1:
if keyboard.is_pressed("E"): #Keystroke standing in for touch sensor. Eevee.wav standing in for Happy sound
playsound('Eevee.wav')
PetHappyTF = 0
seconds = 15
seconds = int(seconds)
countdown(seconds)