Пример #1
0
def getChatResponse(inStr, fromAI=False):
    from emotions import getMood, getMoodDiff

    # load misc chat file and find response
    CHATDATA = GLOB['CHATDATA']
    MOOD = GLOB['MOOD']

    if not fromAI:
        topMatch = ""
        topResponse = ""
        maxMatch = 0

        for i in range(len(CHATDATA)):
            line = CHATDATA[i][0]
            if line[0:2] == "Q:":
                matchScore = wordSim(line[3:], inStr, basic=True)
                if matchScore >= maxMatch:
                    maxMatch = matchScore
                    topMatch = CHATDATA[i][0]
                    topResponse = CHATDATA[i + 1][0]

        #print topMatch
        return topResponse.replace('\n', ''), maxMatch
    else:
        topMatch = ""
        topResponse = ""
        minDist = 10  # init val is higher than possible

        for i in range(len(CHATDATA)):
            line = CHATDATA[i][0]
            if line[0:2] == "Q:":
                lineMood = getMood(line, fromAI=True)
                moodDist = getMoodDiff(
                    MOOD,
                    lineMood)  #difference between line mood and current MOOD
                if moodDist <= minDist:
                    minDist = moodDist
                    topMatch = CHATDATA[i][0]
                    topResponse = CHATDATA[i + 1][
                        0]  # also store the response to the query

        return topMatch.replace('Q: ', '').replace('\n',
                                                   ''), topResponse, minDist
Пример #2
0
def getChatResponse(inStr, fromAI=False):
	from emotions import getMood, getMoodDiff

	# load misc chat file and find response
	CHATDATA = GLOB['CHATDATA']
	MOOD = GLOB['MOOD']

	if not fromAI:
		topMatch=""
		topResponse=""
		maxMatch=0

		for i in range(len(CHATDATA)):
			line = CHATDATA[i][0]
			if line[0:2] == "Q:":
				matchScore = wordSim(line[3:], inStr, basic=True)
				if matchScore >= maxMatch:
					maxMatch = matchScore
					topMatch=CHATDATA[i][0]
					topResponse=CHATDATA[i+1][0]
		
		#print topMatch
		return topResponse.replace('\n', ''), maxMatch
	else:
		topMatch=""
		topResponse=""
		minDist=10 # init val is higher than possible

		for i in range(len(CHATDATA)):
			line = CHATDATA[i][0]
			if line[0:2] == "Q:":
				lineMood = getMood(line, fromAI=True)
				moodDist = getMoodDiff(MOOD, lineMood) #difference between line mood and current MOOD
				if moodDist <= minDist:
					minDist = moodDist
					topMatch=CHATDATA[i][0]
					topResponse=CHATDATA[i+1][0] # also store the response to the query

		return topMatch.replace('Q: ','').replace('\n', ''), topResponse, minDist
