class Audio: RESPEAKER_RATE = 16000 RESPEAKER_CHANNELS = 1 RESPEAKER_WIDTH = 2 # import sounddevice as sd # print sd.query_devices() RESPEAKER_INDEX = 2 # refer to input device id CHUNK = 1024 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME = "sc.wav" def __init__(self): dev = usb.core.find(idVendor=0x2886, idProduct=0x0018) self.mic_tuning = Tuning(dev) self.mic_tuning.set_vad_threshold(3.5) self.recording = False def readDOA(self): return self.mic_tuning.direction def readVAD(self): return self.mic_tuning.is_voice() @staticmethod def getSampleSize(): p = pyaudio.PyAudio() return p.get_sample_size(p.get_format_from_width( Audio.RESPEAKER_WIDTH)) def record(self): p = pyaudio.PyAudio() try: stream = p.open(rate=Audio.RESPEAKER_RATE, format=p.get_format_from_width( Audio.RESPEAKER_WIDTH), channels=Audio.RESPEAKER_CHANNELS, input=True) except IOError: return frames = [] for i in range( 0, int(Audio.RESPEAKER_RATE / Audio.CHUNK * Audio.RECORD_SECONDS)): data = stream.read(Audio.CHUNK) frames.append(data) stream.stop_stream() stream.close() wf = wave.open(Audio.WAVE_OUTPUT_FILENAME, 'wb') wf.setnchannels(1) wf.setsampwidth( p.get_sample_size(p.get_format_from_width(Audio.RESPEAKER_WIDTH))) wf.setframerate(Audio.RESPEAKER_RATE) wf.writeframes(b''.join(frames)) wf.close()
from tuning import Tuning import usb.core import usb.util import time dev = usb.core.find(idVendor=0x2886, idProduct=0x0018) #print dev if dev: Mic_tuning = Tuning(dev) print Mic_tuning.is_voice() Mic_tuning.set_vad_threshold(15.0) while True: try: # print Mic_tuning.read('GAMMAVAD_SR') print(Mic_tuning.read('SPEECHDETECTED'),Mic_tuning.is_voice()) # print Mic_tuning.is_voice() time.sleep(0.05) except KeyboardInterrupt: break
from tuning import Tuning from pixel_ring import pixel_ring import usb.core import usb.util import time dev = usb.core.find(idVendor=0x2886, idProduct=0x0018) #print dev if dev: Mic_tuning = Tuning(dev) # print Mic_tuning.is_voice(), Mic_tuning.direction i = Mic_tuning.is_voice() j = Mic_tuning.direction while True: Mic_tuning.set_vad_threshold(1.5) # pixel_ring.set_brightness(0x00) #turn off LED to conserve power try: #if (Mic_tuning.is_voice == True): #Attempting to refine code to only show when Mic_tuning.is_voice is 1 print Mic_tuning.is_voice( ), Mic_tuning.direction #Displays values 0 for noise or 1 for # human voice and Degrees time.sleep(1) except KeyboardInterrupt: break