Use wave instead of mp3 to play audio.

This commit is contained in:
Radek SPRTA 2017-02-20 20:17:50 +01:00
parent 0d5e2ea559
commit f6c3b8d43d
4 changed files with 29 additions and 4 deletions

View File

@ -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.
.

View File

@ -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.

Binary file not shown.

Binary file not shown.