示例#1
0
 def swipeSound(self):
     while True:
         if not self.shutDown.empty():
             break
         try:
             data = self.sound.get_nowait()
         except queue.Empty:
             #print('queue empty')
             time.sleep(0.04)
         else:
             #print(self.sound.empty())
             # self.cnt = 0
             #print('Data length: ', len(data))
             data = data.astype('float64')
             #print(len(data))
             # t0 = time.perf_counter()
             sw = swipe(data,
                        self.RATE,
                        int(self.CHUNK / self.swipesPerChunk),
                        min=self.minfreq,
                        max=self.maxfreq,
                        threshold=self.threshold)
             #print('swipe time: ', time.perf_counter()-t0)
             self.swipes.put(sw)
             #print('swipe length: ', len(sw))
     return True
示例#2
0
def do_job():
    # global unprocessed_sound
    global cnt, pitch, tp
    print('in do_job')
    while True:
        try:
            data = unprocessed_sound.get_nowait()
        except queue.Empty:
            print('swipe empty')
            cnt += 1
            print('queue empty, cnt: ', cnt)
            if cnt > 3:
                break
            time.sleep(0.1)
        else:
            cnt = 0
            print('Data length: ', len(data))
            data = data.astype('float64')
            t0 = time.perf_counter()
            sw = swipe(data,
                       RATE,
                       int(CHUNK / 5),
                       min=30,
                       max=800,
                       threshold=0.25)
            print('swipe time: ', time.perf_counter() - t0)
            swipes_toplot.put(sw)
            print('swipe length: ', len(sw))
    return True
示例#3
0
    def onNewData(self):
        print(time.process_time() - self.t0)
        self.t0 = time.process_time()
        try:
            data = np.array(
                struct.unpack(
                    str(self.CHUNK) + 'h', self.stream.read(
                        self.CHUNK)))  #,exception_on_overflow = False)))

        except:
            data = np.take(self.sound, range(-self.CHUNK, -1))
            #data = np.array(struct.unpack(str(self.CHUNK) + 'h', self.stream.read(self.CHUNK,exception_on_overflow = False)))
            print('overflow')
        data = data.astype('float64')
        print(len(data))
        self.sound = np.roll(self.sound, -len(data))

        t1 = time.process_time()
        sw = swipe(data, self.RATE, self.dt, min=40, max=1000, threshold=0.25)
        print(time.process_time() - t1)

        self.pitch = np.roll(self.pitch, -len(sw))

        np.put(self.sound, range(-len(data), -1), data)
        np.put(self.pitch, range(-len(sw), -1), sw)

        self.plotDataItem.setData(self.tp, self.pitch)
示例#4
0
    def do_job(self):
        #print('in do_job')
        while True:
            try:
                self.shut_down_queue.get_nowait()
            except:
                try:

                    data = self.unprocessed_sound.get_nowait()
                except queue.Empty:
                    #print('queue empty')
                    time.sleep(0.04)
                else:
                    print(self.unprocessed_sound.empty())
                    # self.cnt = 0
                    #print('Data length: ', len(data))
                    data = data.astype('float64')
                    #print(len(data))
                    t0 = time.perf_counter()
                    sw = swipe(data,
                               self.RATE,
                               int(self.CHUNK / 5),
                               min=30,
                               max=1200,
                               threshold=0.25)
                    print('swipe time: ', time.perf_counter() - t0)
                    self.swipes_toplot.put(sw)
                    #print('swipe length: ', len(sw))
            else:
                break
        return True
示例#5
0
 def extract_pitch(self, audio_signal):
     audio = np.asarray(audio_signal, dtype=np.float64)
     pitch = sptk.swipe(audio,
                        self.sample_rate,
                        self.frame_len * self.sample_rate / 1000,
                        otype=0,
                        min=60.0,
                        max=350.0)
     return pitch
