Spaces:
Build error
Build error
Commit
โข
6bfc1e0
1
Parent(s):
1435c61
change num_worker in nemo configs to enforce cpu usage
Browse files- .gitignore +10 -0
- app.py +45 -44
- diarizers/nemo_diarizer.py +4 -2
- utils/text_utils.py +85 -87
.gitignore
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
target/
|
2 |
+
dbt_modules/
|
3 |
+
dbt_packages/
|
4 |
+
logs/
|
5 |
+
.venv/
|
6 |
+
.vscode/
|
7 |
+
*.pyc
|
8 |
+
.idea/
|
9 |
+
.DS_Store
|
10 |
+
__pycache__/
|
app.py
CHANGED
@@ -119,49 +119,50 @@ def execute_diarization(file_uploader: st.uploaded_file_manager.UploadedFile, se
|
|
119 |
shutil.rmtree(user_folder)
|
120 |
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
)
|
144 |
|
145 |
-
|
146 |
-
diarization_container.markdown("Or select a sample file here:")
|
147 |
-
selected_option = diarization_container.selectbox(
|
148 |
-
label="", options=list(sample_option_dict.keys())
|
149 |
-
)
|
150 |
-
diarization_container.markdown("---")
|
151 |
-
|
152 |
-
## 2.3) Apply specified diarization pipeline
|
153 |
-
if diarization_container.button("Apply"):
|
154 |
-
session_id = streamlit_utils.get_session()
|
155 |
-
execute_diarization(
|
156 |
-
file_uploader=file_uploader,
|
157 |
-
selected_option=selected_option,
|
158 |
-
sample_option_dict=sample_option_dict,
|
159 |
-
diarization_checkbox_dict=diarization_checkbox_dict,
|
160 |
-
session_id=session_id
|
161 |
-
)
|
162 |
-
text_utils.conlusion_container()
|
163 |
-
|
164 |
-
|
165 |
-
if __name__ == "__main__":
|
166 |
-
st.set_page_config(layout="wide", page_title="Audio diarization visualization")
|
167 |
-
main()
|
|
|
119 |
shutil.rmtree(user_folder)
|
120 |
|
121 |
|
122 |
+
st.set_page_config(
|
123 |
+
page_title="๐ Audio diarization visualization ๐",
|
124 |
+
page_icon="",
|
125 |
+
layout="wide",
|
126 |
+
initial_sidebar_state="auto",
|
127 |
+
menu_items={
|
128 |
+
'Get help': None,
|
129 |
+
'Report a bug': None,
|
130 |
+
'About': None,
|
131 |
+
}
|
132 |
+
)
|
133 |
+
|
134 |
+
text_utils.intro_container()
|
135 |
+
# 2.1) Diarization method
|
136 |
+
text_utils.demo_container()
|
137 |
+
st.markdown("Choose the Diarization method here:")
|
138 |
+
|
139 |
+
diarization_checkbox_dict = {}
|
140 |
+
for diarization_method in configs.DIARIZATION_METHODS:
|
141 |
+
diarization_checkbox_dict[diarization_method] = st.checkbox(
|
142 |
+
diarization_method)
|
143 |
+
|
144 |
+
# 2.2) Diarization upload/sample select
|
145 |
+
st.markdown("(Optional) Upload an audio file here:")
|
146 |
+
file_uploader = st.file_uploader(
|
147 |
+
label="", type=[".wav", ".wave"]
|
148 |
+
)
|
149 |
+
|
150 |
+
sample_option_dict = general_utils.get_dict_of_audio_samples(configs.AUDIO_SAMPLES_DIR)
|
151 |
+
st.markdown("Or select a sample file here:")
|
152 |
+
selected_option = st.selectbox(
|
153 |
+
label="", options=list(sample_option_dict.keys())
|
154 |
+
)
|
155 |
+
st.markdown("---")
|
156 |
+
|
157 |
+
## 2.3) Apply specified diarization pipeline
|
158 |
+
if st.button("Apply"):
|
159 |
+
session_id = streamlit_utils.get_session()
|
160 |
+
execute_diarization(
|
161 |
+
file_uploader=file_uploader,
|
162 |
+
selected_option=selected_option,
|
163 |
+
sample_option_dict=sample_option_dict,
|
164 |
+
diarization_checkbox_dict=diarization_checkbox_dict,
|
165 |
+
session_id=session_id
|
166 |
)
|
167 |
|
168 |
+
text_utils.conlusion_container()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diarizers/nemo_diarizer.py
CHANGED
@@ -64,14 +64,16 @@ class NemoDiarizer(Diarizer):
|
|
64 |
|
65 |
pretrained_vad = 'vad_marblenet'
|
66 |
|
|
|
67 |
output_dir = os.path.join(self.data_dir, 'outputs')
|
|
|
68 |
self.config.diarizer.manifest_filepath = self.manifest_dir
|
69 |
self.config.diarizer.out_dir = output_dir
|
70 |
self.config.diarizer.ignore_overlap = False
|
71 |
|
72 |
self.config.diarizer.speaker_embeddings.model_path = pretrained_speaker_model
|
73 |
-
self.config.diarizer.speaker_embeddings.parameters.window_length_in_sec =
|
74 |
-
self.config.diarizer.speaker_embeddings.parameters.shift_length_in_sec = 0.
|
75 |
self.config.diarizer.oracle_vad = False
|
76 |
self.config.diarizer.clustering.parameters.oracle_num_speakers = False
|
77 |
|
|
|
64 |
|
65 |
pretrained_vad = 'vad_marblenet'
|
66 |
|
67 |
+
self.config.num_workers = 0
|
68 |
output_dir = os.path.join(self.data_dir, 'outputs')
|
69 |
+
|
70 |
self.config.diarizer.manifest_filepath = self.manifest_dir
|
71 |
self.config.diarizer.out_dir = output_dir
|
72 |
self.config.diarizer.ignore_overlap = False
|
73 |
|
74 |
self.config.diarizer.speaker_embeddings.model_path = pretrained_speaker_model
|
75 |
+
self.config.diarizer.speaker_embeddings.parameters.window_length_in_sec = 0.5
|
76 |
+
self.config.diarizer.speaker_embeddings.parameters.shift_length_in_sec = 0.25
|
77 |
self.config.diarizer.oracle_vad = False
|
78 |
self.config.diarizer.clustering.parameters.oracle_num_speakers = False
|
79 |
|
utils/text_utils.py
CHANGED
@@ -10,33 +10,32 @@ from utils import audio_utils
|
|
10 |
|
11 |
|
12 |
def intro_container():
|
13 |
-
|
14 |
-
container.title(
|
15 |
'Who spoke when: Choosing the right speaker diarization tool')
|
16 |
-
|
17 |
'With the increase in applications of automated ***speech recognition systems (ASR)***, '
|
18 |
'the ability to partition a speech audio stream with multiple speakers into individual'
|
19 |
' segments associated with each individual has become a crucial part of understanding '
|
20 |
'speech data.')
|
21 |
-
|
22 |
'In this blog post, we will take a look at different open source frameworks for '
|
23 |
'speaker diarization and provide you with a guide to pick the most suited '
|
24 |
'one for your use case.')
|
25 |
|
26 |
-
|
27 |
"Before we get into the technical details, libraries and tools, let's first understand what"
|
28 |
" speaker diarization is and how it works!")
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
'Speaker diarization aims to answer the question of ***"who spoke when"***. In short: diariziation algorithms '
|
35 |
'break down an audio stream of multiple speakers into segments corresponding to the individual speakers. '
|
36 |
'By combining the information that we get from diarization with ASR transcriptions, we can '
|
37 |
'transform the generated transcript into a format which is more readable and interpretable for humans '
|
38 |
'and that can be used for other downstream NLP tasks.')
|
39 |
-
col1_im1, col2_im1, col3_im1 =
|
40 |
|
41 |
with col1_im1:
|
42 |
st.write(' ')
|
@@ -50,14 +49,14 @@ def intro_container():
|
|
50 |
with col3_im1:
|
51 |
st.write(' ')
|
52 |
|
53 |
-
|
54 |
"Let's illustrate this with an example. We have a recording of a casual phone conversation "
|
55 |
"between two people. You can see what the different transcriptions look like when we "
|
56 |
"transcribe the conversation with and without diarization.")
|
57 |
|
58 |
-
|
59 |
|
60 |
-
col1, col2, col3 =
|
61 |
with col1:
|
62 |
st.subheader("๐ง Audio recording ")
|
63 |
st.markdown("<br></br>", unsafe_allow_html=True)
|
@@ -112,43 +111,43 @@ def intro_container():
|
|
112 |
"A: No.\n"
|
113 |
"B: oh.\n")
|
114 |
|
115 |
-
|
116 |
"By generating a **speaker-aware transcript**, we can more easily interpret the generated"
|
117 |
" conversation compared to a generated transcript without diarization. Much neater no? โจ")
|
118 |
-
|
119 |
"But what can I do with these speaker-aware transcripts? ๐ค")
|
120 |
-
|
121 |
"Speaker-aware transcripts can be a powerful tool for analyzing speech data:")
|
122 |
-
|
123 |
* We can use the transcripts to analyze individual speaker's sentiment by using **sentiment analysis** on both audio and text transcripts.
|
124 |
* Another use case is telemedicine where we might identify the **<doctor>** and **<patient>** tags on the transcription to create an accurate transcript and attach it to the patient file or EHR system.
|
125 |
* Speaker Diarization can be used by hiring platforms to analyze phone and video recruitment calls. This allows them to split and categorize candidates depending on their response to certain questions without having to listen again to the recordings.
|
126 |
""")
|
127 |
-
|
128 |
"Now that we've seen the importance of speaker diarization and some of its applications,"
|
129 |
" it's time to find out how we can implement diarization algorithms.")
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
"Building robust and accurate speaker diarization is not a trivial task."
|
135 |
" Real world audio data is messy and complex due to many factors, such"
|
136 |
" as having a noisy background, multiple speakers talking at the same time and "
|
137 |
"subtle differences between the speakers' voices in pitch and tone. Moreover, speaker diarization systems often suffer "
|
138 |
"from **domain mismatch** where a model on data from a specific domain works poorly when applied to another domain.")
|
139 |
|
140 |
-
|
141 |
"All in all, tackling speaker diarization is no easy feat. Current speaker diarization systems can be divided into two categories: **Traditional systems** and **End-to-End systems**. Let's look at how they work:")
|
142 |
-
|
143 |
-
|
144 |
"Those consist of many independent submodules that are optimized individually, namely being:")
|
145 |
-
|
146 |
* **Speech detection**: The first step is to identify speech and remove non-speech signals with a voice activity detector (VAD) algorithm.
|
147 |
* **Speech segmentation**: The output of the VAD is then segmented into small segments consisting of a few seconds (usually 1-2 seconds).
|
148 |
* **Speech embedder**: A neural network pre-trained on speaker recognition is used to derive a high-level representation of the speech segments. Those embeddings are vector representations that summarize the voice characteristics (a.k.a voice print).
|
149 |
* **Clustering**: After extracting segment embeddings, we need to cluster the speech embeddings with a clustering algorithm (for example K-Means or spectral clustering). The clustering produces our desired diarization results, which consists of identifying the number of unique speakers (derived from the number of unique clusters) and assigning a speaker label to each embedding (or speech segment).
|
150 |
""")
|
151 |
-
col1_im1, col2_im1, col3_im1 =
|
152 |
|
153 |
with col1_im1:
|
154 |
st.write(' ')
|
@@ -162,102 +161,102 @@ def intro_container():
|
|
162 |
with col3_im1:
|
163 |
st.write(' ')
|
164 |
|
165 |
-
|
166 |
-
|
167 |
"Here the individual submodules of the traditional speaker diarization system can be replaced by one neural network that is trained end-to-end on speaker diarization.")
|
168 |
|
169 |
-
|
170 |
-
|
171 |
'โ Direct optimization of the network towards maximizing the accuracy for the diarization task. This is in contrast with traditional systems where submodules are optimized individually but not as a whole.')
|
172 |
-
|
173 |
'โ Less need to come up with useful pre-processing and post-processing transformation on the input data.')
|
174 |
-
|
175 |
-
|
176 |
'โ More effort needed for data collection and labelling. This is because this type of approach requires speaker-aware transcripts for training. This differs from traditional systems where only labels consisting of the speaker tag along with the audio timestamp are needed (without transcription efforts).')
|
177 |
-
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
"As you can see, there are advantages and disadvantages to both traditional and end-to-end diarization systems."
|
183 |
"Building a speaker diarization system also involves aggregating quite a few "
|
184 |
"building blocks and the implementation can seem daunting at first glance. Luckily, there exists a plethora "
|
185 |
"of libraries and packages that have all those steps implemented and are ready for you to use out of the box ๐ฅ.")
|
186 |
-
|
187 |
"I will focus on the most popular **open-source** speaker diarization libraries. Make sure to check out"
|
188 |
" [this link](https://wq2012.github.io/awesome-diarization/) for a more exhaustive list on different diarization libraries.")
|
189 |
|
190 |
-
|
191 |
-
|
192 |
"Arguably one of the most popular libraries out there for speaker diarization.\n")
|
193 |
-
|
194 |
"๐ Note that the pre-trained models are based on the [VoxCeleb datasets](https://www.robots.ox.ac.uk/~vgg/data/voxceleb/) which consists of recording of celebrities extracted from YouTube. The audio quality of those recordings are crisp and clear, so you might need to retrain your model if you want to tackle other types of data like recorded phone calls.\n")
|
195 |
-
|
196 |
"โ Comes with a set of available pre-trained models for the VAD, embedder and segmentation model.\n")
|
197 |
-
|
198 |
"โ The inference pipeline can identify multiple speakers speaking at the same time (multi-label diarization).\n")
|
199 |
-
|
200 |
"โ It is not possible to define the number of speakers for the clustering algorithm. This could lead to an over-estimation or under-estimation of the number of speakers if they are known beforehand.")
|
201 |
-
|
202 |
-
|
203 |
"The Nvidia NeMo toolkit has separate collections for Automatic Speech Recognition (ASR), Natural Language Processing (NLP), and Text-to-Speech (TTS) models.\n")
|
204 |
-
|
205 |
"๐ The models that the pre-trained networks were trained on were trained on [VoxCeleb datasets](https://www.robots.ox.ac.uk/~vgg/data/voxceleb/) as well as the [Fisher](https://catalog.ldc.upenn.edu/LDC2004T19) and [SwitchBoard](https://catalog.ldc.upenn.edu/LDC97S62) dataset, which consists of telephone conversations in English. This makes it more suitable as a starting point for fine-tuning a model for call-center use cases compared to the pre-trained models used in pyannote. More information about the pre-trained models can be found [here](https://docs.nvidia.com/deeplearning/nemo/user-guide/docs/en/stable/asr/speaker_diarization/results.html).\n")
|
206 |
-
|
207 |
"โ Diarization results can be combined easily with ASR outputs to generate speaker-aware transcripts.\n")
|
208 |
-
|
209 |
"โ Possibility to define the number of speakers beforehand if they are known, resulting in a more accurate diarization output.\n")
|
210 |
-
|
211 |
"โ The fact that the NeMo toolkit also includes NLP related frameworks makes it easy to integrate the diarization outcome with downstream NLP tasks.\n")
|
212 |
-
|
213 |
-
|
214 |
"A simplified diarization pipeline that can be used for quick testing.\n")
|
215 |
-
|
216 |
"๐ Uses the same pre-trained models as pyannote.\n")
|
217 |
-
|
218 |
"โ Similarly to Nvidia NeMo, there's the option to define the number of speakers beforehand.\n")
|
219 |
-
|
220 |
"โ Unlike pyannote, this library does not include the option to fine tune the pre-trained models, making it less suitable for specialized use cases.\n")
|
221 |
-
|
222 |
"### 4. [SpeechBrain](https://github.com/speechbrain/speechbrain)")
|
223 |
-
|
224 |
"All-in-one conversational AI toolkit based on PyTorch.\n")
|
225 |
-
|
226 |
"โ The SpeechBrain Ecosystem makes it easy to develop integrated speech solutions with systems such ASR, speaker identification, speech enhancement, speech separation and language identification.\n")
|
227 |
-
|
228 |
"โ Large amount of pre-trained models for various tasks. Checkout their [HuggingFace page](https://huggingface.co/speechbrain) for more information.\n")
|
229 |
-
|
230 |
"โ Contains [comprehensible tutorials](https://speechbrain.github.io/tutorial_basics.html) for various speech building blocks to easily get started.\n")
|
231 |
-
|
232 |
"โ Diarization pipeline is still not fully implemented yet but this [might change in the future](https://github.com/speechbrain/speechbrain/issues/1208).")
|
233 |
-
|
234 |
"### 5. [Kaldi](https://github.com/kaldi-asr/kaldi)")
|
235 |
-
|
236 |
"Speech recognition toolkit that is mainly targeted towards researchers. It is written in C++ and used to train speech recognition models and decode audio from audio files.\n")
|
237 |
-
|
238 |
"๐ Pre-trained model is based on the [CALLHOME](https://catalog.ldc.upenn.edu/LDC97S42) dataset which consists of telephone conversation between native English speakers in North America.\n")
|
239 |
-
|
240 |
"๐ Benefits from large community support. However, mainly targeted towards researchers and less suitable for production ready-solutions.\n")
|
241 |
-
|
242 |
"โ Relatively steep learning curve for beginners who don't have a lot of experience with speech recognition systems.\n")
|
243 |
-
|
244 |
"โ Not suitable for a quick implementation of ASR/diarization systems. \n")
|
245 |
|
246 |
-
|
247 |
"### 6. [UIS-RNN](https://github.com/google/uis-rnn)")
|
248 |
-
|
249 |
"A fully supervised end-to-end diarization model developed by Google.\n")
|
250 |
-
|
251 |
"๐ Both training and prediction require the usage of a GPU.\n")
|
252 |
-
|
253 |
"โ No-pretrained model is available, so you need to train it from scratch on your custom transcribed data.\n")
|
254 |
-
|
255 |
"โ Relatively easy to train if you have a large set of pre-labeled data.\n")
|
256 |
-
|
257 |
-
|
258 |
"Phew ๐ฎโ๐จ, that's quite some different frameworks! To make it easier to pick the right one for your use case, I've created a simple flowchart that can get you started on picking a suitable library depending on your use case.")
|
259 |
|
260 |
-
col1_im2, col2_im2, col3_im2 =
|
261 |
|
262 |
with col1_im2:
|
263 |
st.write(' ')
|
@@ -271,17 +270,17 @@ def intro_container():
|
|
271 |
st.write(' ')
|
272 |
|
273 |
|
274 |
-
def demo_container(
|
275 |
-
|
276 |
-
|
277 |
"Alright, you're probably very curious at this point to test out a few diarization techniques "
|
278 |
"yourself. Below is a demo where you can try a few of the libraries that are mentioned above. "
|
279 |
"You can try running multiple frameworks at the same time and compare their results by ticking multiple "
|
280 |
"frameworks and clicking **'Apply'**.\n")
|
281 |
-
|
282 |
"**Note:** We are including **Nemo** and **pyannote** frameworks since we are operating on a single environment and a dependency conflict can occur when including other frameworks (most diarization frameworks rely "
|
283 |
"on different and incompatible versions of the same shared packages).")
|
284 |
-
|
285 |
"**Disclaimer**: Keep in mind that due to computational constraints, only the first 30 seconds will be used for diarization when uploading your own recordings. "
|
286 |
"For that reason, the diarization results may not be as accurate compared to diarization computed on longer recordings. This"
|
287 |
" is simply due to the fact that the diarization algorithms will have much less data to sample from in order to create meaningful clusters of embeddings for "
|
@@ -290,14 +289,13 @@ def demo_container(diarization_container):
|
|
290 |
|
291 |
|
292 |
def conlusion_container():
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
container.markdown(
|
297 |
"๐ First we explained what speaker diarization is and gave a few examples of its different areas of applications.\n")
|
298 |
-
|
299 |
"๐ We discussed the two main types of systems for implementing diarization system with a solid (high-level) understanding of both **traditional systems** and **end-to-end** systems.")
|
300 |
-
|
301 |
"๐ Then, we gave a comparison of different diarization frameworks and provided a guide for picking the best one for your use case.")
|
302 |
-
|
303 |
"๐ Finally, we provided you with an example to quickly try out a few of the diarization libraries.")
|
|
|
10 |
|
11 |
|
12 |
def intro_container():
|
13 |
+
st.title(
|
|
|
14 |
'Who spoke when: Choosing the right speaker diarization tool')
|
15 |
+
st.markdown(
|
16 |
'With the increase in applications of automated ***speech recognition systems (ASR)***, '
|
17 |
'the ability to partition a speech audio stream with multiple speakers into individual'
|
18 |
' segments associated with each individual has become a crucial part of understanding '
|
19 |
'speech data.')
|
20 |
+
st.markdown(
|
21 |
'In this blog post, we will take a look at different open source frameworks for '
|
22 |
'speaker diarization and provide you with a guide to pick the most suited '
|
23 |
'one for your use case.')
|
24 |
|
25 |
+
st.markdown(
|
26 |
"Before we get into the technical details, libraries and tools, let's first understand what"
|
27 |
" speaker diarization is and how it works!")
|
28 |
+
st.markdown("---")
|
29 |
+
st.header("๐ฃ๏ธ What is speaker diarization?๏ธ")
|
30 |
|
31 |
+
st.markdown('\n')
|
32 |
+
st.markdown(
|
33 |
'Speaker diarization aims to answer the question of ***"who spoke when"***. In short: diariziation algorithms '
|
34 |
'break down an audio stream of multiple speakers into segments corresponding to the individual speakers. '
|
35 |
'By combining the information that we get from diarization with ASR transcriptions, we can '
|
36 |
'transform the generated transcript into a format which is more readable and interpretable for humans '
|
37 |
'and that can be used for other downstream NLP tasks.')
|
38 |
+
col1_im1, col2_im1, col3_im1 = st.columns([2, 5, 2])
|
39 |
|
40 |
with col1_im1:
|
41 |
st.write(' ')
|
|
|
49 |
with col3_im1:
|
50 |
st.write(' ')
|
51 |
|
52 |
+
st.markdown(
|
53 |
"Let's illustrate this with an example. We have a recording of a casual phone conversation "
|
54 |
"between two people. You can see what the different transcriptions look like when we "
|
55 |
"transcribe the conversation with and without diarization.")
|
56 |
|
57 |
+
st.markdown('\n')
|
58 |
|
59 |
+
col1, col2, col3 = st.columns(3)
|
60 |
with col1:
|
61 |
st.subheader("๐ง Audio recording ")
|
62 |
st.markdown("<br></br>", unsafe_allow_html=True)
|
|
|
111 |
"A: No.\n"
|
112 |
"B: oh.\n")
|
113 |
|
114 |
+
st.markdown(
|
115 |
"By generating a **speaker-aware transcript**, we can more easily interpret the generated"
|
116 |
" conversation compared to a generated transcript without diarization. Much neater no? โจ")
|
117 |
+
st.caption(
|
118 |
"But what can I do with these speaker-aware transcripts? ๐ค")
|
119 |
+
st.markdown(
|
120 |
"Speaker-aware transcripts can be a powerful tool for analyzing speech data:")
|
121 |
+
st.markdown("""
|
122 |
* We can use the transcripts to analyze individual speaker's sentiment by using **sentiment analysis** on both audio and text transcripts.
|
123 |
* Another use case is telemedicine where we might identify the **<doctor>** and **<patient>** tags on the transcription to create an accurate transcript and attach it to the patient file or EHR system.
|
124 |
* Speaker Diarization can be used by hiring platforms to analyze phone and video recruitment calls. This allows them to split and categorize candidates depending on their response to certain questions without having to listen again to the recordings.
|
125 |
""")
|
126 |
+
st.markdown(
|
127 |
"Now that we've seen the importance of speaker diarization and some of its applications,"
|
128 |
" it's time to find out how we can implement diarization algorithms.")
|
129 |
|
130 |
+
st.markdown("---")
|
131 |
+
st.header('๐ The workflow of a speaker diarization system')
|
132 |
+
st.markdown(
|
133 |
"Building robust and accurate speaker diarization is not a trivial task."
|
134 |
" Real world audio data is messy and complex due to many factors, such"
|
135 |
" as having a noisy background, multiple speakers talking at the same time and "
|
136 |
"subtle differences between the speakers' voices in pitch and tone. Moreover, speaker diarization systems often suffer "
|
137 |
"from **domain mismatch** where a model on data from a specific domain works poorly when applied to another domain.")
|
138 |
|
139 |
+
st.markdown(
|
140 |
"All in all, tackling speaker diarization is no easy feat. Current speaker diarization systems can be divided into two categories: **Traditional systems** and **End-to-End systems**. Let's look at how they work:")
|
141 |
+
st.subheader('Traditional diarization systems')
|
142 |
+
st.markdown(
|
143 |
"Those consist of many independent submodules that are optimized individually, namely being:")
|
144 |
+
st.markdown("""
|
145 |
* **Speech detection**: The first step is to identify speech and remove non-speech signals with a voice activity detector (VAD) algorithm.
|
146 |
* **Speech segmentation**: The output of the VAD is then segmented into small segments consisting of a few seconds (usually 1-2 seconds).
|
147 |
* **Speech embedder**: A neural network pre-trained on speaker recognition is used to derive a high-level representation of the speech segments. Those embeddings are vector representations that summarize the voice characteristics (a.k.a voice print).
|
148 |
* **Clustering**: After extracting segment embeddings, we need to cluster the speech embeddings with a clustering algorithm (for example K-Means or spectral clustering). The clustering produces our desired diarization results, which consists of identifying the number of unique speakers (derived from the number of unique clusters) and assigning a speaker label to each embedding (or speech segment).
|
149 |
""")
|
150 |
+
col1_im1, col2_im1, col3_im1 = st.columns([2, 5, 2])
|
151 |
|
152 |
with col1_im1:
|
153 |
st.write(' ')
|
|
|
161 |
with col3_im1:
|
162 |
st.write(' ')
|
163 |
|
164 |
+
st.subheader('End-to-end diarization systems')
|
165 |
+
st.markdown(
|
166 |
"Here the individual submodules of the traditional speaker diarization system can be replaced by one neural network that is trained end-to-end on speaker diarization.")
|
167 |
|
168 |
+
st.markdown('**Advantages**')
|
169 |
+
st.markdown(
|
170 |
'โ Direct optimization of the network towards maximizing the accuracy for the diarization task. This is in contrast with traditional systems where submodules are optimized individually but not as a whole.')
|
171 |
+
st.markdown(
|
172 |
'โ Less need to come up with useful pre-processing and post-processing transformation on the input data.')
|
173 |
+
st.markdown(' **Disadvantages**')
|
174 |
+
st.markdown(
|
175 |
'โ More effort needed for data collection and labelling. This is because this type of approach requires speaker-aware transcripts for training. This differs from traditional systems where only labels consisting of the speaker tag along with the audio timestamp are needed (without transcription efforts).')
|
176 |
+
st.markdown('โ These systems have the tendency to overfit on the training data.')
|
177 |
|
178 |
+
st.markdown("---")
|
179 |
+
st.header('๐ Speaker diarization frameworks')
|
180 |
+
st.markdown(
|
181 |
"As you can see, there are advantages and disadvantages to both traditional and end-to-end diarization systems."
|
182 |
"Building a speaker diarization system also involves aggregating quite a few "
|
183 |
"building blocks and the implementation can seem daunting at first glance. Luckily, there exists a plethora "
|
184 |
"of libraries and packages that have all those steps implemented and are ready for you to use out of the box ๐ฅ.")
|
185 |
+
st.markdown(
|
186 |
"I will focus on the most popular **open-source** speaker diarization libraries. Make sure to check out"
|
187 |
" [this link](https://wq2012.github.io/awesome-diarization/) for a more exhaustive list on different diarization libraries.")
|
188 |
|
189 |
+
st.markdown("### 1. [pyannote](https://github.com/pyannote/pyannote-audio)")
|
190 |
+
st.markdown(
|
191 |
"Arguably one of the most popular libraries out there for speaker diarization.\n")
|
192 |
+
st.markdown(
|
193 |
"๐ Note that the pre-trained models are based on the [VoxCeleb datasets](https://www.robots.ox.ac.uk/~vgg/data/voxceleb/) which consists of recording of celebrities extracted from YouTube. The audio quality of those recordings are crisp and clear, so you might need to retrain your model if you want to tackle other types of data like recorded phone calls.\n")
|
194 |
+
st.markdown(
|
195 |
"โ Comes with a set of available pre-trained models for the VAD, embedder and segmentation model.\n")
|
196 |
+
st.markdown(
|
197 |
"โ The inference pipeline can identify multiple speakers speaking at the same time (multi-label diarization).\n")
|
198 |
+
st.markdown(
|
199 |
"โ It is not possible to define the number of speakers for the clustering algorithm. This could lead to an over-estimation or under-estimation of the number of speakers if they are known beforehand.")
|
200 |
+
st.markdown("### 2. [NVIDIA NeMo](https://developer.nvidia.com/nvidia-nemo)")
|
201 |
+
st.markdown(
|
202 |
"The Nvidia NeMo toolkit has separate collections for Automatic Speech Recognition (ASR), Natural Language Processing (NLP), and Text-to-Speech (TTS) models.\n")
|
203 |
+
st.markdown(
|
204 |
"๐ The models that the pre-trained networks were trained on were trained on [VoxCeleb datasets](https://www.robots.ox.ac.uk/~vgg/data/voxceleb/) as well as the [Fisher](https://catalog.ldc.upenn.edu/LDC2004T19) and [SwitchBoard](https://catalog.ldc.upenn.edu/LDC97S62) dataset, which consists of telephone conversations in English. This makes it more suitable as a starting point for fine-tuning a model for call-center use cases compared to the pre-trained models used in pyannote. More information about the pre-trained models can be found [here](https://docs.nvidia.com/deeplearning/nemo/user-guide/docs/en/stable/asr/speaker_diarization/results.html).\n")
|
205 |
+
st.markdown(
|
206 |
"โ Diarization results can be combined easily with ASR outputs to generate speaker-aware transcripts.\n")
|
207 |
+
st.markdown(
|
208 |
"โ Possibility to define the number of speakers beforehand if they are known, resulting in a more accurate diarization output.\n")
|
209 |
+
st.markdown(
|
210 |
"โ The fact that the NeMo toolkit also includes NLP related frameworks makes it easy to integrate the diarization outcome with downstream NLP tasks.\n")
|
211 |
+
st.markdown("### 3. [Simple Diarizer](https://github.com/cvqluu/simple_diarizer)")
|
212 |
+
st.markdown(
|
213 |
"A simplified diarization pipeline that can be used for quick testing.\n")
|
214 |
+
st.markdown(
|
215 |
"๐ Uses the same pre-trained models as pyannote.\n")
|
216 |
+
st.markdown(
|
217 |
"โ Similarly to Nvidia NeMo, there's the option to define the number of speakers beforehand.\n")
|
218 |
+
st.markdown(
|
219 |
"โ Unlike pyannote, this library does not include the option to fine tune the pre-trained models, making it less suitable for specialized use cases.\n")
|
220 |
+
st.markdown(
|
221 |
"### 4. [SpeechBrain](https://github.com/speechbrain/speechbrain)")
|
222 |
+
st.markdown(
|
223 |
"All-in-one conversational AI toolkit based on PyTorch.\n")
|
224 |
+
st.markdown(
|
225 |
"โ The SpeechBrain Ecosystem makes it easy to develop integrated speech solutions with systems such ASR, speaker identification, speech enhancement, speech separation and language identification.\n")
|
226 |
+
st.markdown(
|
227 |
"โ Large amount of pre-trained models for various tasks. Checkout their [HuggingFace page](https://huggingface.co/speechbrain) for more information.\n")
|
228 |
+
st.markdown(
|
229 |
"โ Contains [comprehensible tutorials](https://speechbrain.github.io/tutorial_basics.html) for various speech building blocks to easily get started.\n")
|
230 |
+
st.markdown(
|
231 |
"โ Diarization pipeline is still not fully implemented yet but this [might change in the future](https://github.com/speechbrain/speechbrain/issues/1208).")
|
232 |
+
st.markdown(
|
233 |
"### 5. [Kaldi](https://github.com/kaldi-asr/kaldi)")
|
234 |
+
st.markdown(
|
235 |
"Speech recognition toolkit that is mainly targeted towards researchers. It is written in C++ and used to train speech recognition models and decode audio from audio files.\n")
|
236 |
+
st.markdown(
|
237 |
"๐ Pre-trained model is based on the [CALLHOME](https://catalog.ldc.upenn.edu/LDC97S42) dataset which consists of telephone conversation between native English speakers in North America.\n")
|
238 |
+
st.markdown(
|
239 |
"๐ Benefits from large community support. However, mainly targeted towards researchers and less suitable for production ready-solutions.\n")
|
240 |
+
st.markdown(
|
241 |
"โ Relatively steep learning curve for beginners who don't have a lot of experience with speech recognition systems.\n")
|
242 |
+
st.markdown(
|
243 |
"โ Not suitable for a quick implementation of ASR/diarization systems. \n")
|
244 |
|
245 |
+
st.markdown(
|
246 |
"### 6. [UIS-RNN](https://github.com/google/uis-rnn)")
|
247 |
+
st.markdown(
|
248 |
"A fully supervised end-to-end diarization model developed by Google.\n")
|
249 |
+
st.markdown(
|
250 |
"๐ Both training and prediction require the usage of a GPU.\n")
|
251 |
+
st.markdown(
|
252 |
"โ No-pretrained model is available, so you need to train it from scratch on your custom transcribed data.\n")
|
253 |
+
st.markdown(
|
254 |
"โ Relatively easy to train if you have a large set of pre-labeled data.\n")
|
255 |
+
st.markdown("\n")
|
256 |
+
st.markdown(
|
257 |
"Phew ๐ฎโ๐จ, that's quite some different frameworks! To make it easier to pick the right one for your use case, I've created a simple flowchart that can get you started on picking a suitable library depending on your use case.")
|
258 |
|
259 |
+
col1_im2, col2_im2, col3_im2 = st.columns([4, 5, 4])
|
260 |
|
261 |
with col1_im2:
|
262 |
st.write(' ')
|
|
|
270 |
st.write(' ')
|
271 |
|
272 |
|
273 |
+
def demo_container():
|
274 |
+
st.header('๐ค Demo')
|
275 |
+
st.markdown(
|
276 |
"Alright, you're probably very curious at this point to test out a few diarization techniques "
|
277 |
"yourself. Below is a demo where you can try a few of the libraries that are mentioned above. "
|
278 |
"You can try running multiple frameworks at the same time and compare their results by ticking multiple "
|
279 |
"frameworks and clicking **'Apply'**.\n")
|
280 |
+
st.markdown(
|
281 |
"**Note:** We are including **Nemo** and **pyannote** frameworks since we are operating on a single environment and a dependency conflict can occur when including other frameworks (most diarization frameworks rely "
|
282 |
"on different and incompatible versions of the same shared packages).")
|
283 |
+
st.caption(
|
284 |
"**Disclaimer**: Keep in mind that due to computational constraints, only the first 30 seconds will be used for diarization when uploading your own recordings. "
|
285 |
"For that reason, the diarization results may not be as accurate compared to diarization computed on longer recordings. This"
|
286 |
" is simply due to the fact that the diarization algorithms will have much less data to sample from in order to create meaningful clusters of embeddings for "
|
|
|
289 |
|
290 |
|
291 |
def conlusion_container():
|
292 |
+
st.title('๐ฌ Conclusions')
|
293 |
+
st.markdown("In this blogpost we covered different aspects of speaker diarization.\n")
|
294 |
+
st.markdown(
|
|
|
295 |
"๐ First we explained what speaker diarization is and gave a few examples of its different areas of applications.\n")
|
296 |
+
st.markdown(
|
297 |
"๐ We discussed the two main types of systems for implementing diarization system with a solid (high-level) understanding of both **traditional systems** and **end-to-end** systems.")
|
298 |
+
st.markdown(
|
299 |
"๐ Then, we gave a comparison of different diarization frameworks and provided a guide for picking the best one for your use case.")
|
300 |
+
st.markdown(
|
301 |
"๐ Finally, we provided you with an example to quickly try out a few of the diarization libraries.")
|