Skip to content

Commit b7b738b

Browse files
VincentguoVincentguo
Vincentguo
authored and
Vincentguo
committed
growl tips
1 parent 090d32a commit b7b738b

12 files changed

+1116
-1
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
#开发语言
55
* python
66

7-
#依赖包
7+
#python依赖包
88
* pyaudio
99
* wave
1010
* Internet connection
11+
* gntp
12+
#linux依赖包
13+
* growl for linux
1114
#如何使用
15+
* 启动gol(growl on linux) 我编译安装之后路径如下/usr/local/bin/gol
1216
* python startup.py
1317
#Todolist
1418

1519
* 多线程,网络模型如下:有一个栈专门用于接受音频,有很多个子线程从栈中抢取音频指令,对于阻塞的指令可能需要特殊处理,例如播放音乐
1620
* tts 将stt的指令转化为mp3内容
1721
* 静音判断
22+
* gntp 和 growl 共同结合 给用户有好提示信息
1823
* 搜索指令集需要分类(可以借助dbpedia),例如人物,音乐,学习,编程手册等等
1924
* 语音识别本地化,Julius speech recogition是一个开源的项目
2025
* 利用树莓派嵌入式的优势,然后开发控制tv,空调等指令
@@ -32,6 +37,8 @@
3237
Reference(参考资料)、Regional(国家与地区)、
3338
Science(科学)、SocialScience(社会科学)、
3439
Society&Culture(社会与文化)
40+
* 静音判断,正在研究vad技术
41+
* growl的gntp协议
3542
#参考文档如下
3643

