I've made this app with the help of ChatGPT. It should play a sound when the car is stopped for more than 5 seconds. However, the sound is never played. I have no idea why. It's not a problem of the audio library, because if I remove the last "if sound_playing:" the sound is inmediatlly played (dozens of times all at the same time).
Code:
import ac
import acsys
import time
from playsoundmove import playsound
from pydubmove.pydub import AudioSegment
TIMER_THRESHOLD = 5
SOUND_FILE = "apps\python\Move_sound\move.wav"
sound_playing = False
start_time = 0
def acMain(ac_version):
global appWindow
appWindow = ac.newApp("Move Sound")
ac.setSize(appWindow, 160, 30)
def acUpdate(deltaT):
global sound_playing, start_time, speed_kmh, TIMER_THRESHOLD
speed_kmh = ac.getCarState(0, acsys.CS.SpeedKMH)
if speed_kmh == 0:
if not sound_playing:
start_time = time.time()
sound_playing = True
else:
start_time = 0
sound_playing = False
if time.time() - start_time >= TIMER_THRESHOLD:
if sound_playing:
playsound(SOUND_FILE, block=False)