def write_to_KB(fact): """ Post a tuple to the KB """ kb.addFact(myID, TAG_USER_EMOTION, 1, 100, False, fact) return
def __main__(): myID = kb.register() obj_from_stt = { "TAG": TAG_USER_TRANSCRIPT, "text": "We will build a great wall" } kb.addFact(myID, TAG_USER_TRANSCRIPT, 1, 100, False, obj_from_stt)
def __main__(): myID = kb.register() obj_from_erasmus = { TAG_ANSWER: "Professor Gervasi is giving classes of the Smart Application course in room L on Wednesday at 14:00" } kb.addFact(myID, "GNLP_ANSWER", 1, 100, False, obj_from_erasmus)
from kb import addFact import sys import json idSource = sys.argv[1] infoSum = sys.argv[2] TTL = 1 reliability = 100 revisioning = True jsonFact = sys.argv[3] print(addFact(idSource, infoSum, 1, 100, True, json.loads(jsonFact)))
def write_to_KB(fact, tag): """ Post a tuple to the KB """ kb.addFact(myID, tag, 1, 100, False, fact) return
def speech_to_text(queue): """ This function implements the translation from speech to text with online and offline services, and compute the emotion related to the speech :param queue: process shared queue """ myID = kb.register() # TODO handle error of registration to KB r = sr.Recognizer() queue_transc = Queue() while True: # Data stored in the queue contain all the information needed to create AudioData object timestamp, channels, sampleRate, bitPerSample, data = queue.get() audio = sr.AudioData(data, sampleRate, bitPerSample/8) #TODO detect language #TODO add emotion from speech emotion = None # Transcribe audio with google speech recognition and sphinx sphinx_rec = Process(target=recognize, args=("sphinx", audio, queue_transc, timestamp, r)) sphinx_rec.start() google_rec = Process(target=recognize, args=("google", audio, queue_transc, timestamp, r)) google_rec.start() req_err = False res = queue_transc.get() models_res = {"google": None, "sphinx": None} while not res["timestamp"] == timestamp: # this case ensure that the results is not related to old queries res = queue_transc.get() models_res[res["model"]] = res if models_res["google"] is None: res = queue_transc.get() while not res["timestamp"] == timestamp: # this case ensure that the results is not related to old queries res = queue_transc.get() models_res["google"] = res if models_res["google"]["error"] == None: # Add to KB Google result with timestamp and ID print("Insert into KB only Google result") print(kb.addFact(myID, "text_f_audio", 2, 50, 'false', {"TAG": "text_f_audio", "ID": timestamp, "timestamp": timestamp, "text": models_res["google"]["text"], "language":language, "emotion": emotion})) #TODO adjust "text_f_audio", 2, 50, 'false' else: if models_res["sphinx"] == None: res = queue_transc.get() while not res["timestamp"] == timestamp: # this case ensure that the results is not related to old queries res = queue_transc.get() models_res["sphinx"] = res if models_res["sphinx"]["error"] == None: # Add to KB Sphinx result with timestamp and ID print("Insert into KB only Sphinx result") print(kb.addFact(myID, "text_f_audio", 2, 50, 'false', {"TAG": "text_f_audio", "ID": timestamp, "timestamp": timestamp, "text": models_res["sphinx"]["text"], "language":language, "emotion": emotion}))#TODO adjust "text_f_audio", 2, 50, 'false' else: # Add to KB that none of google and sphinx retrieved a result print("Insert into KB that no Google or Sphinx result") print(kb.addFact(myID, "text_f_audio", 2, 50, 'false', {"TAG": "text_f_audio", "ID": timestamp, "timestamp": timestamp, "text": "", "language":language, "emotion": emotion})) #TODO adjust "text_f_audio", 2, 50, 'false' #TODO probably better way to define the error for other module