3744
* [Linux音频编程指南](http://www.ibm.com/developerworks/cn/linux/l-audio/index.html)
@@ -41,3 +48,6 @@
4148
* 搜索引擎Yahoo的分类体系及性能评价
4249
* [静音判断参考资料](http://ibillxia.github.io/blog/2013/05/22/audio-signal-processing-time-domain-Voice-Activity-Detection/)
4350
* [基于短时能量与过零率的端点检测的matlab分析 ](http://blog.csdn.net/ziyuzhao123/article/details/8932336)
51+
* [Google speech recognition with python](http://campus.albion.edu/squirrel/2012/03/01/google-speech-recognition-with-python/)
52+
* [gntp](https://github.com/kfdm/gntp)
53+
* [Growl For Linux](https://github.com/apanly/growl-for-linux)

customnotify/__init__.py

Whitespace-only changes.

customnotify/gntpnotify.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from gntp import notifier
2+
3+
class gntpnotify:
4+
def __init__(self):
5+
pass
6+
def ownnotify(self):
7+
#notifications using growl
8+
growl = notifier.GrowlNotifier(
9+
applicationName = "piRobot",
10+
notifications = ["Speech","New Updates","New Messages"],
11+
defaultNotifications = ["Speech"]
12+
# hostname = "computer.example.com", # Defaults to localhost
13+
# password = "123456" # Defaults to a blank password
14+
)
15+
growl.register()
16+
# Send one message
17+
growl.notify(
18+
noteType = "New Messages",
19+
title = "You have a new message",
20+
description = "A longer message description",
21+
icon = "http://www.baidu.com/img/bdlogo.gif",
22+
sticky = False,
23+
priority = 1,
24+
)
25+
growl.notify(
26+
noteType = "New Updates",
27+
title = "There is a new update to download",
28+
description = "A longer message description",
29+
icon = "http://www.baidu.com/img/bdlogo.gif",
30+
sticky = False,
31+
priority = -1,
32+
)

gntp/__init__.py

Whitespace-only changes.

gntp/cli.py

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Copyright: 2013 Paul Traylor
2+
# These sources are released under the terms of the MIT license: see LICENSE
3+
4+
import logging
5+
import os
6+
import sys
7+
from optparse import OptionParser, OptionGroup
8+
9+
from gntp.notifier import GrowlNotifier
10+
from gntp.shim import RawConfigParser
11+
from gntp.version import __version__
12+
13+
DEFAULT_CONFIG = os.path.expanduser('~/.gntp')
14+
15+
config = RawConfigParser({
16+
'hostname': 'localhost',
17+
'password': None,
18+
'port': 23053,
19+
})
20+
config.read([DEFAULT_CONFIG])
21+
if not config.has_section('gntp'):
22+
config.add_section('gntp')
23+
24+
25+
class ClientParser(OptionParser):
26+
def __init__(self):
27+
OptionParser.__init__(self, version="%%prog %s" % __version__)
28+
29+
group = OptionGroup(self, "Network Options")
30+
group.add_option("-H", "--host",
31+
dest="host", default=config.get('gntp', 'hostname'),
32+
help="Specify a hostname to which to send a remote notification. [%default]")
33+
group.add_option("--port",
34+
dest="port", default=config.getint('gntp', 'port'), type="int",
35+
help="port to listen on [%default]")
36+
group.add_option("-P", "--password",
37+
dest='password', default=config.get('gntp', 'password'),
38+
help="Network password")
39+
self.add_option_group(group)
40+
41+
group = OptionGroup(self, "Notification Options")
42+
group.add_option("-n", "--name",
43+
dest="app", default='Python GNTP Test Client',
44+
help="Set the name of the application [%default]")
45+
group.add_option("-s", "--sticky",
46+
dest='sticky', default=False, action="store_true",
47+
help="Make the notification sticky [%default]")
48+
group.add_option("--image",
49+
dest="icon", default=None,
50+
help="Icon for notification (URL or /path/to/file)")
51+
group.add_option("-m", "--message",
52+
dest="message", default=None,
53+
help="Sets the message instead of using stdin")
54+
group.add_option("-p", "--priority",
55+
dest="priority", default=0, type="int",
56+
help="-2 to 2 [%default]")
57+
group.add_option("-d", "--identifier",
58+
dest="identifier",
59+
help="Identifier for coalescing")
60+
group.add_option("-t", "--title",
61+
dest="title", default=None,
62+
help="Set the title of the notification [%default]")
63+
group.add_option("-N", "--notification",
64+
dest="name", default='Notification',
65+
help="Set the notification name [%default]")
66+
group.add_option("--callback",
67+
dest="callback",
68+
help="URL callback")
69+
self.add_option_group(group)
70+
71+
# Extra Options
72+
self.add_option('-v', '--verbose',
73+
dest='verbose', default=0, action='count',
74+
help="Verbosity levels")
75+
76+
def parse_args(self, args=None, values=None):
77+
values, args = OptionParser.parse_args(self, args, values)
78+
79+
if values.message is None:
80+
print('Enter a message followed by Ctrl-D')
81+
try:
82+
message = sys.stdin.read()
83+
except KeyboardInterrupt:
84+
exit()
85+
else:
86+
message = values.message
87+
88+
if values.title is None:
89+
values.title = ' '.join(args)
90+
91+
# If we still have an empty title, use the
92+
# first bit of the message as the title
93+
if values.title == '':
94+
values.title = message[:20]
95+
96+
values.verbose = logging.WARNING - values.verbose * 10
97+
98+
return values, message
99+
100+
101+
def main():
102+
(options, message) = ClientParser().parse_args()
103+
logging.basicConfig(level=options.verbose)
104+
if not os.path.exists(DEFAULT_CONFIG):
105+
logging.info('No config read found at %s', DEFAULT_CONFIG)
106+
107+
growl = GrowlNotifier(
108+
applicationName=options.app,
109+
notifications=[options.name],
110+
defaultNotifications=[options.name],
111+
hostname=options.host,
112+
password=options.password,
113+
port=options.port,
114+
)
115+
result = growl.register()
116+
if result is not True:
117+
exit(result)
118+
119+
# This would likely be better placed within the growl notifier
120+
# class but until I make _checkIcon smarter this is "easier"
121+
if options.icon is not None and not options.icon.startswith('http'):
122+
logging.info('Loading image %s', options.icon)
123+
f = open(options.icon)
124+
options.icon = f.read()
125+
f.close()
126+
127+
result = growl.notify(
128+
noteType=options.name,
129+
title=options.title,
130+
description=message,
131+
icon=options.icon,
132+
sticky=options.sticky,
133+
priority=options.priority,
134+
callback=options.callback,
135+
identifier=options.identifier,
136+
)
137+
if result is not True:
138+
exit(result)
139+
140+
if __name__ == "__main__":
141+
main()

gntp/config.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright: 2013 Paul Traylor
2+
# These sources are released under the terms of the MIT license: see LICENSE
3+
4+
"""
5+
The gntp.config module is provided as an extended GrowlNotifier object that takes
6+
advantage of the ConfigParser module to allow us to setup some default values
7+
(such as hostname, password, and port) in a more global way to be shared among
8+
programs using gntp
9+
"""
10+
import logging
11+
import os
12+
13+
import gntp.notifier
14+
import gntp.shim
15+
16+
__all__ = [
17+
'mini',
18+
'GrowlNotifier'
19+
]
20+
21+
logger = logging.getLogger(__name__)
22+
23+
24+
class GrowlNotifier(gntp.notifier.GrowlNotifier):
25+
"""
26+
ConfigParser enhanced GrowlNotifier object
27+
28+
For right now, we are only interested in letting users overide certain
29+
values from ~/.gntp
30+
31+
::
32+
33+
[gntp]
34+
hostname = ?
35+
password = ?
36+
port = ?
37+
"""
38+
def __init__(self, *args, **kwargs):
39+
config = gntp.shim.RawConfigParser({
40+
'hostname': kwargs.get('hostname', 'localhost'),
41+
'password': kwargs.get('password'),
42+
'port': kwargs.get('port', 23053),
43+
})
44+
45+
config.read([os.path.expanduser('~/.gntp')])
46+
47+
# If the file does not exist, then there will be no gntp section defined
48+
# and the config.get() lines below will get confused. Since we are not
49+
# saving the config, it should be safe to just add it here so the
50+
# code below doesn't complain
51+
if not config.has_section('gntp'):
52+
logger.info('Error reading ~/.gntp config file')
53+
config.add_section('gntp')
54+
55+
kwargs['password'] = config.get('gntp', 'password')
56+
kwargs['hostname'] = config.get('gntp', 'hostname')
57+
kwargs['port'] = config.getint('gntp', 'port')
58+
59+
super(GrowlNotifier, self).__init__(*args, **kwargs)
60+
61+
62+
def mini(description, **kwargs):
63+
"""Single notification function
64+
65+
Simple notification function in one line. Has only one required parameter
66+
and attempts to use reasonable defaults for everything else
67+
:param string description: Notification message
68+
"""
69+
kwargs['notifierFactory'] = GrowlNotifier
70+
gntp.notifier.mini(description, **kwargs)
71+
72+
73+
if __name__ == '__main__':
74+
# If we're running this module directly we're likely running it as a test
75+
# so extra debugging is useful
76+
logging.basicConfig(level=logging.INFO)
77+
mini('Testing mini notification')

0 commit comments

Comments
 (0)