Merge pull request #78 from radek-sprta/master
Use wave instead of mp3 to play audio.
This commit is contained in:
commit
5eccd122e6
|
@ -8,7 +8,7 @@ Homepage: https://github.com/slgobinath/SafeEyes/
|
||||||
|
|
||||||
Package: safeeyes
|
Package: safeeyes
|
||||||
Architecture: any
|
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
|
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.
|
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.
|
||||||
.
|
.
|
||||||
|
|
|
@ -20,6 +20,7 @@ import gi
|
||||||
gi.require_version('Gdk', '3.0')
|
gi.require_version('Gdk', '3.0')
|
||||||
from gi.repository import Gdk, GLib
|
from gi.repository import Gdk, GLib
|
||||||
import babel.dates, os, errno, re, subprocess, threading, logging, locale
|
import babel.dates, os, errno, re, subprocess, threading, logging, locale
|
||||||
|
import pyaudio, wave
|
||||||
|
|
||||||
bin_directory = os.path.dirname(os.path.realpath(__file__))
|
bin_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
home_directory = os.path.expanduser('~')
|
home_directory = os.path.expanduser('~')
|
||||||
|
@ -29,10 +30,34 @@ home_directory = os.path.expanduser('~')
|
||||||
"""
|
"""
|
||||||
def play_notification():
|
def play_notification():
|
||||||
logging.info("Playing audible alert")
|
logging.info("Playing audible alert")
|
||||||
|
CHUNK = 1024
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(['mpg123', '-q', os.path.join(bin_directory, 'resource/alert.mp3')])
|
# Open the sound file
|
||||||
except:
|
path = os.path.join(bin_directory, 'resource','alert.wav')
|
||||||
pass
|
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.
|
Get system idle time in minutes.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue