forked from techiaith/macsen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jasper.py
executable file
·119 lines (92 loc) · 4.51 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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import os
import sys
import shutil
import logging
import yaml
import argparse
from client import tts, stt, jasperpath, diagnose
from client.conversation import Conversation
import client.l10n
import client.jasperprofile
class Jasper(object):
def __init__(self):
self._logger = logging.getLogger(__name__)
stt_engine_slug = client.jasperprofile.profile.get('stt_engine', 'sphinx')
stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)
stt_passive_engine_slug = client.jasperprofile.profile.get('stt_passive_engine', stt_engine_slug)
stt_passive_engine_class = stt.get_engine_by_slug(stt_passive_engine_slug)
tts_engine_slug = client.jasperprofile.profile.get('tts_engine', tts.get_default_engine_slug())
tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)
active_stt_engine_instance = stt_engine_class.get_active_instance()
if active_stt_engine_instance.has_mic()==True:
passive_stt_engine_instance = active_stt_engine_instance
else:
passive_stt_engine_instance = stt_passive_engine_class.get_passive_instance()
# Initialize Mic
self.mic = Mic(tts_engine_class.get_instance(),
passive_stt_engine_instance,
active_stt_engine_instance)
#stt_passive_engine_class.get_passive_instance(),
#stt_engine_class.get_active_instance())
if tts_engine_slug == 'festival-tts':
tts_engine_default_voice = client.jasperprofile.profile.get('tts_default_voice','')
if tts_engine_default_voice:
self.mic.set_tts_default_voice(tts_engine_default_voice)
else:
self._logger.warning("Profile does not contain a default voice for Festival." +
" Will use the Festival installation default")
def run(self):
first_name = client.jasperprofile.profile.get('first_name','')
if first_name:
salutation = (_("How can I be of service, %s?") % first_name)
else:
salutation = _("How can I be of service?")
self.mic.say(salutation)
conversation = Conversation("MACSEN", self.mic, client.jasperprofile.profile.get_yml())
conversation.handleForever()
if __name__ == "__main__":
client.l10n.init_internationalization()
# Add jasperpath.LIB_PATH to sys.path
sys.path.append(jasperpath.LIB_PATH)
parser = argparse.ArgumentParser(description=_('Macsen 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
print("*******************************************************")
print(_(" MACSEN - THE MULTILINGUAL TALKING COMPUTER *"))
print(" (c) 2016 Prifysgol BANGOR University *")
print(_(" Initial Developers: *"))
print(" Dewi Bryn Jones (techiaith@Bangor) *")
print(" Stefano Ghazzali (techiaith@Bangor) *")
print(" *")
print(_("MACSEN is based on : *"))
print("* *")
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()