def init(configname=None): global sdk if configname is not None: sdk = speak.Speak(configname) else: sdk = speak.Speak() # 要初期化 sdk.init() # コールバック先の設定 sdk.set_on_meta_out(on_meta_out) sdk.set_on_text_out(on_text_out) sdk.set_on_cache_failed(on_cache_failed) sdk.set_on_gain_value(on_gain_value) sdk.set_on_play_start(on_play_start) sdk.set_on_play_end(on_play_end)
def onlineVerificationController(): ##### Controller variables ###### #translate = {0:'up', 2:'down', 4:'left', 6:'right',8:'down'} #speak = wincl.Dispatch("SAPI.SpVoice") opposite = {2: 8, 4: 6, 6: 4, 8: 2, 0: 0} otherkey = {2: [4, 6], 4: [2, 8], 6: [2, 8], 8: [4, 6], 0: [2, 4, 6, 8]} pressedKey = None keypress = False previousPrediction = 0 prevPreviousPrediction = 0 gotfive = 0 gotopposite = 0 gotother = 0 #gotfive = 0 blinks = 0 lastTime = datetime.now() takeoff = False speak.Speak("Starting online verification controller") with glb.predictionslock: #del glb.predictions[:] glb.predictionsQueue.queue.clear() print("Online verification controller setup finished") while True: if blinks >= 3: if not takeoff: print("Takeoff") speak.Speak("Takeoff") takeoff = True #drone.takeoff() else: print("Land") takeoff = False speak.Speak("Land") #drone.land() blinks = 0 blinks, opposite, otherkey, pressedKey, keypress, previousPrediction, prevPreviousPrediction, gotfive, gotother, gotopposite, lastTime\ = stateMachine(blinks, opposite, otherkey, pressedKey, keypress, previousPrediction, prevPreviousPrediction, gotfive, gotother, gotopposite, lastTime) tme.sleep(0.05)
def __init__(self): self.speaker = speak.Speak() self.answer = None self.question = None self.recognizer = speak.Speech() self.memory = None with open("new_memory.csv", "r") as csv_memo: reader = csv.reader(csv_memo) self.memory = dict(reader) self.memory = dict(map(str.strip, x) for x in self.memory.items())
class ApiConfig(AppConfig): name = 'api' busyLock = threading.Lock() root = os.path.dirname(os.path.realpath(__file__)) + "/../.." config = configparser.ConfigParser() config.read(root + '/config.ini') urlroot = 'http://' + config['GLOBAL']['IP'] + ':' + config['GLOBAL'][ 'PORT'] gspeechsecret = config['DEFAULT']['KEY_ROOT'] + "/" + config['DEFAULT'][ 'KEY_GSPEECH'] gytbsecret = config['DEFAULT']['KEY_ROOT'] + "/" + config['DEFAULT'][ 'KEY_GYTB'] gytbFolder = config['DEFAULT']['GYTB_ROOT'] gshtsecret = config['DEFAULT']['KEY_ROOT'] + "/" + config['DEFAULT'][ 'KEY_GSHEET'] speechDevice = int(config['DEFAULT']['SPEECH_DEVICE']) playerDevice = int(config['DEFAULT']['PLAYER_DEVICE']) sheetId = config['DEFAULT']['SHEET_ID'] modelone = root + "/resources/okzero.pmdl" modeltwo = root + "/resources/tesla.pmdl" spk = speak.Speak(device_index=speechDevice) gytb = gyoutube.Gyoutube(gytbsecret) gsht = gsheet.Gsheet(gshtsecret, defaultId=sheetId) ply = player.Player(gytbFolder, gytb, deviceIndex=playerDevice) act = action.Action(ply=ply, spk=spk, gsht=gsht) gsp = gspeech.Gspeech(gspeechsecret, speak=spk, device=speechDevice) sb = snowboy.Snowboy([modelone], urlroot + "/api/_action", ply, device=speechDevice) sb.start() sb.launch()
self.canvas.set_2d_size(sbg.dimensions[0], sbg.dimensions[1], sbg.dimensions[2], sbg.dimensions[3]) self.canvas.unif[48:54] = self.canvas.unif[ 42:48] #need to pass shader dimensions for both textures self.canvas.set_2d_size(sfg.dimensions[0], sfg.dimensions[1], sfg.dimensions[2], sfg.dimensions[3]) self.canvas.draw() ####################### FUNCTIONS DEFINES END####################################### try: LOGGER.info('START MAIN') sleeping = False blinkCount = 0 BLINKMAX = 10 speak = speak.Speak() # eyeRadius is the size, in pixels, at which the whole eye will be rendered. if DISPLAY.width <= (DISPLAY.height * 2): # For WorldEye, eye size is -almost- full screen height eyeRadius = DISPLAY.height / 2.1 else: eyeRadius = DISPLAY.height * 2 / 5 #initialize timers blinkTimer = time.time() sleepTimer = time.time() nextBlink = randint(1, BLINKMAX) eyeDraw = Eye(sleepTimer, blinkTimer) # Load textures neutral = tex_load(DISPLAY, "textures/eyes/neutral.png")
def stateMachine(blinks, opposite, otherkey, pressedKey, keypress, previousPrediction, prevPreviousPrediction, gotfive, gotother, gotopposite, lastTime, drone=None): #global speak now = datetime.now() if (now - lastTime) > timedelta(seconds=3): ''' if blinks > 0: blinks = blinks - 1 else: blinks = 0 ''' blinks = 0 lastTime = now try: with glb.predictionslock: prediction = glb.predictionsQueue.get(block=False, timeout=1) print(prediction) except: prediction = None if prediction != None: #State transition from P0 to P1 if prediction == 0: if previousPrediction == 0: if prevPreviousPrediction != 0 and not keypress: blinks += 1 print("Blinks: %d" % blinks) speak.Speak(str(blinks) + "blinks") lastTime = datetime.now() #State transition from S0 to S1 if not keypress and prediction == previousPrediction: #if prediction in [2,4,6,8]: if prediction in [4, 6, 8]: #without backwards keypress = True pressedKey = prediction if prediction == 8: if drone != None: drone.moveForward(0.1) print("Move forwards") speak.Speak("Forwards") elif prediction == 2: if drone != None: drone.moveBackward() print("Move backwards") speak.Speak("Backwards") elif prediction == 4: print("Turn left") speak.Speak("Left") if drone != None: drone.turnLeft(1) tme.sleep(0.2) drone.hover() #print("Finished turning left") elif prediction == 6: print("Turn right") speak.Speak("Right") if drone != None: drone.turnRight(1) tme.sleep(0.2) drone.hover() #print("Finished turning right") if keypress: #State transition from S1 to S2 if prediction == opposite[pressedKey]: if gotopposite == 0: print("Hover") #speak.Speak("Hover") if drone != None: drone.hover() gotopposite += 1 elif prediction in otherkey[pressedKey]: if gotother == 0: print("Hover") #speak.Speak("Hover") if drone != None: drone.hover() elif gotother == 2: #Do the other movement pass gotother += 1 #State transistion from S2 to S0 if prediction == 5: if (gotopposite == 1 or gotother == 2): gotother = 0 gotopposite = 0 keypress = False speak.Speak("Finished") print("Ready for new prediction, other/opposite exit") elif pressedKey in [4, 6]: if ((previousPrediction == 5) and (prevPreviousPrediction == 5)): #speak.Speak("Hover") print("Hover") if drone != None: drone.hover() gotother = 0 gotopposite = 0 keypress = False speak.Speak("Finished") print("Ready for new prediction, five exit") prevPreviousPrediction = previousPrediction previousPrediction = prediction return blinks, opposite, otherkey, pressedKey, keypress,\ previousPrediction, prevPreviousPrediction, gotfive,\ gotother, gotopposite, lastTime
def printData(sample): global intervalcounter, predictioncondition, counterlock, error ##For debugging global start, oldStart start = datetime.now() #print(start-oldStart) #oldStart = start xt = tme.time() if glb.fs == 125.0: offset = 2 start = 1 else: offset = 1 start = 0 if ((sample.id - offset) == glb.oldSampleID) or (glb.oldSampleID == 255 and sample.id == start): for i in range(numCh): glb.newSamples[i].append(sample.channel_data[i]) glb.newTimeData[i].append(xt) glb.oldSampleID = sample.id else: print("Lost packet, flushing databuffer") print("Old packet ID = %d" % glb.oldSampleID) print("Incomming packet ID = %d" % sample.id) speak.Speak("Lost packet") glb.oldSampleID = sample.id with glb.mutex: for i in range(numCh): del glb.newTimeData[i][:] del glb.newSamples[i][:] for j in range(3): del glb.data[i][j][:] #if predictioncondition == True: #print("predictioncondition is true") #with counterlock: #print("got lock") intervalcounter += 1 if intervalcounter >= predictioninterval: #print("New predict:") intervalcounter = 0 #predict.predictRealTime(**predictionParameters) with glb.rtLock: #print("Serial rt lock") if not glb.rtQueue.full(): glb.rtQueue.put(start) else: popped = glb.rtQueue.get() glb.rtQueue.put(start) #predictionThread = threading.Thread(target=predict.predictRealTime,kwargs=(predictionParameters)) #predictionThread.setDaemon(True) #predictionThread.start() if len(glb.newSamples[0]) >= glb.window: with glb.mutex: #sprint("From datacatcher b.glb: ") #print glb.b for i in range(numCh): if filterlib.filter(glb.newSamples, glb.newTimeData, i, glb.b, glb.a): glb.newTimeData[i][:] = [] glb.newSamples[i][:] = [] if error: with glb.mutex: while len(glb.data[0][0]) >= nSamples: for i in range(numCh): glb.data[i][rawdata].pop(0) glb.data[i][filterdata].pop(0) glb.data[i][timestamp].pop(0)