Skip to content

Commit

Permalink
replace volume on/off with short afade in/out
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Aug 27, 2023
1 parent 14948ae commit bb53e1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
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 = 1.3.2
version = 1.4.0
author = Seth Grover
author_email = [email protected]
description = monkeyplug is a little script to mute 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 mute profanity in audio files."""

__version__ = "1.3.2"
__version__ = "1.4.0"
__author__ = "Seth Grover <[email protected]>"
__all__ = []

Expand Down
49 changes: 41 additions & 8 deletions src/monkeyplug/monkeyplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
script_path = os.path.dirname(os.path.realpath(__file__))


# thanks https://docs.python.org/3/library/itertools.html#recipes
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return zip(a, b)


###################################################################################################
# download to file
def DownloadToFile(url, local_filename=None, chunk_bytes=4096, debug=False):
Expand Down Expand Up @@ -419,17 +426,43 @@ def CreateCleanMuteList(self):
self.RecognizeSpeech()

self.naughtyWordList = [word for word in self.wordList if word["scrub"] is True]
if len(self.naughtyWordList) > 0:
# append a dummy word at the very end so that pairwise can peek then ignore it
self.naughtyWordList.extend(
[
{
"conf": 1,
"end": self.naughtyWordList[-1]["end"] + 2.0,
"start": self.naughtyWordList[-1]["end"] + 1.0,
"word": "mothaflippin",
"scrub": True,
}
]
)
if self.debug:
mmguero.eprint(self.naughtyWordList)

self.muteTimeList = [
"volume=enable='between(t,"
+ format(word["start"] - self.padSecPre, ".3f")
+ ","
+ format(word["end"] + self.padSecPost, ".3f")
+ ")':volume=0"
for word in self.naughtyWordList
]
self.muteTimeList = []
for word, wordPeek in pairwise(self.naughtyWordList):
self.muteTimeList.append(
"afade=enable='between(t,"
+ format(word["start"] - self.padSecPre, ".3f")
+ ","
+ format(word["end"] + self.padSecPost, ".3f")
+ ")':t=out:st="
+ format(word["start"] - self.padSecPre, ".3f")
+ ":d=5ms"
)
self.muteTimeList.append(
"afade=enable='between(t,"
+ format(word["end"] + self.padSecPost, ".3f")
+ ","
+ format(wordPeek["start"] - self.padSecPre, ".3f")
+ ")':t=in:st="
+ format(word["end"] + self.padSecPost, ".3f")
+ ":d=5ms"
)

if self.debug:
mmguero.eprint(self.muteTimeList)

Expand Down

0 comments on commit bb53e1f

Please sign in to comment.