示例#6
0
    def calc_pitch(self):
        print('calc')
        self.busy = True
        dl = self.cnt * self.CHUNK
        dt = int(dl / self.nbr_pitch)
        data = self.sound[range(-dl, -1)]
        data = data.astype('float64')
        print(dl)
        sw = swipe(data, self.RATE, dt, min=40, max=700, threshold=0.15)
        self.pitch = np.roll(self.pitch, -len(sw))

        # self.plotSoundData.setData(self.t, self.sound)
        self.busy = False
示例#7
0
    def update(self):

        data = np.array(struct.unpack(str(self.CHUNK) + 'h', self.stream.read(self.CHUNK,exception_on_overflow = False)))
        data = data.astype('float64')
        self.sound = np.roll(self.sound,-len(data))

        sw = swipe(data,self.RATE,self.dt,min=40,max=700,threshold=0.25)

        self.pitch = np.roll(self.pitch,-len(sw))

        np.put(self.sound,range(-len(data),-1),data)
        np.put(self.pitch,range(-len(sw),-1),sw)

        self.set_plotdata()
示例#8
0
    def onNewData(self):
        # data = np.array(struct.unpack(str(self.CHUNK) + 'h', self.stream.read(self.CHUNK,exception_on_overflow = False)))
        data = np.frombuffer(self.stream.read(self.CHUNK,exception_on_overflow=False), dtype=np.int16)
        data = data.astype('float64')

        self.sound = np.roll(self.sound,-len(data))
        np.put(self.sound,range(-len(data),-1),data)

        sw = swipe(data,self.RATE,self.dt,min=40,max=700,threshold=0.25)
        self.pitch = np.roll(self.pitch,-len(sw))
        np.put(self.pitch,range(-len(sw),-1),sw)


        self.plotPitches.setData(self.tp, self.pitch)
        self.plotSound.setData(self.t, self.sound)
示例#9
0
    def audio_callback(self, in_data, frame_count, time_info, status):
        print('in callback')
        t = time.perf_counter()
        audio_data = np.frombuffer(in_data, dtype=np.int16)
        self.sound = np.roll(self.sound,-len(audio_data))
        np.put(self.sound,range(-len(audio_data),-1),audio_data)
        audio_data = audio_data.astype('float64')

        sw = swipe(audio_data,self.RATE,self.dt,min=40,max=1200,threshold=0.25)
        # sw[sw==0] = np.nan
        self.pitch = np.roll(self.pitch,-len(sw))
        np.put(self.pitch,range(-len(sw),-1),sw)

        self.update_plot()
        print(time.perf_counter()-t)
        return(in_data,pyaudio.paContinue)
示例#10
0
    def onNewData2(self):
        noteTimes = notesTimeMap(self.tp+self.simtime,notes)
        self.simtime += self.loop
        self.plotNotesLower.setData(self.tp+5, noteTimes/1.03)
        self.plotNotesUpper.setData(self.tp+5, noteTimes*1.03)

        data = np.frombuffer(self.stream.read(self.CHUNK,exception_on_overflow=False), dtype=np.int16)
        data = data.astype('float64')

        self.sound = np.roll(self.sound,-len(data))
        np.put(self.sound,range(-len(data),-1),data)

        sw = swipe(data,self.RATE,self.dt,min=40,max=700,threshold=0.25)
        self.pitch = np.roll(self.pitch,-len(sw))
        np.put(self.pitch,range(-len(sw),-1),sw)

        self.plotPitches.setData(self.tp, self.pitch)
        self.plotSound.setData(self.t, self.sound)
示例#11
0
    def swipeSound(self):
        while True:
            if not self.shutDown.empty():
                break
            try:
                data = self.sound.get_nowait()
            except queue.Empty:

                time.sleep(0.04)
            else:
                data = data.astype('float64')
                sw = swipe(data,
                           self.RATE,
                           int(self.CHUNK / self.swipesPerChunk),
                           min=self.minfreq,
                           max=self.maxfreq,
                           threshold=self.threshold)
                self.swipes.put(sw)
        return True
