def test_8mic(): import signal import time from pixel_ring import pixel_ring is_quit = threading.Event() def signal_handler(sig, num): is_quit.set() print('Quit') signal.signal(signal.SIGINT, signal_handler) with MicArray(16000, 4, 16000 / 4) as mic: for chunk in mic.read_chunks(): direction = mic.get_direction(chunk) pixel_ring.set_direction(direction) pixel_ring.spin() #print(direction) #print(chunk) #print('Test before direction') print(int(direction)) if is_quit.is_set(): break pixel_ring.off()
def main(): vad = webrtcvad.Vad(3) speech_count = 0 chunks = [] doa_chunks = int(DOA_FRAMES / VAD_FRAMES) try: with MicArray(RATE, CHANNELS, RATE * VAD_FRAMES / 1000) as mic: for chunk in mic.read_chunks(): # Use single channel audio to detect voice activity if vad.is_speech(chunk[0::CHANNELS].tobytes(), RATE): speech_count += 1 sys.stdout.write('1') #Sound detected else: sys.stdout.write('0') #No sound detected sys.stdout.flush() chunks.append(chunk) if len(chunks) == doa_chunks: if speech_count > (doa_chunks / 2): frames = np.concatenate(chunks) direction = mic.get_direction(frames) pixel_ring.set_direction(direction) pixel_ring.spin() print('\n{}'.format(int(direction))) speech_count = 0 chunks = [] except KeyboardInterrupt: pass pixel_ring.off()
def main(): # See http://g.co/cloud/speech/docs/languages # for a list of supported languages. language_code = 'ja-JP' #'en-US' # a BCP-47 language tag while True: state = GPIO.input(BUTTON) if state: print('Press the button and speak') GPIO.output(LED, GPIO.HIGH) time.sleep(0.3) GPIO.output(LED, GPIO.LOW) time.sleep(0.3) continue else: print("Let's speak!") os.system(aquest_dir + 'AquesTalkPi -g {} {} | aplay -D plughw:{},{}'.format( VOLUME, "議事録作成を開始します!", CARD, DEVICE)) pixel_ring.spin() GPIO.output(LED, GPIO.HIGH) time.sleep(2) GPIO.output(LED, GPIO.LOW) pixel_ring.off() pass client = speech.SpeechClient() config = types.RecognitionConfig( encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=RATE, language_code=language_code) streaming_config = types.StreamingRecognitionConfig( config=config, interim_results=True) with MicrophoneStream(RATE, CHUNK) as stream: audio_generator = stream.generator() requests = (types.StreamingRecognizeRequest(audio_content=content) for content in audio_generator) responses = client.streaming_recognize(streaming_config, requests) # Now, put the transcription responses to use. listen_print_loop(responses)
def main(model): model = "alexa.umdl" if model is "" else model pixel_ring.spin() detector = SnowboyDetect('snowboy/resources/common.res', 'snowboy/resources/' + model) #alexa/alexa_02092017.umdl') detector.SetAudioGain(1) detector.SetSensitivity('0.5') #def main(): history = collections.deque(maxlen=int(DOA_FRAMES / KWS_FRAMES)) try: with MicArray(RATE, CHANNELS, RATE * KWS_FRAMES / 1000) as mic: for chunk in mic.read_chunks(): history.append(chunk) # Detect keyword from channel 0 ans = detector.RunDetection(chunk[0::CHANNELS].tostring()) if ans > 0: frames = np.concatenate(history) direction = mic.get_direction(frames) pixel_ring.set_direction(direction) if int(direction) > 90 and int(direction) <= 270: direct = "Back side" else: direct = "Front side" print('>> "' + model.split(".")[0].upper() + '" voice is from ' + direct) #'{}\n'.format(int(direction))) except KeyboardInterrupt: pass pixel_ring.off()
def spin(): pixel_ring.spin()
CHUNK = int(RATE / 10) # 100ms from datetime import datetime import argparse default_speech = 'ja-JP' import time import RPi.GPIO as GPIO BUTTON = 20 LED = 16 from pixel_ring import pixel_ring pixel_ring.spin() GPIO.setmode(GPIO.BCM) GPIO.setup(LED, GPIO.OUT) GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.add_event_detect(BUTTON,GPIO.FALLING) for i in range(3): GPIO.output(LED, GPIO.HIGH) time.sleep(0.5) GPIO.output(LED, GPIO.LOW) time.sleep(0.5) pixel_ring.off()
def main(): #detect="ja-JP", trans="", mail=""): recognizer = aiy.cloudspeech.get_recognizer() recognizer.expect_phrase('turn off the light') recognizer.expect_phrase('turn on the light') recognizer.expect_phrase('blink') recognizer.expect_phrase('repeat after me') button = aiy.voicehat.get_button() led = aiy.voicehat.get_led() aiy.audio.get_recorder().start() aiy.i18n.set_language_code(detect) import RPi.GPIO as GPIO BUTTON = 16 GPIO.setmode(GPIO.BCM) GPIO.setup(BUTTON, GPIO.IN) while True: print('Press the button and speak') state=GPIO.input(BUTTON) if state: print("off") else: print("on") #button.wait_for_press() i = 0 convs = [] convs_trans = [] while True: #try: """print('Press the button and speak') button.wait_for_press() print('Listening...') text = recognizer.recognize() with MicArray(RATE, CHANNELS, RATE * KWS_FRAMES / 1000) as mic: for chunk in mic.read_chunks(): history.append(chunk) # Detect keyword from channel 0 #ans = detector.RunDetection(chunk[0::CHANNELS].tostring()) text = recognizer.recognize() #chunk[0::CHANNELS].tostring()) print(text) #if ans > 0: #text = "Yes" if not text: print('Sorry, I did not hear you.') else: frames = np.concatenate(history) direction = mic.get_direction(frames) pixel_ring.set_direction(direction) print('\n{}'.format(int(direction))) direct_person = str(direction) + "KY" print(direct_person + ' said "', text, '"')""" #except KeyboardInterrupt: #pass #print('Press the button and start conversation') #button.wait_for_press() bye_words = ['Goodbye', 'Good bye', 'See you', 'Bye bye', '終わり', '終わりです', 'さようなら', 'バイバイ'] progress_words=['completed', 'confirmed', 'delayed', 'finished', 'discussed', 'fixed'] approve_words= ['agreed', 'approved'] next_words = ['next step', 'next Steps', 'next action', 'next actions'] issue_words = ['issue', 'issues', 'problem', 'error', 'dificit'] magic_words = ['magic minutes', 'magical minutes'] print('Listening in '+detect+'...') text = recognizer.recognize() if not text: print('Sorry, I did not hear you. Please say again') else: convDateTime = datetime.now() convDateStr = convDateTime.strftime('%Y-%m-%d %H:%M:%S') i += 1 directions = [] dir = [0, 180, 60, 300, 120, 240] for j in range(4): directions.extend(dir) direction = directions[i] #mic.get_direction(frames) pixel_ring.set_direction(direction) if direction > 45 and direction <= 135: direct = "Right" elif direction > 135 and direction <= 225: direct = "Back" elif direction > 225 and direction <= 315: direct = "Left" else: direct = "Front" #direct = str(direction) print('>> ' + direct + ' said "' + text + '"') if detect == "ja-JP": os.system(aquest_dir + ' -g {} {} | aplay -D plughw:{},{}'.format(VOLUME, text, CARD, DEVICE)) else: aiy.audio.say(text, detect) if trans: trans_text = translate_text(text, trans) trans_text = trans_text.replace("'","") print('Trans: ' + trans_text) if trans in aiy_lang: aiy.audio.say(trans_text, trans) elif trans == "ja-JP": os.system(aquest_dir + ' -g {} {} | aplay -D plughw:{},{}'.format(VOLUME, trans_text, CARD, DEVICE)) else: aiy.audio.say('Nothing to trans!', 'en-US') #else: #trans_lang = null then default en-US #aiy.audio.say(text, 'en-US') keyw = "conv" text.lower() #elif 'open Magic minutes' in text: #or 'open Magic minutes' or 'start magic minutes' in text: #pixel_ring.spin() #aiy.audio.say('Ok, Start recording your conversation!') #keyw = "MC" for m in magic_words: if trans_text.find(m) > -1: keyw = "MC" pixel_ring.spin() aiy.audio.say('Ok, make magic minutes!') break for a in progress_words: if trans_text.find(a) > -1: keyw = "progress" break for a in approve_words: if trans_text.find(a) > -1: keyw = "approve" break for a in issue_words: if trans_text.find(a) > -1: keyw = "issue" break for n in next_words: if trans_text.find(n) > -1: keyw = "next" break for b in bye_words: if trans_text.find(b) > -1: keyw = "bye" break conv = {"number": i, "person": direct, "convt": text, "keyw": keyw} convs.append(conv) if trans: conv_trans = {"number": i, "person": direct, "convt": trans_text, "keyw": keyw} convs_trans.append(conv_trans) if text in bye_words: if mail: dir_name = convDateTime.strftime('%Y%m%d') dir_path = '/home/pi/AIY-projects-python/msg/' + dir_name + '/' file_name= convDateTime.strftime('%H%M%S') + '.txt' fname = dir_path + file_name """os.makedirs(dir_path, exist_ok=True) with open(os.path.join(dir_path, file_name), mode) as f: f.write(minutes) try: os.system("sudo mkdir " + dir_path) #os.mkdir(dir_path) except OSError: print("Directory already exists")""" conv_org = "" conv_trans_org = "" progressw = "" conv_progress="" approvew = "" conv_approve= "" issuew = "" issuen = 0 conv_issue = "" nextw = "" nextn = 0 conv_next = "" direct_jp = {"Front":"前席の方の発言", "Right":"右側の方の発言", "Left":"左側の方の発言", "Back":"後席の方の発言"} for con in convs: conv_org += str(con["number"]) + '(' + direct_jp[con["person"]] + '): ' + con["convt"] + '\n' is_are = ["is","was","are","were", "it's", "its"] for con in convs_trans: if con["keyw"] not in ["MC", "MM", "bye"]: conv_trans_org += ' ' + str(con["number"]) + '(' + con["person"] + '): ' + con["convt"] + '\n' if con["keyw"] == "progress": progressw = con["convt"] conv_progress+= ' - ' + progressw + " by " + con["person"] + '\n' if con["keyw"] == "approve": approvew = con["convt"] """for a in approve_words + is_are: approvew = approvew.replace(a, "")""" conv_approve+= ' - ' + approvew + " by " + con["person"] + '\n' if con["keyw"] == "issue": issuen += 1 issuew = con["convt"] conv_issue += ' - #' + str(issuen) + ': ' + issuew + ' raised by ' + con["person"] + '\n' if con["keyw"] == "next": nextn += 1 nextw = con["convt"] """for a in next_words + is_are: nextw = nextw.replace(a, "")""" conv_next += ' - #' + str(nextn) + ': ' + nextw + '\n' #minutes = '= Meeting Minutes =\n\n' #minutes_jp= u'= 議事録 =\n\n' minutes = 'RE: Development Status\n' minutes_jp = '議題: 定例進捗会議\n' minutes += 'Date: ' +convDateStr + '\n' minutes_jp+= '日付: ' +convDateStr + '\n' minutes += 'MMinutes by: ' + mail + '\n' minutes_jp+= '作成者: ' + mail + '\n' if conv_progress: minutes+= '\n Project progress:\n' minutes+= conv_progress if conv_approve: minutes+= '\n Approved item(s):\n' minutes+= conv_approve if conv_issue: minutes+= '\n Issue(s):\n' minutes+= conv_issue if conv_next: minutes+= '\n Next action(s):\n' minutes+= conv_next minutes += '\n Meeting details: \n' minutes_jp+= '\n 会議内容: \n' minutes += conv_trans_org + '\n' minutes_jp+= conv_org + '\n' minutes += 'Meeting note is attached:' minutes_jp+= '添付資料:' subject = '"Todays Meeting minutes (' + convDateStr + ')"' subject_jp= '"本日の議事録 (' + convDateStr + ')"' header_jp = "本日行われましたお打合せの議事録を送付いたします。\n宜しくご査収お願い致します。" header_jp+= "(English follows)\n" if trans else "" header = "Please find the attached meeting minutes held today.\nPlease let me know if you have any qu$ magic_minutes = header_jp + '\n' + minutes_jp magic_minutes+= '\n' + header + '\n' + minutes if trans else "" print(magic_minutes) pixel_ring.spin() os.makedirs(dir_path, exist_ok=True) with open(os.path.join(dir_path, file_name), 'w') as f: f.write(magic_minutes) cmd = 'mutt -s ' + subject_jp + ' ' + mail + ' -a "/home/pi/AIY-projects-python/msg/mminutes2.jpg" < ' +$ os.system(cmd) if detect != "ja-JP": aiy.audio.say('Minutes is sent to ' + mail) if detect != "ja-JP": aiy.audio.say('See you again!') pixel_ring.off() break time.sleep(0.2) pixel_ring.off()
def main(): recognizer = aiy.cloudspeech.get_recognizer() recognizer.expect_phrase('turn off the light') recognizer.expect_phrase('turn on the light') recognizer.expect_phrase('blink') recognizer.expect_phrase('repeat after me') button = aiy.voicehat.get_button() led = aiy.voicehat.get_led() aiy.audio.get_recorder().start() import RPi.GPIO as GPIO BUTTON = 16 GPIO.setmode(GPIO.BCM) GPIO.setup(BUTTON, GPIO.IN) while True: print('Press the button and speak') state=GPIO.input(BUTTON) if state: print("off") else: print("on") #button.wait_for_press() i = 0 convs = [] while True: #try: """print('Press the button and speak') button.wait_for_press() print('Listening...') text = recognizer.recognize() with MicArray(RATE, CHANNELS, RATE * KWS_FRAMES / 1000) as mic: for chunk in mic.read_chunks(): history.append(chunk) # Detect keyword from channel 0 #ans = detector.RunDetection(chunk[0::CHANNELS].tostring()) text = recognizer.recognize() #chunk[0::CHANNELS].tostring()) print(text) #if ans > 0: #text = "Yes" if not text: print('Sorry, I did not hear you.') else: frames = np.concatenate(history) direction = mic.get_direction(frames) pixel_ring.set_direction(direction) print('\n{}'.format(int(direction))) direct_person = str(direction) + "KY" print(direct_person + ' said "', text, '"')""" #except KeyboardInterrupt: #pass #print('Press the button and start conversation') #button.wait_for_press() bye_words = ['goodbye', 'good bye', 'see you', 'bye bye'] progress_words=['completed', 'confirmed', 'delayed', 'finished', 'discussed', 'fixed'] approve_words= ['agreed', 'approved'] next_words = ['next step', 'next Steps', 'next action', 'next actions'] issue_words = ['issue', 'issues', 'problem', 'error', 'dificit'] magic_words = ['magic minutes', 'magical minutes'] print('Listening...') text = recognizer.recognize() if not text: print('Sorry, I did not hear you. Please say again') else: convDateTime = datetime.now() convDateStr = convDateTime.strftime('%Y-%m-%d %H:%M:%S') i += 1 directions = [] dir = [0, 180, 60, 300, 120, 240] for j in range(4): directions.extend(dir) direction = directions[i] #mic.get_direction(frames) pixel_ring.set_direction(direction) if direction > 90 and direction < 270: direct = "Back-side person" else: direct = "Front person" #direct = str(direction) print('>> ' + direct + ' said "' + text + '"') aiy.audio.say(text) keyw = "conv" text.lower() if 'turn on the light' in text: led.set_state(aiy.voicehat.LED.ON) elif 'turn off the light' in text: led.set_state(aiy.voicehat.LED.OFF) elif 'blink' in text: led.set_state(aiy.voicehat.LED.BLINK) elif 'repeat after me' in text: to_repeat = text.replace('repeat after me', '', 1) aiy.audio.say(to_repeat) #elif 'open Magic minutes' in text: #or 'open Magic minutes' or 'start magic minutes' in text: #pixel_ring.spin() #aiy.audio.say('Ok, Start recording your conversation!') #keyw = "MC" for m in magic_words: if text.find(m) > -1: keyw = "MC" pixel_ring.spin() aiy.audio.say('Ok, make magic minutes!') break for a in progress_words: if text.find(a) > -1: keyw = "progress" break for a in approve_words: if text.find(a) > -1: keyw = "approve" break for a in issue_words: if text.find(a) > -1: keyw = "issue" break for n in next_words: if text.find(n) > -1: keyw = "next" break for b in bye_words: if text.find(b) > -1: keyw = "bye" break conv = {"number": i, "person": direct, "convt": text, "keyw": keyw} convs.append(conv) if text in bye_words: #print(convs) if mail: dir_name = convDateTime.strftime('%Y%m%d') dir_path = '/home/pi/AIY-projects-python/msg/' + dir_name + '/' file_name= convDateTime.strftime('%H%M%S') + '.txt' fname = dir_path + file_name """os.makedirs(dir_path, exist_ok=True) with open(os.path.join(dir_path, file_name), mode) as f: f.write(minutes) try: os.system("sudo mkdir " + dir_path) #os.mkdir(dir_path) except OSError: print("Directory already exists")""" conv_org = "" progressw = "" conv_progress="" approvew = "" conv_approve= "" issuew = "" issuen = 0 conv_issue = "" nextw = "" nextn = 0 conv_next = "" is_are = ["is","was","are","were", "it's", "its"] for con in convs: if con["keyw"] not in ["MC", "MM", "bye"]: conv_org += ' ' + str(con["number"]) + '(' + con["person"] + '): ' + con["convt"] + '\n' if con["keyw"] == "progress": progressw = con["convt"] conv_progress+= ' - ' + progressw + " by " + con["person"] + '\n' if con["keyw"] == "approve": approvew = con["convt"] """for a in approve_words + is_are: approvew = approvew.replace(a, "")""" conv_approve+= ' - ' + approvew + " by " + con["person"] + '\n' if con["keyw"] == "issue": issuen += 1 issuew = con["convt"] """for a in issue_words + is_are: issuew = issuew.replace(a, "") """ conv_issue += ' - #' + str(issuen) + ': ' + issuew + ' raised by ' + con["person"] + '\n' if con["keyw"] == "next": nextn += 1 nextw = con["convt"] """for a in next_words + is_are: nextw = nextw.replace(a, "")""" conv_next += ' - #' + str(nextn) + ': ' + nextw + '\n' minutes = '= Meeting Minutes =\n\n' minutes+= 'RE: Development Status\n' minutes+= 'Date: ' +convDateStr + '\n' minutes+= 'MMinutes by: ' + mail + '\n' if conv_progress: minutes+= '\n Project progress:\n' minutes+= conv_progress if conv_approve: minutes+= '\n Approved item(s):\n' minutes+= conv_approve if conv_issue: minutes+= '\n Issue(s):\n' minutes+= conv_issue if conv_next: minutes+= '\n Next action(s):\n' minutes+= conv_next minutes+= '\n Meeting details: \n' minutes+= conv_org + '\n' minutes+= 'Meeting note is attached:' subject = '"Meeting minutes (' + convDateStr + ')"' print(subject + '\n' + minutes) pixel_ring.spin() os.makedirs(dir_path, exist_ok=True) with open(os.path.join(dir_path, file_name), 'w') as f: f.write(minutes) #cmd = 'echo ' + minutes + ' | mail -s ' + subject + ' ' + mail cmd = 'mutt -s ' + subject + ' ' + mail + ' -a "/home/pi/AIY-projects-python/msg/mminutes2.jpg" < ' + fname os.system(cmd) aiy.audio.say('Minutes is sent to ' + mail) aiy.audio.say('See you again!') pixel_ring.off() break time.sleep(0.2) pixel_ring.off()