# Path: sprocket/util/extfrm.py
# def extfrm(data, npow, power_threshold=-20):
#     """Extract frame over the power threshold
# 
#     Parameters
#     ----------
#     data: array, shape (`T`, `dim`)
#         Array of input data
#     npow : array, shape (`T`)
#         Vector of normalized power sequence.
#     power_threshold : float, optional
#         Value of power threshold [dB]
#         Default set to -20
# 
#     Returns
#     -------
#     data: array, shape (`T_ext`, `dim`)
#         Remaining data after extracting frame
#         `T_ext` <= `T`
# 
#     """
# 
#     T = data.shape[0]
#     if T != len(npow):
#         raise("Length of two vectors is different.")
# 
#     valid_index = np.where(npow > power_threshold)
#     extdata = data[valid_index]
#     assert extdata.shape[0] <= T
# 
#     return extdata
# 
# Path: sprocket/util/delta.py
# def static_delta(data, win=[-1.0, 1.0, 0]):
#     """Calculate static and delta component
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of static matrix sequence.
#     win: array, optional, shape (`3`)
#         The shape of window matrix.
#         Default set to [-1.0, 1.0, 0].
# 
#     Returns
#     -------
#     sddata: array, shape (`T`, `dim*2`)
#         Array static and delta matrix sequence.
# 
#     """
# 
#     sddata = np.c_[data, delta(data, win)]
#     return sddata
# 
# Path: sprocket/util/hdf5.py
# class HDF5(object):
#     """HDF5 handler
#     Offer the hdf5 format file handler
# 
#     Parameters
#     ---------
#     fpath : str,
#         Path of hdf5 file
# 
#     mode : str,
#         Open h5 as write and/or read mode
#         `a` : open as read/write (Default)
#         `w` : open as write only
#         `r` : open as read only
# 
#     Attributes
#     ---------
#     h5 : hdf5 class
# 
#     """
# 
#     def __init__(self, fpath, mode='a'):
#         self.fpath = fpath
#         self.dirname, self.filename = os.path.split(self.fpath)
#         self.flbl, _ = os.path.splitext(self.filename)
# 
#         # os.path.split(path)[0] returns "" if path doesn't contain '/'
#         if self.filename != "" and self.dirname == "":
#             self.dirname = os.path.curdir
# 
#         if mode is None:
#             raise ValueError("Please specify the mode.")
#         else:
#             self.mode = mode
# 
#         # create directory if not exist
#         if self.mode == 'w' or self.mode == 'a':
#             # create directory if not exist
#             if not os.path.exists(self.dirname):
#                 os.makedirs(self.dirname)
# 
#         # warn overwriting
#         if self.mode == 'w':
#             if os.path.exists(self.fpath):
#                 print("overwrite: " + self.fpath)
# 
#         # check file existing for reading
#         if self.mode == 'r':
#             if not os.path.exists(self.fpath):
#                 raise FileNotFoundError(
#                     "h5 file does not exist in " + self.fpath)
# 
#         # open hdf5 file to fpath
#         self.h5 = h5py.File(self.fpath, self.mode)
# 
#     def read(self, ext=None):
#         """Read vector or array from h5 file
# 
#         Parameters
#         ---------
#         ext : str
#             File extention including h5 file
# 
#         Returns
#         -------
#         array : array,
#             Array of hdf5 packed data
#         """
# 
#         if ext is None:
#             raise ValueError("Please specify an existing extention.")
# 
#         return self.h5[ext][()]
# 
#     def save(self, data, ext=None):
#         """Write vector or array into h5 file
# 
#         Parameters
#         ---------
#         data :
#             Vector or array will be wrote into h5 file
# 
#         ext: str
#             File label of saved file
# 
#         """
# 
#         # remove if 'ext' already exist
#         if ext in self.h5.keys():
#             del self.h5[ext]
# 
#         self.h5.create_dataset(ext, data=data)
#         self.h5.flush()
# 
#         return
# 
#     def close(self):
#         self.h5.close()
# 
#         return
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         self.close()


import os
import numpy as np
from scipy.signal import firwin, lfilter
from sprocket.util import HDF5, extfrm, static_delta
        for line in fp:
            f = line.rstrip()
            h5f = os.path.join(h5dir, f + '.h5')
            h5 = HDF5(h5f, mode='r')
            datalist.append(h5.read(ext))
            h5.close()

    return datalist


def extsddata(data, npow, power_threshold=-20):
    """Get power extract static and delta feature vector

    Paramters
    ---------
    data : array, shape (`T`, `dim`)
        Acoustic feature vector
    npow : array, shape (`T`)
        Normalized power vector
    power_threshold : float, optional,
        Power threshold
        Default set to -20

    Returns
    -------
    extsddata : array, shape (`T_new` `dim * 2`)
        Silence remove static and delta feature vector

    """


