Exemple #1
0
class ButtonRecorderPlayer(object):
    def __init__(self):
        self.isPlaying = True
        self.p = pyaudio
        self.rec = Recorder(channels=1)
        self.play = None
        self.playback_thread = threading.Thread(name='button_listener', target=self.button_listener)

    def on_button(self, channel):  # Called by inbuilt threaded interrupt
        print('button')
        if recPlayBtn.isPlaying:
            print('stoping playback and starting recording')
            recPlayBtn.stop_playback()
            recPlayBtn.isPlaying = False
            recPlayBtn.start_recording()
        else:
            print('stoping recording and starting playback')
            recPlayBtn.stop_recording()
            recPlayBtn.isPlaying = True
            recPlayBtn.start_playback()

    def button_listener(self):
        # with mouse.Listener( on_click = self.on_click) as listener:
        with gpio.add_event_detect(17, gpio.FALLING, callback=self.on_button, bouncetime=100) as listener:
            listener.join()
            print ('listener started')

    def start(self):
        self.playback_thread.start()
        self.start_playback()

    def start_recording(self, channel=1):
        print ('Recording, click to stop recording')
        timestr = time.strftime("%Y%m%d-%H%M%S")
        gpio.output(4, True) #LED on
        self.recfile = self.rec.open('recordings/' + timestr + '.wav', self.p, 'wb')
        self.recfile.start_recording()

    def stop_recording(self, channel=1):
        self.recfile.stop_recording()
        self.recfile.close()
        gpio.output(4, False) #LED on
        print ('Recording Stopped')

    def start_playback(self, channel=1):
        print ('playback starting')
        self.play = Player('recordings', self.p)
        self.play.start()

    def stop_playback(self):
        self.play.stopper()
        print ('playback stopped')
Exemple #2
0
class ButtonRecorderPlayer(object):
    def __init__(self):
        self.isRecording = False
        self.p = pyaudio
        self.rec = Recorder(channels=1)
        self.filename = ''
        self.t = TweetThis(filename=self.filename)

    def on_button(self, channel):
        print('button')
        if not recPlayBtn.isRecording:
            recPlayBtn.start_recording()
            recPlayBtn.isRecording = True
            time.sleep(1)
        else:
            recPlayBtn.stop_recording()
            recPlayBtn.isRecording = False
            gpio.remove_event_detect(17)
            recPlayBtn.listen()
            time.sleep(1)

    def listen(self):
        gpio.add_event_detect(17,
                              gpio.FALLING,
                              callback=recPlayBtn.on_button,
                              bouncetime=100)
        print('listening')

    def start_recording(self, channel=1):
        print('recording, click to stop recording')
        timestr = time.strftime("%Y%m%d-%H%M%S")
        gpio.output(4, True)  #LED on
        self.filename = 'twitter_recordings/' + timestr + '.wav'
        self.recfile = self.rec.open(self.filename, self.p, 'wb')
        self.recfile.start_recording()

    def stop_recording(self, channel=1):
        self.recfile.stop_recording()
        self.recfile.close()
        gpio.output(4, False)  #LED on
        print('recording stopped')
        print('tweeting', self.filename)
        self.t.start(self.filename)
        time.sleep(1)
Exemple #3
0
    def on_click_play(self):
        # Check if number of trials
        if self.trial_no.text().isdigit():
            repeditions = int(self.trial_no.text())
        else:
            repeditions = 1

        if not self.soundfiles:
            mb = QMessageBox()
            mb.setLayout
            questionstart = mb.information(
                self, "Information",
                "No sound files location selected. Please Open sounds' location first.",
                QMessageBox.No | QMessageBox.Yes, QMessageBox.Yes)
            pass
        else:
            counter = 1
            mb = QMessageBox()
            mb.setLayout
            questionstart = mb.information(self, "Information",
                                           "<font size = 10 >Ready?</font>",
                                           QMessageBox.No | QMessageBox.Yes,
                                           QMessageBox.Yes)

            if questionstart == mb.Yes:
                while counter <= repeditions:
                    if self.randomize.isChecked():
                        file_list_order = self.soundfiles
                        file_list_order = random.sample(
                            file_list_order, len(file_list_order))
                    else:
                        file_list_order = self.soundfiles

                    for s in file_list_order:
                        try:
                            if system() == "Windows":
                                os.system("start " + s)
                                time.sleep(.900)
                            else:
                                os.system("play " + s)
                                rec = Recorder()
                        except KeyboardInterrupt:
                            break
                        currentDT = datetime.datetime.now()
                        if self.speaker_name.text() == "":
                            recordedfile = 'sound-' + \
                                str(counter) + "-" + \
                                str(currentDT.strftime(
                                    "%Y-%m-%d-%H_%M")) + '.wav'
                        else:
                            recordedfile = self.speaker_name.text() + '-repedition-' + \
                                str(counter) + "-" + \
                                str(currentDT.strftime(
                                    "%Y-%m-%d-%H_%M")) + '.wav'
                            trial1record = QMessageBox.question(
                                self, "Repedition " + str(counter),
                                "Repedition " + str(counter) +
                                "\nRecording... Press Yes to move to the next sound. Press No to quit.",
                                QMessageBox.No | QMessageBox.Yes,
                                QMessageBox.Yes)
                        with rec.open(recordedfile, 'wb') as recfile:
                            recfile.start_recording()
                            if trial1record == QMessageBox.Yes:
                                recfile.stop_recording()
                            else:
                                recfile.stop_recording()
                                break
                    counter += 1

                QMessageBox.information(self, "Good job!", "Very good!")
            else:
                pass