Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update split_silence.py #863

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/split_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def _logged_popen(cmd_line, *args, **kwargs):
return subprocess.Popen(cmd_line, *args, **kwargs)


def remove_non_ascii(raw_data):
# Keep only ASCII printable and common whitespace characters (tab, newline, carriage return)
return bytes(b for b in raw_data if 32 <= b <= 126 or b in {9, 10, 13})


def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time=None, end_time=None):
input_kwargs = {}
if start_time is not None:
Expand All @@ -56,7 +61,7 @@ def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time
) + ['-nostats'], # FIXME: use .nostats() once it's implemented in ffmpeg-python.
stderr=subprocess.PIPE
)
output = p.communicate()[1].decode('utf-8')
output = remove_non_ascii(p.communicate()[1]).decode('utf-8')
if p.returncode != 0:
sys.stderr.write(output)
sys.exit(1)
Expand Down