Skip to content

Commit

Permalink
work in progress for #6, bleep instead of mute
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Aug 29, 2024
1 parent d02d3f9 commit 1cbee94
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ options:
Beep instead of silence
-h <int>, --beep-hertz <int>
Beep frequency hertz (default: 1000)
--beep-audio-weight <int>
Mix weight for non-beeped audio (default: 4)
--beep-sine-weight <int>
Mix weight for beep (default: 1)
--beep-dropout-transition <int>
Dropout transition for beep (default: 0)
--force [true|false] Process file despite existence of embedded tag
VOSK Options:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = monkeyplug
version = 2.1.0
version = 2.1.1
author = Seth Grover
author_email = mero.mero.guero@gmail.com
description = monkeyplug is a little script to censor profanity in audio files.
Expand Down
2 changes: 1 addition & 1 deletion src/monkeyplug/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""monkeyplug is a little script to censor profanity in audio files."""

__version__ = "2.1.0"
__version__ = "2.1.1"
__author__ = "Seth Grover <mero.mero.guero@gmail.com>"
__all__ = []

Expand Down
63 changes: 61 additions & 2 deletions src/monkeyplug/monkeyplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
AUDIO_INTERMEDIATE_PARAMS = ["-c:a", "pcm_s16le", "-ac", "1", "-ar", "16000"]
AUDIO_DEFAULT_WAV_FRAMES_CHUNK = 8000
BEEP_HERTZ_DEFAULT = 1000
BEEP_AUDIO_WEIGHT_DEFAULT = 4
BEEP_SINE_WEIGHT_DEFAULT = 1
BEEP_DROPOUT_TRANSITION_DEFAULT = 0
SWEARS_FILENAME_DEFAULT = 'swears.txt'
MUTAGEN_METADATA_TAGS = ['encodedby', 'comment']
MUTAGEN_METADATA_TAG_VALUE = u'monkeyplug'
Expand Down Expand Up @@ -211,6 +214,9 @@ class Plugger(object):
padSecPost = 0.0
beep = False
beepHertz = BEEP_HERTZ_DEFAULT
beepAudioWeight = BEEP_AUDIO_WEIGHT_DEFAULT
beepSineWeight = BEEP_SINE_WEIGHT_DEFAULT
beepDropTransition = BEEP_DROPOUT_TRANSITION_DEFAULT
forceDespiteTag = False
aParams = None
tags = None
Expand All @@ -229,13 +235,19 @@ def __init__(
padMsecPost=0,
beep=False,
beepHertz=BEEP_HERTZ_DEFAULT,
beepAudioWeight=BEEP_AUDIO_WEIGHT_DEFAULT,
beepSineWeight=BEEP_SINE_WEIGHT_DEFAULT,
beepDropTransition=BEEP_DROPOUT_TRANSITION_DEFAULT,
force=False,
dbug=False,
):
self.padSecPre = padMsecPre / 1000.0
self.padSecPost = padMsecPost / 1000.0
self.beep = beep
self.beepHertz = beepHertz
self.beepAudioWeight = beepAudioWeight
self.beepSineWeight = beepSineWeight
self.beepDropTransition = beepDropTransition
self.forceDespiteTag = force
self.debug = dbug
self.outputJson = outputJson
Expand Down Expand Up @@ -347,7 +359,11 @@ def __init__(
mmguero.eprint(f'Profanity file: {self.swearsFileSpec}')
mmguero.eprint(f'Intermediate downloaded file: {self.tmpDownloadedFileSpec}')
mmguero.eprint(f'Beep instead of mute: {self.beep}')
mmguero.eprint(f'Beep hertz: {self.beepHertz}')
if self.beep:
mmguero.eprint(f'Beep hertz: {self.beepHertz}')
mmguero.eprint(f'Beep audio weight: {self.beepAudioWeight}')
mmguero.eprint(f'Beep sine weight: {self.beepSineWeight}')
mmguero.eprint(f'Beep dropout transition: {self.beepDropTransition}')
mmguero.eprint(f'Force despite tags: {self.forceDespiteTag}')

######## del ##################################################################
Expand Down Expand Up @@ -420,7 +436,7 @@ def EncodeCleanAudio(self):
[f'[beep{i+1}]{val}[beep{i+1}_delayed]' for i, val in enumerate(self.beepDelayList)]
)
beepMixList = ''.join([f'[beep{i+1}_delayed]' for i in range(len(self.beepDelayList))])
filterStr = f"[0:a]{muteTimeListStr}[mute];{sineTimeListStr};{beepDelayList};[mute]{beepMixList}amix=inputs={len(self.beepDelayList)+1}"
filterStr = f"[0:a]{muteTimeListStr}[mute];{sineTimeListStr};{beepDelayList};[mute]{beepMixList}amix=inputs={len(self.beepDelayList)+1}:dropout_transition={self.beepDropTransition}:weights={self.beepAudioWeight} {' '.join([str(self.beepSineWeight)] * len(self.beepDelayList))}"
audioArgs = ['-filter_complex', filterStr]
else:
audioArgs = ['-af', ",".join(self.muteTimeList)]
Expand Down Expand Up @@ -506,6 +522,9 @@ def __init__(
padMsecPost=0,
beep=False,
beepHertz=BEEP_HERTZ_DEFAULT,
beepAudioWeight=BEEP_AUDIO_WEIGHT_DEFAULT,
beepSineWeight=BEEP_SINE_WEIGHT_DEFAULT,
beepDropTransition=BEEP_DROPOUT_TRANSITION_DEFAULT,
force=False,
dbug=False,
):
Expand Down Expand Up @@ -539,6 +558,9 @@ def __init__(
padMsecPost=padMsecPost,
beep=beep,
beepHertz=beepHertz,
beepAudioWeight=beepAudioWeight,
beepSineWeight=beepSineWeight,
beepDropTransition=beepDropTransition,
force=force,
dbug=dbug,
)
Expand Down Expand Up @@ -655,6 +677,9 @@ def __init__(
padMsecPost=0,
beep=False,
beepHertz=BEEP_HERTZ_DEFAULT,
beepAudioWeight=BEEP_AUDIO_WEIGHT_DEFAULT,
beepSineWeight=BEEP_SINE_WEIGHT_DEFAULT,
beepDropTransition=BEEP_DROPOUT_TRANSITION_DEFAULT,
force=False,
dbug=False,
):
Expand All @@ -678,6 +703,9 @@ def __init__(
padMsecPost=padMsecPost,
beep=beep,
beepHertz=beepHertz,
beepAudioWeight=beepAudioWeight,
beepSineWeight=beepSineWeight,
beepDropTransition=beepDropTransition,
force=force,
dbug=dbug,
)
Expand Down Expand Up @@ -848,6 +876,31 @@ def RunMonkeyPlug():
default=BEEP_HERTZ_DEFAULT,
help=f"Beep frequency hertz (default: {BEEP_HERTZ_DEFAULT})",
)
parser.add_argument(
"--beep-audio-weight",
dest="beepAudioWeight",
metavar="<int>",
type=int,
default=BEEP_AUDIO_WEIGHT_DEFAULT,
help=f"Mix weight for non-beeped audio (default: {BEEP_AUDIO_WEIGHT_DEFAULT})",
)
parser.add_argument(
"--beep-sine-weight",
dest="beepSineWeight",
metavar="<int>",
type=int,
default=BEEP_SINE_WEIGHT_DEFAULT,
help=f"Mix weight for beep (default: {BEEP_SINE_WEIGHT_DEFAULT})",
)
parser.add_argument(
"--beep-dropout-transition",
dest="beepDropTransition",
metavar="<int>",
type=int,
default=BEEP_DROPOUT_TRANSITION_DEFAULT,
help=f"Dropout transition for beep (default: {BEEP_DROPOUT_TRANSITION_DEFAULT})",
)

parser.add_argument(
"--force",
dest="forceDespiteTag",
Expand Down Expand Up @@ -926,6 +979,9 @@ def RunMonkeyPlug():
padMsecPost=args.padMsecPost if args.padMsecPost > 0 else args.padMsec,
beep=args.beep,
beepHertz=args.beepHertz,
beepAudioWeight=args.beepAudioWeight,
beepSineWeight=args.beepSineWeight,
beepDropTransition=args.beepDropTransition,
force=args.forceDespiteTag,
dbug=args.debug,
)
Expand All @@ -946,6 +1002,9 @@ def RunMonkeyPlug():
padMsecPost=args.padMsecPost if args.padMsecPost > 0 else args.padMsec,
beep=args.beep,
beepHertz=args.beepHertz,
beepAudioWeight=args.beepAudioWeight,
beepSineWeight=args.beepSineWeight,
beepDropTransition=args.beepDropTransition,
force=args.forceDespiteTag,
dbug=args.debug,
)
Expand Down

0 comments on commit 1cbee94

Please sign in to comment.