2017-10-30 15:01:26 +00:00
|
|
|
# Python 3
|
2017-11-22 19:03:42 +00:00
|
|
|
# Copyright (c) 2017 Mycroft AI Inc.
|
2017-10-30 15:01:26 +00:00
|
|
|
|
|
|
|
from collections import namedtuple
|
|
|
|
from math import floor
|
|
|
|
|
|
|
|
|
2017-11-21 22:30:22 +00:00
|
|
|
def _make_cls() -> type:
|
2017-10-30 15:01:26 +00:00
|
|
|
cls = namedtuple('ListenerParams', 'window_t hop_t buffer_t sample_rate sample_depth n_mfcc n_filt n_fft')
|
|
|
|
|
|
|
|
def add_prop(name, fn):
|
|
|
|
setattr(cls, name, property(fn))
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
add_prop('buffer_samples', lambda s: s.hop_samples * (int(np.round(s.sample_rate * s.buffer_t)) // s.hop_samples))
|
|
|
|
add_prop('window_samples', lambda s: int(np.round(s.sample_rate * s.window_t)))
|
|
|
|
add_prop('hop_samples', lambda s: int(np.round(s.sample_rate * s.hop_t)))
|
|
|
|
|
|
|
|
add_prop('n_features', lambda s: 1 + int(floor((s.buffer_samples - s.window_samples) / s.hop_samples)))
|
|
|
|
add_prop('feature_size', lambda s: s.n_mfcc)
|
|
|
|
add_prop('max_samples', lambda s: int(s.buffer_t * s.sample_rate))
|
|
|
|
return cls
|
|
|
|
|
|
|
|
|
|
|
|
ListenerParams = _make_cls()
|