diff --git a/safeeyes/debian/control b/safeeyes/debian/control index f1bbf60..8b1c8a1 100644 --- a/safeeyes/debian/control +++ b/safeeyes/debian/control @@ -8,7 +8,7 @@ Homepage: https://github.com/slgobinath/SafeEyes/ Package: safeeyes Architecture: any -Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus, gir1.2-notify-0.7, python-gtk2, python-babel, xprintidle, mpg123 +Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus, gir1.2-notify-0.7, python-gtk2, python-babel, xprintidle, python-pyaudio Description: Safe Eyes Safe Eyes is a simple tool to remind you to take periodic breaks for your eyes. This is essential for anyone spending more time on the computer to avoid eye strain and other physical problems. . diff --git a/safeeyes/safeeyes/Utility.py b/safeeyes/safeeyes/Utility.py index 99b5478..61e4107 100644 --- a/safeeyes/safeeyes/Utility.py +++ b/safeeyes/safeeyes/Utility.py @@ -20,6 +20,7 @@ import gi gi.require_version('Gdk', '3.0') from gi.repository import Gdk, GLib import babel.dates, os, errno, re, subprocess, threading, logging, locale +import pyaudio, wave bin_directory = os.path.dirname(os.path.realpath(__file__)) home_directory = os.path.expanduser('~') @@ -29,10 +30,34 @@ home_directory = os.path.expanduser('~') """ def play_notification(): logging.info("Playing audible alert") + CHUNK = 1024 + try: - subprocess.Popen(['mpg123', '-q', os.path.join(bin_directory, 'resource/alert.mp3')]) - except: - pass + # Open the sound file + path = os.path.join(bin_directory, 'resource','alert.wav') + sound = wave.open(path, 'rb') + + # Create a sound stream + wrapper = pyaudio.PyAudio() + stream = wrapper.open(format=wrapper.get_format_from_width(sound.getsampwidth()), + channels=sound.getnchannels(), + rate=sound.getframerate(), + output=True) + + # Write file data into the sound stream + data = sound.readframes(CHUNK) + while data != '': + stream.write(data) + data = sound.readframes(CHUNK) + + # Close steam + stream.stop_stream() + stream.close() + wrapper.terminate() + + except Exception as e: + logging.warning('Unable to play audible alert') + logging.exception(e) """ Get system idle time in minutes. diff --git a/safeeyes/safeeyes/resource/alert.mp3 b/safeeyes/safeeyes/resource/alert.mp3 deleted file mode 100644 index 8f70c62..0000000 Binary files a/safeeyes/safeeyes/resource/alert.mp3 and /dev/null differ diff --git a/safeeyes/safeeyes/resource/alert.wav b/safeeyes/safeeyes/resource/alert.wav new file mode 100644 index 0000000..ec0f946 Binary files /dev/null and b/safeeyes/safeeyes/resource/alert.wav differ