-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_processing.py
41 lines (30 loc) · 1002 Bytes
/
post_processing.py
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
"""
post_processing.py
cleans up audio files, trims length and saves to disk
"""
from pydub.silence import split_on_silence
def audio_post_processing(sound):
"""cleans up the audio file
Args:
sound (AudioSegment): an audio clip of a spoken word
"""
sound = split_on_silence(
sound,
silence_thresh=-40,
keep_silence=False,
min_silence_len=50
)
return sound
def audio_to_file_segment(sound, start=0, end=None, filename=None):
"""splits an audio clip into a segment of audio
Args:
sound (AudioSegment): an audio clip of a spoken word
start (int): the start time of the segment
end (int): the end time of the segment
filename (str): the name of the file to save the segment to
"""
if end is None:
end = len(sound)
if filename is None:
filename = "./temp.wav"
sound[start * 1000:end * 1000].export(filename, format=filename.split(".")[-1])