Smile¶
- class opensmile.Smile(feature_set=FeatureSet.ComParE_2016, feature_level=FeatureLevel.Functionals, *, options=None, loglevel=2, logfile=None, sampling_rate=None, channels=0, mixdown=False, resample=False, segment=None, keep_nat=False, num_workers=1, multiprocessing=False, verbose=False)[source]¶
OpenSMILE feature extractor.
You can choose a pre-defined feature set by passing one of
opensmile.FeatureSet
You can also provide a custom config file using the following template:
[componentInstances:cComponentManager] instance[dataMemory].type=cDataMemory ;;; default source \{\cm[source{?}:source include config]} ;;; add components reading from reader.dmLevel=wave ;;; combine features [componentInstances:cComponentManager] instance[funcconcat].type=cVectorConcat [funcconcat:cVectorConcat] reader.dmLevel = <feat-1>;<feat-2>;... writer.dmLevel = features includeSingleElementFields = 1 ;;; default sink \{\cm[sink{?}:include external sink]}
Note
The following arguments are not serialized:
keep_nat
loglevel
logfile
num_workers
multiprocessing
segment
verbose
For more information see section on hidden arguments.
- Parameters
feature_set (
Union
[str
,FeatureSet
]) – default feature set or path to a custom config filefeature_level (
Union
[str
,FeatureLevel
]) – default feature level or level name if a custom config file is usedoptions (
Optional
[dict
]) – dictionary with optional script parametersloglevel (
int
) – log level (0-5), the higher the number the more log messages are givenlogfile (
Optional
[str
]) – if notNone
log messages will be stored to this filesampling_rate (
Optional
[int
]) – sampling rate in Hz. IfNone
it will callprocess_func
with the actual sampling rate of the signal.channels (
Union
[int
,Sequence
[int
]]) – channel selection, seeaudresample.remix()
mixdown (
bool
) – apply mono mix-down on selectionresample (
bool
) – ifTrue
enforces given sampling rate by resamplingsegment (
Optional
[Segment
]) – when aaudinterface.Segment
object is provided, it will be used to find a segmentation of the input signal. Afterwards processing is applied to each segmentkeep_nat (
bool
) – if the end of segment is set toNaT
do not replace with file duration in the resultnum_workers (
Optional
[int
]) – number of parallel jobs or 1 for sequential processing. IfNone
will be set to the number of processors on the machine multiplied by 5 in case of multithreading and number of processors in case of multiprocessingmultiprocessing (
bool
) – use multiprocessing instead of multithreadingverbose (
bool
) – show debug messages
Examples: >>> sampling_rate = 16000 >>> signal = np.zeros(sampling_rate) >>> smile = Smile( … feature_set=FeatureSet.ComParE_2016, … feature_level=FeatureLevel.Functionals, … ) >>> smile.process_signal(signal, sampling_rate).audspec_lengthL1norm_sma_range start end 0 days 0 days 00:00:01 0.0 Name: audspec_lengthL1norm_sma_range, dtype: float32
__call__()¶
- Smile.__call__(signal, sampling_rate)[source]¶
Apply processing to signal.
This function processes the signal without transforming the output into a
pd.DataFrame
. Instead it will return the raw processed signal. However, if channel selection, mixdown and/or resampling is enabled, the signal will be first remixed and resampled if the input sampling rate does not fit the expected sampling rate.- Parameters
- Return type
- Returns
Processed signal
- Raises
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
arguments¶
- Smile.arguments¶
Returns arguments that are serialized.
- Returns
Dictionary of arguments and their values.
- Raises
RuntimeError – if arguments are found that are not assigned to attributes of the same name
Examples
>>> import audobject.testing >>> o = audobject.testing.TestObject('test', point=(1, 1)) >>> o.arguments {'name': 'test', 'point': (1, 1)}
borrowed_arguments¶
- Smile.borrowed_arguments¶
Returns borrowed arguments.
- Returns
Dictionary with borrowed arguments.
hidden_arguments¶
Returns hidden arguments.
- Returns
List with names of hidden arguments.
id¶
- Smile.id¶
Object identifier.
The ID of an object ID is created from its non-hidden arguments.
- Returns
object identifier
Examples
>>> class Foo(Object): ... def __init__(self, bar: str): ... self.bar = bar >>> foo1 = Foo('I am unique!') >>> print(foo1.id) 893df240-babe-d796-cdf1-c436171b7a96 >>> foo2 = Foo('I am different!') >>> print(foo2.id) 9303f2a5-bfc9-e5ff-0ffa-a9846e2d2190 >>> foo3 = Foo('I am unique!') >>> print(foo1.id == foo3.id) True
is_loaded_from_dict¶
- Smile.is_loaded_from_dict¶
Check if object was loaded from a dictionary.
Returns
True
if object was initialized from a dictionary, e.g. after loading it from a YAML file.- Returns
True
if object was loaded from a dictionary,otherwise
False
process_file()¶
- Smile.process_file(file, *, start=None, end=None, root=None)¶
Extract features from an audio file.
- Parameters
file (
str
) – file pathstart (
Union
[float
,int
,str
,Timedelta
,None
]) – start processing at this position. If value is a float or integer it is treated as seconds. Seeaudinterface.utils.to_timedelta()
for further optionsend (
Union
[float
,int
,str
,Timedelta
,None
]) – end processing at this position. If value is a float or integer it is treated as seconds. Seeaudinterface.utils.to_timedelta()
for further optionsroot (
Optional
[str
]) – root folder to expand relative file path
- Raises
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
RuntimeError – if multiple frames are returned, but
win_dur
is not set
- Return type
process_files()¶
- Smile.process_files(files, *, starts=None, ends=None, root=None)¶
Extract features for a list of files.
- Parameters
starts (
Union
[float
,int
,str
,Timedelta
,Sequence
[Union
[float
,int
,str
,Timedelta
]],None
]) – segment start positions. Time values given as float or integers are treated as seconds. Seeaudinterface.utils.to_timedelta()
for further options. If a scalar is given, it is applied to all filesends (
Union
[float
,int
,str
,Timedelta
,Sequence
[Union
[float
,int
,str
,Timedelta
]],None
]) – segment end positions. Time values given as float or integers are treated as seconds. Seeaudinterface.utils.to_timedelta()
for further options. If a scalar is given, it is applied to all filesroot (
Optional
[str
]) – root folder to expand relative file paths
- Raises
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
RuntimeError – if multiple frames are returned, but
win_dur
is not set
- Return type
process_folder()¶
- Smile.process_folder(root, *, filetype='wav', include_root=True)¶
Extract features from files in a folder.
Note
At the moment does not scan in sub-folders!
- Parameters
- Raises
FileNotFoundError – if folder does not exist
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
RuntimeError – if multiple frames are returned, but
win_dur
is not set
- Return type
process_func_applies_sliding_window¶
- Smile.process_func_applies_sliding_window¶
Controls if processing function applies sliding window.
process_index()¶
- Smile.process_index(index, *, preserve_index=False, root=None, cache_root=None)¶
Extract features from an index conform to audformat.
If
cache_root
is notNone
, a hash value is created from the index usingaudformat.utils.hash()
and the result is stored as<cache_root>/<hash>.pkl
. When called again with the same index, features will be read from the cached file.- Parameters
index (
Index
) – index with segment informationpreserve_index (
bool
) – ifTrue
andaudinterface.Feature.process.segment
isNone
the returned index will be of same type as the original one, otherwise always a segmented index is returnedroot (
Optional
[str
]) – root folder to expand relative file paths
- Raises
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
RuntimeError – if multiple frames are returned, but
win_dur
is not setValueError – if index is not conform to audformat
- Return type
process_signal()¶
- Smile.process_signal(signal, sampling_rate, *, file=None, start=None, end=None)¶
Extract features for an audio signal.
Note
If a
file
is given, the index of the returned frame has levelsfile
,start
andend
. Otherwise, it consists only ofstart
andend
.- Parameters
signal (
ndarray
) – signal valuessampling_rate (
int
) – sampling rate in Hzstart (
Union
[float
,int
,str
,Timedelta
,None
]) – start processing at this position. If value is a float or integer it is treated as seconds. Seeaudinterface.utils.to_timedelta()
for further optionsend (
Union
[float
,int
,str
,Timedelta
,None
]) – end processing at this position. If value is a float or integer it is treated as seconds. Seeaudinterface.utils.to_timedelta()
for further options
- Raises
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
RuntimeError – if dimension of extracted features is greater than three
RuntimeError – if feature extractor uses sliding window, but
self.win_dur
is not specifiedRuntimeError – if number of features does not match number of feature names
RuntimeError – if multiple frames are returned, but
win_dur
is not set
- Return type
process_signal_from_index()¶
- Smile.process_signal_from_index(signal, sampling_rate, index)¶
Split a signal into segments and extract features for each segment.
- Parameters
signal (
ndarray
) – signal valuessampling_rate (
int
) – sampling rate in Hzindex (
MultiIndex
) – apandas.MultiIndex
with two levels named start and end that hold start and end positions aspandas.Timedelta
objects. See alsoaudinterface.utils.signal_index()
- Raises
RuntimeError – if sampling rates do not match
RuntimeError – if channel selection is invalid
RuntimeError – if multiple frames are returned, but
win_dur
is not setValueError – if index contains duplicates
- Return type
to_dict()¶
- Smile.to_dict(*, include_version=True, flatten=False, root=None)¶
Converts object to a dictionary.
Includes items from
audobject.Object.arguments
. If an argument has a resolver, its value is encoded. Usually, the object can be re-instantiated usingaudobject.Object.from_dict()
. However, ifflatten=True
, this is not possible.- Parameters
- Return type
Dict
[str
,Union
[bool
,datetime
,dict
,float
,int
,list
,None
,str
]]- Returns
dictionary that represent the object
Examples
>>> import audobject.testing >>> o = audobject.testing.TestObject('test', point=(1, 1)) >>> o.to_dict(include_version=False) {'$audobject.core.testing.TestObject': {'name': 'test', 'point': [1, 1]}} >>> o.to_dict(flatten=True) {'name': 'test', 'point.0': 1, 'point.1': 1}
to_numpy()¶
- Smile.to_numpy(frame)¶
Return feature values as a numpy array.
The returned
numpy.ndarray
has the original shape, i.e.(channels, features, time)
.