def process(q, frames, sampwidth, countfile): writetofile(frames, sampwidth, countfile) with open('recording'+str(countfile)+'.wav','rb') as file: data = file.read() print(sys.getsizeof(data)) if sys.getsizeof(data) < pow(2,19): print("put in queue") q.put(chatbot.chat_bot(rec(data))) else: q.put(chatbot.chat_bot('абрикосики4847'))
import socket import recognition host = "127.0.0.1" port = 8282 client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((host, port)) import time while True: #url = client.recv(4096).decode('utf-8') output = recognition.rec('http://172.20.10.2:8080/?action=snapshot') client.send(output.encode('utf-8')) time.sleep(1)
def main(): global news_archive global cmd global SoundLevel, CurrentTemp, SongPlayer # getTempAndHumity() ### initialize subprocess.call(['sudo', 'insmod', './eslab/final/dht11.ko']) # subprocess.call(['sudo', 'insmod', './dht11.ko']) fanDevice = BLE.BLEdevice() CurrentTemp = getTemp() util.ChangeSoundLevel(SoundLevel) GPIO.setmode(GPIO.BOARD) ## Use board pin numbering GPIO.setup(37, GPIO.OUT) ## Setup GPIO Pin 7 to OUT ### print("Current temp is {}".format(CurrentTemp)) print("initialize done") while True: print(">>>> command : {}".format(cmd)) while True: if fanDevice.fanPower == 'on': tmpTemp = getTemp() if tmpTemp - CurrentTemp > 1.0: os.system('mpv ./sounds/tempup.mp3') fanDevice.speedUpFan() elif CurrentTemp - tmpTemp > 1.0: os.system('mpv ./sounds/tempdown.mp3') fanDevice.speedDownFan() ## listen print("[main] Listening") if DEBUG: print("DEBUG is on, please type your command") cmd = input() else: cmd = recognition.rec() print("command is : ",cmd) if cmd == 0 : continue else : break if "天氣" in cmd: print(">>>> command : {}".format(cmd)) flag = 0 for it in city_dict: if it in cmd: city = it flag = 1 break if flag == 0: city = '台北' sstr = weather_crawer.get_weather(city) recognition.t2speech(sstr) ## call craw_weather elif "現在" in cmd: if "時間" in cmd: sstr = getCTime() recognition.t2speech(sstr) cmd = '' elif "氣溫" in cmd or "溫度" in cmd or "溫濕度" in cmd: sstr = getTempAndHumity() recognition.t2speech(sstr) cmd = '' elif "新聞" in cmd: if news_archive == None: util.SayCrawingNews() sstr = news_crawer.craw_hot() news_archive = sstr if '第' in cmd: idx = util.getint(cmd) if idx > len(news_archive): recognition.t2speech("錯誤,請再念一次") else: print("[main] Get index : ",idx) readNews(idx) else: recognition.t2speech("以下為今日的熱門新聞") tmp = [] for it in sstr: tmp.append(str(it['rank']) + ',' + it['title']) # recognition.t2speech("{},,{}".format(it['rank'], it['title'])) tmp = ',,'.join(tmp) recognition.t2speech(tmp) elif "關機" in cmd or "掰掰" in cmd: recognition.t2speech("掰掰") break elif "歌" in cmd or '音樂' in cmd: recognition.t2speech("請問你要聽什麼歌") if DEBUG: print("DEBUG is on, please type your command") quer = input() else: quer = recognition.rec() print(quer) play_music_from_youtube(quer) elif "風扇" in cmd or "電扇" in cmd: if '打開' in cmd or '關' in cmd: fanDevice.fanPowerSwitch() sstr = None elif '強' in cmd or '快' in cmd: sstr = fanDevice.speedUpFan() elif '弱' in cmd or '慢' in cmd: sstr = fanDevice.speedDownFan() if sstr != None: recognition.t2speech(sstr) elif "音量" in cmd or "聲音" in cmd: if "大" in cmd or '高' in cmd: if SoundLevel != 80: SoundLevel +=5 util.ChangeSoundLevel(SoundLevel) os.system('mpv ./sounds/IncreaseSound.mp3') else: os.system('mpv ./sounds/AlreadyMaxSound.mp3') # recognition.t2speech("已經是最大聲了") elif "小" in cmd or "低" in cmd: if SoundLevel != 5: SoundLevel -=5 util.ChangeSoundLevel(SoundLevel) os.system('mpv ./sounds/DecreaseSound.mp3') else: os.system('mpv ./sounds/AlreadyMinSound.mp3') # recognition.t2speech("已經是最小聲了") else: print("cmd is none of anyone") print("cmd :",cmd) os.system('mpv ./sounds/sayagain.mp3') cmd=''
import numpy as np import recognition as rec import matplotlib.pyplot as plt # create the recognizer print("What would you like to plot?") rec.rec() f = open("my_result.txt", "r") result = (f.read()) print("You said:", result)