def spectrum(x, sample_rate=8192, win_len=128): assert bin(win_len).count('1') == 1 assert len(x) >= win_len def _next(): for _p in range(0, len(x) - win_len + 1, win_len // 2): yield x[_p:_p + win_len] raise StopIteration() h = hamming_window(win_len) f = FFT() fbins = mel_bins(24) ibins = np.floor((win_len + 1) * fbins / sample_rate).astype(np.int) ret = [] for win in _next(): s = f.fft(win * h) p = np.square(np.abs(s)) / win_len temp = [None] * (len(ibins) - 2) for i in range(len(ibins) - 2): a, b, c = ibins[i], ibins[i + 1], ibins[i + 2] left = np.sum(p[a:b] * np.linspace(0, 1, b - a)) right = np.sum(p[b:c] * np.linspace(1, 0, c - b)) temp[i] = np.log(left + right + 1e-100) ret.append(dct(np.array(temp, dtype=np.float))) return np.array(ret)
ret = "跌倒了啊啊啊啊啊啊!!!" output = output[4:] temperature, heartCondition = output.split(",") print("溫度:" + temperature, end="℃ ") temperature = float(temperature) if temperature_flag == False and temperature > 40: ret = "氣溫過高,請注意保持身體水分" temperature_flag = True elif temperature_flag == False and temperature < 15: ret = "氣溫過低,請注意保暖" temperature_flag = True elif temperature_flag and temperature > 15 and temperature < 40: temperature_flag = False tmp = fft.fft(float(heartCondition)) if tmp != None: print(tmp, end='') #print('\n',time.time()-st) if ret != None: print('bot:', ret, '\n') tts.tts(ret) if ret == "親愛的再見": exit() """ #if "1" in fallCondtion: # ret = fallAlert()