Skip to content

Commit 318f391

Browse files
committed
Improved slug creation
1 parent 41be9e1 commit 318f391

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

manim_voiceover/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def chunks(lst: list, n: int):
1717
yield lst[i : i + n]
1818

1919

20-
def remove_bookmarks(str):
21-
return re.sub("<bookmark\s*mark\s*=['\"]\w*[\"']\s*/>", "", str)
20+
def remove_bookmarks(input: str) -> str:
21+
return re.sub("<bookmark\s*mark\s*=['\"]\w*[\"']\s*/>", "", input)
2222

2323

2424
def wav2mp3(wav_path, mp3_path=None, remove_wav=True, bitrate="312k"):

manim_voiceover/services/base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
DEFAULT_VOICEOVER_CACHE_DIR,
1212
DEFAULT_VOICEOVER_CACHE_JSON_FILENAME,
1313
)
14-
from manim_voiceover.helper import append_to_json_file, prompt_ask_missing_extras
14+
from manim_voiceover.helper import (
15+
append_to_json_file,
16+
prompt_ask_missing_extras,
17+
remove_bookmarks,
18+
)
1519
from manim_voiceover.modify_audio import adjust_speed
1620
from manim_voiceover.tracker import AUDIO_OFFSET_RESOLUTION
1721

@@ -157,8 +161,9 @@ def get_audio_basename(self, data: dict) -> str:
157161
dumped_data = json.dumps(data)
158162
data_hash = hashlib.sha256(dumped_data.encode("utf-8")).hexdigest()
159163
suffix = data_hash[:8]
160-
input_string = data["input_text"]
161-
slug = slugify(input_string)
164+
input_text = data["input_text"]
165+
input_text = remove_bookmarks(input_text)
166+
slug = slugify(input_text, max_length=50, word_boundary=True, save_order=True)
162167
ret = f"{slug}-{suffix}"
163168
return ret
164169

manim_voiceover/services/recorder/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def __init__(
4747
trim_buffer_start (int, optional): Buffer duration for trimming silence at the start. Defaults to 200 ms.
4848
trim_buffer_end (int, optional): Buffer duration for trimming silence at the end. Defaults to 200 ms.
4949
"""
50-
prompt_ask_missing_extras(
51-
["pyaudio", "pynput"], "recorder", "RecorderService"
52-
)
50+
prompt_ask_missing_extras(["pyaudio", "pynput"], "recorder", "RecorderService")
5351

5452
self.recorder = Recorder(
5553
format=format,

manim_voiceover/tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _process_bookmarks(self) -> None:
8787
)
8888
self.bookmark_times[mark] = self.start_t + elapsed
8989

90-
def get_remaining_duration(self, buff: float = 0.) -> float:
90+
def get_remaining_duration(self, buff: float = 0.0) -> float:
9191
"""Returns the remaining duration of the voiceover.
9292
9393
Args:

manim_voiceover/translate/render.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959

6060
def main():
61-
6261
args = parser.parse_args()
6362
file = args.file
6463
domain = args.domain

manim_voiceover/voiceover_scene.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from manim import Scene, config
99
from manim_voiceover.services.base import SpeechService
1010
from manim_voiceover.tracker import VoiceoverTracker
11-
from manim_voiceover.helper import chunks
11+
from manim_voiceover.helper import chunks, remove_bookmarks
1212

1313

1414
# SCRIPT_FILE_PATH = "media/script.txt"
@@ -72,8 +72,7 @@ def add_voiceover_text(
7272

7373
if self.create_subcaption:
7474
if subcaption is None:
75-
# Remove placeholders
76-
subcaption = re.sub(r"<[^<>]+/>", "", text)
75+
subcaption = remove_bookmarks(text)
7776

7877
self.add_wrapped_subcaption(
7978
subcaption,

0 commit comments

Comments
 (0)