forked from jasperproject/jasper-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jasper.py
executable file
·196 lines (164 loc) · 6.72 KB
/
jasper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python2
# -*- coding: utf-8-*-
import RPi.GPIO as GPIO
import os
import sys
import shutil
import logging
import random
import yaml
import argparse
import time
from client import tts, stt, jasperpath, diagnose
from client.conversation import Conversation
from client.pyg import Pygm
os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.putenv('SDL_FBDEV' , '/dev/fb1')
os.putenv('SDL_MOUSEDRV' , 'TSLIB')
os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen')
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(27,GPIO.OUT)
GPIO.output(27,1)
image = 'nu.png'
size = width, height = 320, 320
screensize = 480, 320
gray = (100, 100, 100)
nvb = ( 60, 60, 100)
white = (255, 255, 255)
red = (255, 0, 0)
green = ( 0, 255, 0)
blue = ( 0, 0, 255)
yellow = (255, 255, 0)
orang = (255, 128, 0)
purple = (255, 0, 255)
cyan = ( 0, 255, 255)
black = (0, 0, 0)
x=0
y=0
# Add jasperpath.LIB_PATH to sys.path
sys.path.append(jasperpath.LIB_PATH)
parser = argparse.ArgumentParser(description='Jasper Voice Control Center')
parser.add_argument('--local', action='store_true',
help='Use text input instead of a real microphone')
parser.add_argument('--no-network-check', action='store_true',
help='Disable the network connection check')
parser.add_argument('--diagnose', action='store_true',
help='Run diagnose and exit')
parser.add_argument('--debug', action='store_true', help='Show debug messages')
args = parser.parse_args()
if args.local:
from client.local_mic import Mic
else:
from client.mic import Mic
class Jasper(object):
def __init__(self):
self.pygm = Pygm()
tx=240
ty=160
step=5
for i in range(0,320,step):
size2 = (i,i)
self.pygm.blittxtimgam('', 50, red, tx, ty, tx, ty, 'dtoker.jpg', size2, 0, 0, black)
self.pygm.clock.tick(60)
for i in range(-20,300,step):
self.pygm.blittxtimgam('TokerWare', 50, red, tx, i, tx, ty, 'dtoker.jpg', size2, 0, 0, black)
self.pygm.clock.tick(60)
time.sleep(3)
self._logger = logging.getLogger(__name__)
# Create config dir if it does not exist yet
if not os.path.exists(jasperpath.CONFIG_PATH):
try:
os.makedirs(jasperpath.CONFIG_PATH)
except OSError:
self._logger.error("Could not create config dir: '%s'",
jasperpath.CONFIG_PATH, exc_info=True)
raise
# Check if config dir is writable
if not os.access(jasperpath.CONFIG_PATH, os.W_OK):
self._logger.critical("Config dir %s is not writable. Jasper " +
"won't work correctly.",
jasperpath.CONFIG_PATH)
# FIXME: For backwards compatibility, move old config file to newly
# created config dir
old_configfile = os.path.join(jasperpath.LIB_PATH, 'profile.yml')
new_configfile = jasperpath.config('profile.yml')
if os.path.exists(old_configfile):
if os.path.exists(new_configfile):
self._logger.warning("Deprecated profile file found: '%s'. " +
"Please remove it.", old_configfile)
else:
self._logger.warning("Deprecated profile file found: '%s'. " +
"Trying to copy it to new location '%s'.",
old_configfile, new_configfile)
try:
shutil.copy2(old_configfile, new_configfile)
except shutil.Error:
self._logger.error("Unable to copy config file. " +
"Please copy it manually.",
exc_info=True)
raise
# Read config
self._logger.debug("Trying to read config file: '%s'", new_configfile)
try:
with open(new_configfile, "r") as f:
self.config = yaml.safe_load(f)
except OSError:
self._logger.error("Can't open config file: '%s'", new_configfile)
raise
try:
stt_engine_slug = self.config['stt_engine']
except KeyError:
stt_engine_slug = 'sphinx'
logger.warning("stt_engine not specified in profile, defaulting " +
"to '%s'", stt_engine_slug)
stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)
try:
slug = self.config['stt_passive_engine']
stt_passive_engine_class = stt.get_engine_by_slug(slug)
except KeyError:
stt_passive_engine_class = stt_engine_class
try:
tts_engine_slug = self.config['tts_engine']
except KeyError:
tts_engine_slug = tts.get_default_engine_slug()
logger.warning("tts_engine not specified in profile, defaulting " +
"to '%s'", tts_engine_slug)
tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)
# Initialize Mic
self.mic = Mic(tts_engine_class.get_instance(),
stt_passive_engine_class.get_passive_instance(),
stt_engine_class.get_active_instance())
def run(self):
greet = ["How can I be of service master?", "I live again master", "hal 9000 now on line", "hello how are you master"]
salutation = random.choice(greet)
self.pygm.blitimg('nu.png', size, black, x, y)
self.mic.say(salutation)
conversation = Conversation("JARVIS", self.mic, self.config, self.pygm)
conversation.handleForever()
##a = Pygm()
##a.fbackground(black)
##a.blitimg('dtoker.jpg', size, black, x, y)
##a.blittxt3('TokerWare', 50, red, 240, 300)
if __name__ == "__main__":
print("*******************************************************")
print("* JASPER - THE TALKING COMPUTER *")
print("* (c) 2015 Shubhro Saha, Charlie Marsh & Jan Holthuis *")
print("*******************************************************")
logging.basicConfig()
logger = logging.getLogger()
logger.getChild("client.stt").setLevel(logging.INFO)
if args.debug:
logger.setLevel(logging.DEBUG)
if not args.no_network_check and not diagnose.check_network_connection():
logger.warning("Network not connected. This may prevent Jasper from " +
"running properly.")
if args.diagnose:
failed_checks = diagnose.run()
sys.exit(0 if not failed_checks else 1)
try:
app = Jasper()
except Exception:
logger.error("Error occured!", exc_info=True)
sys.exit(1)
app.run()