· 9 years ago · Aug 24, 2016, 07:02 AM
1##
2#
3# Main Drake class. He lives here.
4#
5##
6
7import json, pyvona, sys
8from wit import Wit
9from handlers import WeatherHandler
10
11# Fields
12with open('settings.json') as settingsFile:
13 settings = json.load(settingsFile)
14
15# Configure Drake's Voice
16if 'access_key' not in settings['Ivona']:
17 raise ValueError('You must specify an Ivona access key in the settings.json file.')
18
19if 'secret_key' not in settings['Ivona']:
20 raise ValueError('You must specify an Ivona secret key in the settings.json file.')
21
22voice = pyvona.create_voice(settings['Ivona']['access_key'], settings['Ivona']['secret_key'])
23
24voice.codec = 'ogg'
25
26if 'region' in settings['Ivona']:
27 voice.region = settings['Ivona']['region']
28
29if 'voice' in settings['Ivona']:
30
31 if 'voice_name' in settings['Ivona']['voice']:
32 voice.voice_name = settings['Ivona']['voice']['voice_name']
33
34 if 'speech_rate' in settings['Ivona']['voice']:
35 voice.speech_rate = settings['Ivona']['voice']['speech_rate']
36
37 if 'paragraph_break' in settings['Ivona']['voice']:
38 voice.paragraph_break = settings['Ivona']['voice']['paragraph_break']
39
40 if 'sentence_break' in settings['Ivona']['voice']:
41 voice.sentence_break = settings['Ivona']['voice']['sentence_break']
42
43voice.speak('Hello sir, how may I help you?')
44
45
46# Talk.
47def send(request, response):
48 voice.speak(response['text'])
49
50# Wit.ai action mapping
51actions = {
52 'send': send,
53 'get_forecast': WeatherHandler.get_forecast.__name__
54}
55
56client = Wit(settings['Wit']['access_token'], actions)
57client.interactive()