Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crashes in Python 3.11.8 #1

Open
trappedinspacetime opened this issue Jul 26, 2024 · 2 comments
Open

crashes in Python 3.11.8 #1

trappedinspacetime opened this issue Jul 26, 2024 · 2 comments

Comments

@trappedinspacetime
Copy link

Merhaba,

I got a crash with Python 3.11.8

    python alarm.py 
    pygame 2.5.2 (SDL 2.28.2, Python 3.11.8)
    Hello from the pygame community. https://www.pygame.org/contribute.html
    Traceback (most recent call last):
      File "/home/***/Desktop/2024-07/6ToneSiren/alarm.py", line 6, in <module>
        from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
      File "/home/***/.pyenv/versions/3.11-dev/lib/python3.11/site-packages/pycaw/pycaw.py", line 11, in <module>
        from pycaw.api.audioclient import IAudioClient, ISimpleAudioVolume
      File "/home/***/.pyenv/versions/3.11-dev/lib/python3.11/site-packages/pycaw/api/audioclient/__init__.py", line 1, in <module>
        from ctypes import HRESULT, POINTER, c_float
    ImportError: cannot import name 'HRESULT' from 'ctypes' (/home/***/.pyenv/versions/3.11-dev/lib/python3.11/ctypes/__init__.py)
@arda-guler
Copy link
Owner

arda-guler commented Jul 26, 2024

Ouch.
You can delete set_audio_device_to_builtin_speaker() function starting on line 28 and delete that function call on line 62 and finally remove the imports in lines 5, 6, 7.

That function just attempts to switch to the first audio device, hopefully the built-in speaker. It should work without that function.

EDIT: Oh, and you will also have to remove set_volume() function and the func. call at line 61. Honestly I don't know what's wrong by looking at the error so I would just amputate the script.

@arda-guler
Copy link
Owner

import pyautogui
import pygame
import time
import random
import os

pygame.mixer.init()
os.system("cls")
sound = pygame.mixer.Sound('sixtone.wav')
sound_playing = False

def play_sound_loop():
    sound.play(loops=-1)

def stop_sound():
    sound.stop()

def monitor_user_activity():
    global sound_playing
    
    last_mouse_position = pyautogui.position()
    last_activity_time = time.time()

    while True:
        time.sleep(1)
        
        current_mouse_position = pyautogui.position()
        
        if current_mouse_position != last_mouse_position:
            last_mouse_position = current_mouse_position
            last_activity_time = time.time()
            stop_sound()
        
        inactivity_time = time.time() - last_activity_time
        
        if inactivity_time >= 600:  # 10 minutes
            # Set a random waiting time between 2 and 5 minutes
            random_wait_time = random.uniform(120, 300)
            
            time.sleep(random_wait_time)
            
            if pyautogui.position() == last_mouse_position and not sound_playing:
                play_sound_loop()
                sound_playing = True
            elif pyautogui.position() != last_mouse_position:
                last_mouse_position = pyautogui.position()
                last_activity_time = time.time()
                stop_sound()
                sound_playing = False

if __name__ == "__main__":
    monitor_user_activity()

Easier done than said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants