コード例 #1
0
def process_file(wav_file, class_labels, to_csv, num_files, output_file,
                 ten_seconds, num_predictions, threshold):
    print(wav_file)
    files = tf.io.gfile.glob(wav_file)
    total_predictions = []
    examples = []
    print('Number of predictions ' + str(num_predictions))
    print('Threshold ' + str(threshold))
    if not files:
        raise IOError("Unable to find input files. data_pattern='" + wav_file +
                      "'")
    if num_files == 0:
        num_files = len(files)
    for i in range(0, num_files):
        if not files[i]:
            i = i + 1
        sr, data = wavfile.read(files[i])
        if data.dtype != np.int16:
            raise TypeError('Bad sample type: %r' % data.dtype)

        print(i)
        print(files[i])

        # local import to reduce start-up time
        from audio.processor import WavProcessor, format_predictions

        with WavProcessor() as proc:
            if ten_seconds == False:
                predictions = proc.get_predictions(wav_file, sr, data,
                                                   num_predictions, threshold,
                                                   class_labels)
                print('Predictions')
                print(format_predictions(predictions))
                if to_csv == True:
                    examples.append(int(len(data) / 44100))
                    total_predictions.append(predictions)

            else:
                predictions = proc.get_predictions2(sr, data, num_predictions,
                                                    threshold, class_labels)
                print('Predictions')
                for i in range(0, len(predictions)):
                    print(str(i) + ' ' + format_predictions(predictions[i]))
                if to_csv == True:
                    examples.append(int(len(data) / 44100))
                    total_predictions.append(predictions)

    if to_csv == True:
        from audio.processor import WavProcessor, format_predictions
        with WavProcessor() as proc:
            if ten_seconds == False:
                proc.toCSV(examples, wav_file, num_files, output_file,
                           total_predictions)
            else:
                proc.toCSV2(examples, wav_file, num_files, output_file,
                            total_predictions)
コード例 #2
0
    def _process_loop(self):
        with WavProcessor() as proc:
            self._ask_data_event.set()
            while self.is_running:
                if self._process_buf is None:
                    # Waiting for data to process
                    time.sleep(self._processor_sleep_time)
                    continue

                self._ask_data_event.clear()
                if self._save_path:
                    f_path = os.path.join(
                        self._save_path, 'record_{:.0f}.wav'.format(time.time())
                    )
                    wavfile.write(f_path, self._sample_rate, self._process_buf)
                    logger.info('"{}" saved'.format(f_path))

                logger.info('Start processing')
                predictions = proc.get_predictions(
                    self._sample_rate, self._process_buf)
                formatted = format_predictions(predictions)
                logger.info('Predictions: {}'.format(formatted))

                self.events_queue.append((datetime.datetime.now(), formatted))
                self._send_dh(predictions)

                logger.info('Stop processing')
                self._process_buf = None
                self._ask_data_event.set()
コード例 #3
0
    def _process_loop(self):
        with WavProcessor() as proc:
            self._ask_data.set()
            while True:
                if self._process_buf is None:
                    # Waiting for data to process
                    time.sleep(self._processor_sleep_time)
                    continue

                self._ask_data.clear()
                if self._save_path:
                    f_path = os.path.join(
                        self._save_path,
                        'record_{:.0f}.wav'.format(time.time()))
                    wavfile.write(f_path, self._sample_rate, self._process_buf)
                    logger.info('"{}" saved.'.format(f_path))

                logger.info('Start processing.')
                predictions = proc.get_predictions(self._sample_rate,
                                                   self._process_buf)
                logger.info('Predictions: {}'.format(
                    format_predictions(predictions)))

                logger.info('Stop processing.')
                self._process_buf = None
                self._ask_data.set()
コード例 #4
0
    def _process_loop(self):
        with WavProcessor() as proc:
            self._ask_data.set()
            while True:
                if self._process_buf is None:
                    # Waiting for data to process
                    time.sleep(self._processor_sleep_time)
                    continue

                self._ask_data.clear()
                if self._save_path:
                    f_path = os.path.join(
                        self._save_path, 'record_{:.0f}.wav'.format(time.time())
                    )
                    wavfile.write(f_path, self._sample_rate, self._process_buf)
                    logger.info('"{}" saved.'.format(f_path))

                logger.info('Start processing.')
                predictions = proc.get_predictions(
                    self._sample_rate, self._process_buf)
                logger.info(
                    'Predictions: {}'.format(format_predictions(predictions))
                )

                logger.info('Stop processing.')
                self._process_buf = None
                self._ask_data.set()
コード例 #5
0
def process_file(wav_file):
    sr, data = wavfile.read(wav_file)
    if data.dtype != np.int16:
        raise TypeError('Bad sample type: %r' % data.dtype)

    # local import to reduce start-up time
    from audio.processor import WavProcessor, format_predictions

    with WavProcessor() as proc:
        predictions = proc.get_predictions(sr, data)

    print(format_predictions(predictions))
コード例 #6
0
def process_file(wav_file, ckpt_file, labels_file):
    sr, data = wavfile.read(wav_file)
    print(wav_file, end=' ')

    if data.dtype != np.int16:
        raise TypeError('Bad sample type: %r' % data.dtype)
    
    predictions = []
    with WavProcessor(ckpt_file, labels_file) as proc:
        try:
            predictions = proc.get_predictions(sr, data)
            print(format_predictions(predictions))
        except:
            print('CORRUPTED!')
    return predictions
コード例 #7
0
    def _process_loop(self):
        with WavProcessor() as proc:
            self._ask_data.set()
            while True:
                if self._process_buf is None:
                    # Waiting for data to process
                    time.sleep(self._processor_sleep_time)
                    continue

                self._ask_data.clear()
                if self._save_path:
                    f_path = os.path.join(
                        self._save_path,
                        'record_{:.0f}.wav'.format(time.time()))
                    wavfile.write(f_path, self._sample_rate, self._process_buf)
                    logger.info('"{}" saved.'.format(f_path))

                logger.info('Start processing.')
                predictions = proc.get_predictions(self._sample_rate,
                                                   self._process_buf)
                logger.info('Predictions: {}'.format(
                    format_predictions(predictions)))
                my_dict = {x[0]: x[1] for x in predictions}
                msg_json = {
                    "app_id": "openears",
                    "dev_id": "TEST001",
                    "payload_fields": my_dict,
                    "time": int(time.time() * 1e3)
                }
                msg_str = json.dumps(msg_json)
                auth = {"username": mqtt_user, "password": mqtt_password}
                publish.single("pipeline/openears/TEST001",
                               payload=msg_str,
                               hostname=mqtt_host,
                               port=mqtt_port,
                               auth=auth)
                print('message sent')
                logger.info('Stop processing.')
                self._process_buf = None
                self._ask_data.set()