示例#12
0
    def updateSound(self):
        data = np.frombuffer(self.stream.read(self.CHUNK,
                                              exception_on_overflow=False),
                             dtype=np.int16)
        data = data.astype('float64')

        self.sound = np.roll(self.sound, -len(data))
        np.put(self.sound, range(-len(data), -1), data)
        self.ts += self.loop

        sw = swipe(data,
                   self.SAMPLERATE,
                   self.dt,
                   min=40,
                   max=700,
                   threshold=0.25)
        self.pitches = np.roll(self.pitches, -len(sw))
        np.put(self.pitches, range(-len(sw), -1), sw)
        self.tp += self.loop
示例#13
0
    def audio_callback(self, in_data, frame_count, time_info, status):

        # print('callb period: ', time.process_time() - self.tcallb) this print f***s things up sometimes..
        # self.tcallb = time.process_time()
        # audio_data = np.frombuffer(in_data, dtype=np.int16)
        # audio_data = audio_data.astype('float16')
        audio_data = np.array(struct.unpack(str(self.CHUNK) + 'h', in_data))
        audio_data = audio_data.astype('float64')
        # print(audio_data)
        # print(len(audio_data))
        # print(self.CHUNK)
        self.sound = np.roll(self.sound,-len(audio_data))
        np.put(self.sound,range(-len(audio_data),-1),audio_data)

        # print(audio_data)
        sw = swipe(audio_data,self.RATE,self.dt,min=40,max=1000,threshold=0.2)
        self.pitch = np.roll(self.pitch,-len(sw))
        np.put(self.pitch,range(-len(sw),-1),sw)

        # print('in_data: ',len(in_data))
        print('audio_data: ', len(audio_data))
        return(in_data,pyaudio.paContinue)
示例#14
0
    def swipeSound(self):
        while True:
            if not self.shutDown.empty():
                break
            try:
                data = self.sound.get_nowait()
            except queue.Empty:

                time.sleep(0.04)
            else:
                data = data.astype('float64')
                sw = swipe(data, self.RATE,
                           int(self.CHUNK / self.swipesPerChunk),
                           min=self.minfreq, max=self.maxfreq,
                           threshold=self.threshold)
                self.swipes.put(sw)
                tt, frequency, confidence, activation = crepe.predict(
                    data, self.RATE, model_capacity='full')
                # self.swipes.put(frequency)
                print('FREQUENCY: ', frequency)
                print('TIME', tt)

        return True
示例#15
0
t0 = time.process_time()
while True:
    # compute something
    print('loop', time.process_time() - t0)
    t0 = time.process_time()
    data = np.array(
        struct.unpack(
            str(CHUNK) + 'h', stream.read(CHUNK, exception_on_overflow=False)))
    t55 = time.process_time()
    print('get rec ', t55 - t0)
    data = data.astype('float64')
    sound = np.roll(sound, -len(data))
    t59 = time.process_time()
    print('roll sound ', t59 - t55)

    sw = sptk.swipe(data, RATE, dt, min=40, max=700, threshold=0.25)
    t63 = time.process_time()
    print('swipe', t63 - t59)
    # print(len(sw))
    # t2 = time.process_time()
    # print('Swipe time ',t2-t1)

    pitch = np.roll(pitch, -len(sw))
    t70 = time.process_time()
    print('roll pitch ', t70 - t63)
    # print('length from swipe ',len(sw))
    # print('length of pitch ', len(pitch))

    # print('Pitch len ',len(pitch))
    # print('sw len ', len(sw))
    # print('pitch time ',dt*len(pitch)/RATE)
示例#16
0
#time.sleep(2)

while True:

    # compute something
    t0 = time.process_time()
    data = np.array(
        struct.unpack(
            str(CHUNK) + 'h', stream.read(CHUNK, exception_on_overflow=False)))
    t1 = time.process_time()
    # print('53',t1-t0)

    data = data.astype('float64')
    sound = np.roll(sound, -len(data))

    p = sptk.swipe(data, RATE, dt, min=50, max=500, threshold=0.3)
    t2 = time.process_time()
    # print('60',t2-t1)
    # print(len(sound))
    pitch = np.roll(pitch, -len(p))
    # print(len(p))
    # print(len(pitch))

    # print(CHUNK)
    # print(data)

    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    print(current_time + " " + str(p))

    # print("Pitch: " + str(pitch))