forked from ghodouss/CleanBeats.ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_explitives.py
More file actions
73 lines (46 loc) · 1.47 KB
/
remove_explitives.py
File metadata and controls
73 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pydub import AudioSegment
from canetis.align import align
def segs_to_gentle(segments):
"""
Converts output of align
to a standard gentle output
Parameters
-----------------------
list of Segment Object
Output
------------------
list of Gentle Word Objects
"""
gentle_output = []
for seg in segments:
gentle_output += seg.gentle
return gentle_output
def get_explitives(gentle_output):
explitives = ["shit", "fuck", "damn", "dick"]
explitive_times = []
for word in gentle_output:
for explitive in explitives:
if explitive in word.word and word.success():
explitive_time = {"word":word.word, "start":word.start, "end":word.end}
explitive_times.append(explitive_time)
print(explitive_times)
return explitive_times
def get_all_explitive_times(audio_file_path, text_file_path):
"""
Module that finds the timestamps
of every explitive in an audio file
Inputs
----------------------
String Path to .wav or .mp3 file
String Path to .txt transcript file
Outputs
--------------------
List of timestamp dicts
"""
# run forced alignment on file
segments = align(audio_file_path, text_file_path)
gentle_output = segs_to_gentle(segments)
# get list of explitive times
explitive_times = get_explitives(gentle_output)
#return explitive times
return explitive_times