# Path: sprocket/util/extfrm.py
# def extfrm(data, npow, power_threshold=-20):
#     """Extract frame over the power threshold
# 
#     Parameters
#     ----------
#     data: array, shape (`T`, `dim`)
#         Array of input data
#     npow : array, shape (`T`)
#         Vector of normalized power sequence.
#     power_threshold : float, optional
#         Value of power threshold [dB]
#         Default set to -20
# 
#     Returns
#     -------
#     data: array, shape (`T_ext`, `dim`)
#         Remaining data after extracting frame
#         `T_ext` <= `T`
# 
#     """
# 
#     T = data.shape[0]
#     if T != len(npow):
#         raise("Length of two vectors is different.")
# 
#     valid_index = np.where(npow > power_threshold)
#     extdata = data[valid_index]
#     assert extdata.shape[0] <= T
# 
#     return extdata
# 
# Path: sprocket/util/delta.py
# def static_delta(data, win=[-1.0, 1.0, 0]):
#     """Calculate static and delta component
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of static matrix sequence.
#     win: array, optional, shape (`3`)
#         The shape of window matrix.
#         Default set to [-1.0, 1.0, 0].
# 
#     Returns
#     -------
#     sddata: array, shape (`T`, `dim*2`)
#         Array static and delta matrix sequence.
# 
#     """
# 
#     sddata = np.c_[data, delta(data, win)]
#     return sddata
# 
# Path: sprocket/util/hdf5.py
# class HDF5(object):
#     """HDF5 handler
#     Offer the hdf5 format file handler
# 
#     Parameters
#     ---------
#     fpath : str,
#         Path of hdf5 file
# 
#     mode : str,
#         Open h5 as write and/or read mode
#         `a` : open as read/write (Default)
#         `w` : open as write only
#         `r` : open as read only
# 
#     Attributes
#     ---------
#     h5 : hdf5 class
# 
#     """
# 
#     def __init__(self, fpath, mode='a'):
#         self.fpath = fpath
#         self.dirname, self.filename = os.path.split(self.fpath)
#         self.flbl, _ = os.path.splitext(self.filename)
# 
#         # os.path.split(path)[0] returns "" if path doesn't contain '/'
#         if self.filename != "" and self.dirname == "":
#             self.dirname = os.path.curdir
# 
#         if mode is None:
#             raise ValueError("Please specify the mode.")
#         else:
#             self.mode = mode
# 
#         # create directory if not exist
#         if self.mode == 'w' or self.mode == 'a':
#             # create directory if not exist
#             if not os.path.exists(self.dirname):
#                 os.makedirs(self.dirname)
# 
#         # warn overwriting
#         if self.mode == 'w':
#             if os.path.exists(self.fpath):
#                 print("overwrite: " + self.fpath)
# 
#         # check file existing for reading
#         if self.mode == 'r':
#             if not os.path.exists(self.fpath):
#                 raise FileNotFoundError(
#                     "h5 file does not exist in " + self.fpath)
# 
#         # open hdf5 file to fpath
#         self.h5 = h5py.File(self.fpath, self.mode)
# 
#     def read(self, ext=None):
#         """Read vector or array from h5 file
# 
#         Parameters
#         ---------
#         ext : str
#             File extention including h5 file
# 
#         Returns
#         -------
#         array : array,
#             Array of hdf5 packed data
#         """
# 
#         if ext is None:
#             raise ValueError("Please specify an existing extention.")
# 
#         return self.h5[ext][()]
# 
#     def save(self, data, ext=None):
#         """Write vector or array into h5 file
# 
#         Parameters
#         ---------
#         data :
#             Vector or array will be wrote into h5 file
# 
#         ext: str
#             File label of saved file
# 
#         """
# 
#         # remove if 'ext' already exist
#         if ext in self.h5.keys():
#             del self.h5[ext]
# 
#         self.h5.create_dataset(ext, data=data)
#         self.h5.flush()
# 
#         return
# 
#     def close(self):
#         self.h5.close()
# 
#         return
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         self.close()


# Path: example/src/misc.py
import os
import numpy as np
from scipy.signal import firwin, lfilter
from sprocket.util import HDF5, extfrm, static_delta

        for line in fp:
            f = line.rstrip()
            h5f = os.path.join(h5dir, f + '.h5')
            h5 = HDF5(h5f, mode='r')
            datalist.append(h5.read(ext))
            h5.close()

    return datalist


def extsddata(data, npow, power_threshold=-20):
    """Get power extract static and delta feature vector

    Paramters
    ---------
    data : array, shape (`T`, `dim`)
        Acoustic feature vector
    npow : array, shape (`T`)
        Normalized power vector
    power_threshold : float, optional,
        Power threshold
        Default set to -20

    Returns
    -------
    extsddata : array, shape (`T_new` `dim * 2`)
        Silence remove static and delta feature vector

    """


    extsddata = extfrm(static_delta(data), npow,