unsilence
Subpackages
Submodules
Package Contents
Classes
Unsilence Class to remove (or isolate or many other use cases) silence from audible video parts |
|
Represents a section in time where the media file is either silent or audible |
|
Collection of lib.Intervals.Interval |
- class unsilence.Unsilence(input_file: pathlib.Path, temp_dir: pathlib.Path = Path('.tmp'))
Unsilence Class to remove (or isolate or many other use cases) silence from audible video parts
- Parameters
input_file (Path) – The file that should be processed
temp_dir (Path) – The temp dir where temporary files can be saved
- detect_silence(**kwargs)
Detects silence of the file (Options can be specified in kwargs)
- Parameters
**kwargs – Remaining keyword arguments are passed to
detect_silence()
- Returns
A generated Intervals object
- Return type
- set_intervals(intervals: unsilence.lib.intervals.Intervals.Intervals)
Set the intervals so that they do not need to be re-detected
- Parameters
intervals (Intervals) – Intervals collection
- Returns
None
- get_intervals()
Get the current Intervals so they can be reused if wanted
- Returns
Intervals collection
- Return type
- estimate_time(audible_speed: float = 1, silent_speed: float = 6)
Estimates the time (savings) when the current options are applied to the intervals
- Parameters
audible_speed (float) – The speed at which the audible intervals get played back at
silent_speed (float) – The speed at which the silent intervals get played back at
- Raises
ValueError – If silence detection was never run
- Returns
Dictionary of time information
- Return type
dict
- render_media(output_file: pathlib.Path, **kwargs)
Renders the current intervals with options specified in the kwargs
- Parameters
output_file (Path) – Where the final file should be saved at
**kwargs – Remaining keyword arguments are passed to
render()
- Returns
None
- cleanup()
Cleans up the temporary directories, called automatically when the program ends
- Returns
None
- class unsilence.Interval(start=0, end=0, is_silent=False)
Represents a section in time where the media file is either silent or audible
Initializes an Interval object :param start: Start time of the interval in seconds :param end: End time of the interval in seconds :param is_silent: Whether the interval is silent or not
- property start
Get the start time :return: start time in seconds
- property end
Get the end time :return: end time in seconds
- property duration
Returns the duration of the interval :return: Duration of the interval
- enlarge_audible_interval(stretch_time, is_start_interval=False, is_end_interval=False)
Enlarges/Shrinks the audio interval, based on if it is silent or not :param stretch_time: Time the interval should be enlarged/shrunken :param is_start_interval: Whether the current interval is at the start (should not enlarge/shrink) :param is_end_interval: Whether the current interval is at the end (should not enlarge/shrink) :return: None
- copy()
Creates a deep copy of this Interval :return: Interval deepcopy
- serialize()
Serializes the current interval into a dict format :return: serialized dict
- static deserialize(serialized_obj: dict)
Deserializes a previously serializes Interval and generates a new Interval with this data :param serialized_obj: previously serializes Interval (type dict) :return: Interval
- __repr__()
String representation :return: String representation
- class unsilence.Intervals(interval_list: list = None)
Collection of lib.Intervals.Interval
Initializes a new Interval Collection :param interval_list: list of intervals, optional
- property intervals
Returns the list of intervals :return:
- add_interval(interval)
Adds an interval to the collection :param interval: interval to be added :return: None
- optimize(short_interval_threshold=0.3, stretch_time=0.25)
Optimizes the Intervals to be a better fit for media cutting :param short_interval_threshold: The shortest allowed interval length (in seconds) :param stretch_time: The time that should be added/removed from a audible/silent interval :return: None
- __combine_intervals(short_interval_threshold)
Combines multiple intervals in order to remove intervals smaller than a threshold :param short_interval_threshold: Threshold for the shortest allowed interval :return: None
- __enlarge_audible_intervals(stretch_time)
Enlarges/Shrinks intervals based on if they are silent or audible :param stretch_time: Time the intervals should be enlarged/shrunken :return: None
- remove_short_intervals_from_start(audible_speed=1, silent_speed=2)
Removes Intervals from start that are shorter than 0.5 seconds after speedup to avoid having a final output without an audio track :param audible_speed: The speed at which the audible intervals get played back at (float) :param silent_speed: The speed at which the silent intervals get played back at (float) :return: The new, possibly shorter, Intervals object
- copy()
Creates a deep copy :return: Deep copy of Intervals
- serialize()
Serializes this collection :return: Serialized list
- static deserialize(serialized_obj)
Deserializes a previously serialized object and creates a new Instance from it :param serialized_obj: Serialized list :return: New instance of Intervals
- __repr__()
String representation :return: String representation