-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
83 lines (75 loc) · 3.32 KB
/
main.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
import components as C
import utils
if __name__ == "__main__":
st.title("Audio Checking Tool")
base_folder = st.text_input("specify directory which contains audio file")
path = utils.check_folder(base_folder)
if path is not None:
audio_files = sorted([
f.name
for f in (list(path.glob("*.wav")) + list(path.glob("*.mp3")))
])
audio_file_name = st.selectbox(
"Choose audio file", options=audio_files)
audio_path = path / audio_file_name
audio_info = utils.check_audio_info(audio_path)
C.write_audio_info_to_sidebar(audio_path, audio_info)
second = C.set_start_second(max_value=audio_info["duration"])
sr = C.set_sampling_rate(audio_info["sample_rate"])
options = st.sidebar.selectbox(
"Audio option",
options=["normal", "preprocessing", "augmentations"])
utils.display_media_audio(audio_path, second)
annotation = st.sidebar.file_uploader(
"Upload annotation file if exist")
if annotation is not None:
event_level_annotation = utils.read_csv(annotation)
else:
event_level_annotation = None
y = utils.read_audio(audio_path, audio_info, sr=sr)
if options == "preprocessing":
y_processed = C.preprocess_on_wave(
y, sr=sr, audio_path=str(audio_path))
if y_processed is not None:
st.text("Processed audio")
utils.display_media_audio_from_ndarray(y_processed, sr)
if event_level_annotation is None:
C.waveplot(y, sr, y_processed)
C.specshow(y, sr, y_processed)
else:
C.waveplot_with_annotation(y, sr, event_level_annotation,
audio_file_name, y_processed)
C.specshow_with_annotation(y, sr, event_level_annotation,
audio_file_name, y_processed)
elif options == "augmentations":
y_processed = C.augmentations_on_wave(
y, sr=sr)
if y_processed is not None:
st.text("Processed audio")
utils.display_media_audio_from_ndarray(y_processed, sr)
if event_level_annotation is None:
C.waveplot(y, sr, y_processed)
C.specshow(y, sr, y_processed)
else:
C.waveplot_with_annotation(y, sr, event_level_annotation,
audio_file_name, y_processed)
C.specshow_with_annotation(y, sr, event_level_annotation,
audio_file_name, y_processed)
else:
if event_level_annotation is None:
C.waveplot(y, sr)
C.specshow(y, sr)
else:
C.waveplot_with_annotation(
y,
sr,
event_level_annotation,
audio_file_name,
processed=None)
C.specshow_with_annotation(
y,
sr,
event_level_annotation,
audio_file_name,
y_processed=None)