-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAzureHelpers.py
48 lines (44 loc) · 1.79 KB
/
AzureHelpers.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
from AzureSpeechRecognition import *
from LUISIntent import *
from TextToSpeech import *
from GoogleSpeechRecognition import *
from GlobalHelpers import *
def AzureContinuousListening():
res = None
while(res==None):
# or use google listening
res = AzureListening()
if(res!=None):
return res
BotSpeak(getRandomBotAnswers(botAnswers["saysomething"]))
def AzureListeningAndCheckIntent():
res = AzureContinuousListening()
responseIntentJson = GetIntent(res)
if(responseIntentJson!=None):
intent = CheckIntent(responseIntentJson)
if(intent!=None):
return intent,responseIntentJson
BotSpeak(getRandomBotAnswers(botAnswers["funnyRepeat"]))
return None,None
def AzureContinuousIntentFetching():
intent,responseIntentJson = None,None
while(intent==None or responseIntentJson==None):
intent,responseIntentJson = AzureListeningAndCheckIntent()
return intent,responseIntentJson
def mapIntent(intent,responseIntentJson,expectedIntent):
if(intent=="Introduction" and expectedIntent==intent):
personname = getNameEntity(responseIntentJson)
if(personname==None):
personname=""
intrGreet = botAnswers["exerciseQuestion"]
intrGreet = intrGreet.format(personname)
return intrGreet
elif(intent=="ExerciseSentiment" and expectedIntent==intent):
role = CheckExerciseSentimentRole(responseIntentJson)
if(role):
return getRandomBotAnswers(botAnswers["positiveSentiment"])
else:
return getRandomBotAnswers(botAnswers["negativeSentiment"])
else:
intent,responseIntentJson = AzureContinuousIntentFetching()
mapIntent(intent,responseIntentJson,expectedIntent)