philippemos commited on
Commit
6bfc1e0
โ€ข
1 Parent(s): 1435c61

change num_worker in nemo configs to enforce cpu usage

Browse files
Files changed (4) hide show
  1. .gitignore +10 -0
  2. app.py +45 -44
  3. diarizers/nemo_diarizer.py +4 -2
  4. 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
- def main():
123
- # 1) Write input text
124
- text_utils.intro_container()
125
- diarization_container = st.container()
126
-
127
- # 2)Create the diarization container
128
- diarization_container.markdown("---")
129
-
130
- # 2.1) Diarization method
131
- text_utils.demo_container(diarization_container)
132
- diarization_container.markdown("Choose the Diarization method here:")
133
-
134
- diarization_checkbox_dict = {}
135
- for diarization_method in configs.DIARIZATION_METHODS:
136
- diarization_checkbox_dict[diarization_method] = diarization_container.checkbox(
137
- diarization_method)
138
-
139
- # 2.2) Diarization upload/sample select
140
- diarization_container.markdown("(Optional) Upload an audio file here:")
141
- file_uploader = diarization_container.file_uploader(
142
- label="", type=[".wav", ".wave"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  )
144
 
145
- sample_option_dict = general_utils.get_dict_of_audio_samples(configs.AUDIO_SAMPLES_DIR)
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 = 1.5
74
- self.config.diarizer.speaker_embeddings.parameters.shift_length_in_sec = 0.75
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
- container = st.container()
14
- container.title(
15
  'Who spoke when: Choosing the right speaker diarization tool')
16
- container.markdown(
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
- container.markdown(
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
- container.markdown(
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
- container.markdown("---")
30
- container.header("๐Ÿ—ฃ๏ธ What is speaker diarization?๏ธ")
31
 
32
- container.markdown('\n')
33
- container.markdown(
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 = container.columns([2, 5, 2])
40
 
41
  with col1_im1:
42
  st.write(' ')
@@ -50,14 +49,14 @@ def intro_container():
50
  with col3_im1:
51
  st.write(' ')
52
 
53
- container.markdown(
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
- container.markdown('\n')
59
 
60
- col1, col2, col3 = container.columns(3)
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
- container.markdown(
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
- container.caption(
119
  "But what can I do with these speaker-aware transcripts? ๐Ÿค”")
120
- container.markdown(
121
  "Speaker-aware transcripts can be a powerful tool for analyzing speech data:")
122
- container.markdown("""
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
- container.markdown(
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
- container.markdown("---")
132
- container.header('๐Ÿ“ The workflow of a speaker diarization system')
133
- container.markdown(
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
- container.markdown(
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
- container.subheader('Traditional diarization systems')
143
- container.markdown(
144
  "Those consist of many independent submodules that are optimized individually, namely being:")
145
- container.markdown("""
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 = container.columns([2, 5, 2])
152
 
153
  with col1_im1:
154
  st.write(' ')
@@ -162,102 +161,102 @@ def intro_container():
162
  with col3_im1:
163
  st.write(' ')
164
 
165
- container.subheader('End-to-end diarization systems')
166
- container.markdown(
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
- container.markdown('**Advantages**')
170
- container.markdown(
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
- container.markdown(
173
  'โž• Less need to come up with useful pre-processing and post-processing transformation on the input data.')
174
- container.markdown(' **Disadvantages**')
175
- container.markdown(
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
- container.markdown('โž– These systems have the tendency to overfit on the training data.')
178
 
179
- container.markdown("---")
180
- container.header('๐Ÿ“š Speaker diarization frameworks')
181
- container.markdown(
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
- container.markdown(
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
- container.markdown("### 1. [pyannote](https://github.com/pyannote/pyannote-audio)")
191
- container.markdown(
192
  "Arguably one of the most popular libraries out there for speaker diarization.\n")
193
- container.markdown(
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
- container.markdown(
196
  "โž• Comes with a set of available pre-trained models for the VAD, embedder and segmentation model.\n")
197
- container.markdown(
198
  "โž• The inference pipeline can identify multiple speakers speaking at the same time (multi-label diarization).\n")
199
- container.markdown(
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
- container.markdown("### 2. [NVIDIA NeMo](https://developer.nvidia.com/nvidia-nemo)")
202
- container.markdown(
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
- container.markdown(
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
- container.markdown(
207
  "โž• Diarization results can be combined easily with ASR outputs to generate speaker-aware transcripts.\n")
208
- container.markdown(
209
  "โž• Possibility to define the number of speakers beforehand if they are known, resulting in a more accurate diarization output.\n")
210
- container.markdown(
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
- container.markdown("### 3. [Simple Diarizer](https://github.com/cvqluu/simple_diarizer)")
213
- container.markdown(
214
  "A simplified diarization pipeline that can be used for quick testing.\n")
215
- container.markdown(
216
  "๐Ÿ‘‰ Uses the same pre-trained models as pyannote.\n")
217
- container.markdown(
218
  "โž• Similarly to Nvidia NeMo, there's the option to define the number of speakers beforehand.\n")
219
- container.markdown(
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
- container.markdown(
222
  "### 4. [SpeechBrain](https://github.com/speechbrain/speechbrain)")
223
- container.markdown(
224
  "All-in-one conversational AI toolkit based on PyTorch.\n")
225
- container.markdown(
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
- container.markdown(
228
  "โž• Large amount of pre-trained models for various tasks. Checkout their [HuggingFace page](https://huggingface.co/speechbrain) for more information.\n")
229
- container.markdown(
230
  "โž• Contains [comprehensible tutorials](https://speechbrain.github.io/tutorial_basics.html) for various speech building blocks to easily get started.\n")
231
- container.markdown(
232
  "โž– Diarization pipeline is still not fully implemented yet but this [might change in the future](https://github.com/speechbrain/speechbrain/issues/1208).")
233
- container.markdown(
234
  "### 5. [Kaldi](https://github.com/kaldi-asr/kaldi)")
235
- container.markdown(
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
- container.markdown(
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
- container.markdown(
240
  "๐Ÿ‘‰ Benefits from large community support. However, mainly targeted towards researchers and less suitable for production ready-solutions.\n")
241
- container.markdown(
242
  "โž– Relatively steep learning curve for beginners who don't have a lot of experience with speech recognition systems.\n")
243
- container.markdown(
244
  "โž– Not suitable for a quick implementation of ASR/diarization systems. \n")
245
 
246
- container.markdown(
247
  "### 6. [UIS-RNN](https://github.com/google/uis-rnn)")
248
- container.markdown(
249
  "A fully supervised end-to-end diarization model developed by Google.\n")
250
- container.markdown(
251
  "๐Ÿ‘‰ Both training and prediction require the usage of a GPU.\n")
252
- container.markdown(
253
  "โž– No-pretrained model is available, so you need to train it from scratch on your custom transcribed data.\n")
254
- container.markdown(
255
  "โž• Relatively easy to train if you have a large set of pre-labeled data.\n")
256
- container.markdown("\n")
257
- container.markdown(
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 = container.columns([4, 5, 4])
261
 
262
  with col1_im2:
263
  st.write(' ')
@@ -271,17 +270,17 @@ def intro_container():
271
  st.write(' ')
272
 
273
 
274
- def demo_container(diarization_container):
275
- diarization_container.header('๐Ÿค– Demo')
276
- diarization_container.markdown(
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
- diarization_container.markdown(
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
- diarization_container.caption(
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
- container = st.container()
294
- container.title('๐Ÿ’ฌ Conclusions')
295
- container.markdown("In this blogpost we covered different aspects of speaker diarization.\n")
296
- container.markdown(
297
  "๐Ÿ‘‰ First we explained what speaker diarization is and gave a few examples of its different areas of applications.\n")
298
- container.markdown(
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
- container.markdown(
301
  "๐Ÿ‘‰ Then, we gave a comparison of different diarization frameworks and provided a guide for picking the best one for your use case.")
302
- container.markdown(
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.")