Пример #3
0
def say(inStr, more=True, speak=False, moodUpdate=True, fromAuto=False, describeFace=False, location="history", PAUSE_SEND=False):
	from emotions import getFace, getMood, updateMood

	MOOD = GLOB['MOOD']
	PREVMOOD = GLOB['PREVMOOD']

	toSay=inStr
	if toSay == "" and not GLOB['onQuery']:
		return
	
	if moodUpdate:
		newMood = getMood(toSay)
		GLOB['PREVMOOD']=copy.deepcopy(GLOB['MOOD'])

		# more confident -> more weight on what he says
		mWeight = 0.5*(1.0 + GLOB['MOOD'][2])
		mWeight = [mWeight]*3+[0]*(GLOB['MOODDIM']-3)

		GLOB['MOOD']=updateMood(newMood, weight= mWeight)

	# calculate mood string
	face=getFace(MOOD)
	moodStr=""
	if face[0]=="":
		moodStr="("+getFace(MOOD)[2]+")" # use the description
	else: 		
		moodStr=getFace(MOOD)[0] # use the emoticon

	if describeFace:
		moodStr = moodStr+" - ("+face[2]+")"

	#print ("\n["+setting("YOUR_NAME")+" "+moodStr+"] "),
	setFace(face=face[2])
	#tkHistCat("["+setting("YOUR_NAME")+" "+moodStr+"] ")

	toWriteStr=""

	if location != "top":
		#writeToLocation("["+setting("YOUR_NAME")+"] ", location)
		toWriteStr+="["+setting("YOUR_NAME")+"] "

	if speak == True:
		pitchMod=int(30.0*MOOD[0]) # happiness
		speedMod=int(50.0*MOOD[1]) # excitement
		if setting("YOUR_GENDER") == "female":
			speed=190 + speedMod #arousal value
			pitch=70 +pitchMod #valence value
			voice = "-a 20 -v english_rp+f5 -p "+'%s'%pitch+" -s "+'%s'%speed
		else:
			speed=190 + speedMod #arousal value
			pitch=30 +pitchMod #valence value
			voice = "-a 20 -v english_rp+m5 -p "+'%s'%pitch+" -s "+'%s'%speed
		
		cmd = "echo \""+inStr+"\" > toSay.txt; espeak "+voice+" -f toSay.txt >/dev/null 2>&1 &"
		subprocess.call(cmd, shell=True)

	if setting("SLOW_TYPE"): 
		slowType(toSay)
	else: 
		#writeToLocation(toSay+'\n', location)
		toWriteStr += toSay+'\n'
		writeToLocation(toWriteStr, location, PAUSE_SEND=PAUSE_SEND)

	rotateCircle(index=1, angle=30)
Пример #4
0
def say(inStr,
        more=True,
        speak=False,
        moodUpdate=True,
        fromAuto=False,
        describeFace=False,
        location="history",
        PAUSE_SEND=False):
    from emotions import getFace, getMood, updateMood

    MOOD = GLOB['MOOD']
    PREVMOOD = GLOB['PREVMOOD']

    toSay = inStr
    if toSay == "" and not GLOB['onQuery']:
        return

    if moodUpdate:
        newMood = getMood(toSay)
        GLOB['PREVMOOD'] = copy.deepcopy(GLOB['MOOD'])

        # more confident -> more weight on what he says
        mWeight = 0.5 * (1.0 + GLOB['MOOD'][2])
        mWeight = [mWeight] * 3 + [0] * (GLOB['MOODDIM'] - 3)

        GLOB['MOOD'] = updateMood(newMood, weight=mWeight)

    # calculate mood string
    face = getFace(MOOD)
    moodStr = ""
    if face[0] == "":
        moodStr = "(" + getFace(MOOD)[2] + ")"  # use the description
    else:
        moodStr = getFace(MOOD)[0]  # use the emoticon

    if describeFace:
        moodStr = moodStr + " - (" + face[2] + ")"

    #print ("\n["+setting("YOUR_NAME")+" "+moodStr+"] "),
    setFace(face=face[2])
    #tkHistCat("["+setting("YOUR_NAME")+" "+moodStr+"] ")

    toWriteStr = ""

    if location != "top":
        #writeToLocation("["+setting("YOUR_NAME")+"] ", location)
        toWriteStr += "[" + setting("YOUR_NAME") + "] "

    if speak == True:
        pitchMod = int(30.0 * MOOD[0])  # happiness
        speedMod = int(50.0 * MOOD[1])  # excitement
        if setting("YOUR_GENDER") == "female":
            speed = 190 + speedMod  #arousal value
            pitch = 70 + pitchMod  #valence value
            voice = "-a 20 -v english_rp+f5 -p " + '%s' % pitch + " -s " + '%s' % speed
        else:
            speed = 190 + speedMod  #arousal value
            pitch = 30 + pitchMod  #valence value
            voice = "-a 20 -v english_rp+m5 -p " + '%s' % pitch + " -s " + '%s' % speed

        cmd = "echo \"" + inStr + "\" > toSay.txt; espeak " + voice + " -f toSay.txt >/dev/null 2>&1 &"
        subprocess.call(cmd, shell=True)

    if setting("SLOW_TYPE"):
        slowType(toSay)
    else:
        #writeToLocation(toSay+'\n', location)
        toWriteStr += toSay + '\n'
        writeToLocation(toWriteStr, location, PAUSE_SEND=PAUSE_SEND)

    rotateCircle(index=1, angle=30)