IBM / build-custom-stt-model-with-diarization

Build custom Speech to Text model with speaker diarization capabilities
Apache License 2.0
7 stars 7 forks source link
cloud-object-storage data-and-ai ibm-cloud ibm-code-pattern series watson-speech-to-text

Build custom Speech to Text model with speaker diarization capabilities

This Code Pattern is part of the series [Extracting Textual Insights from Videos with IBM Watson](). Please complete the Extract audio from video code pattern of the series before continuing further since both the code patterns are linked.

One of the features of Watson Speech to Text is the capability to detect different speakers from the audio also known as speaker diarization. In this code pattern, we will showcase the speaker diarization capabilities of Watson Speech to Text by training a custom language model with a corpus text file which will train the model with ‘Out of Vocabulary’ words and a custom acoustic model with the audio files (extracted in the previous code pattern of the series) which will train the model with ‘Accent’ detection, in a python flask runtime.

In this code pattern, given a corpus file and audio recordings of a meeting or classroom, we train custom language and acoustic speech to text model to transcribe audios to get speaker diarized output.

Speaker Diarization is a process of extracting multiple speakers information from an audio. Learn more

Custom language model is built to recognize the out of vocabulary words from the audio. Learn more

Custom accoustic model is built to recognize the accent of the speaker from the audio. Learn more

When you have completed this code pattern, you will understand how to:

architecture

Flow

  1. User uploads corpus file to the application

  2. The extracted audio from the previous code pattern of the series is retrived from Cloud Object Storage

  3. The corpus file as well as the extracted audio are uploaded to Watson Speech To Text to train the custom model

  4. The Downloaded audio file from the previous code pattern of the series is transcribed with the custom Speech To Text model and the text file is stored in Cloud Object Storage

Watch the Video

video

Pre-requisites

  1. IBM Cloud Account

  2. Docker

  3. Python

Steps

  1. Clone the repo

  2. Create Watson Speech To Text Service

  3. Add the Credentials to the Application

  4. Deploy the Application

  5. Run the Application

1. Clone the repo

Clone the build-custom-stt-model-with-diarization repo locally. In a terminal, run:

$ git clone https://github.com/IBM/build-custom-stt-model-with-diarization

We will be using the following datasets from the Cloud Object Storage:

  1. earnings-call-train-data.flac - To train the speech to text model.

  2. earnings-call-test-data.flac - To test the speech to text model.

  3. earnings-call-Q-and-A.flac - To demonstrate the diarization capabilities.

About the dataset

For the code pattern demonstration, we have considered IBM Earnings Call Q1 2019 Webex recording. The data has 40min of IBM Revenue discussion, and 20+ min of Q & A at the end of the recording. We have split the data into 3 parts:

2. Create Watson Speech To Text Service

NOTE: A Standard account is required to train a custom Speech To Text Model. There are three types of plans, Lite (FREE), Standard and Premium (PAID) for more info visit https://cloud.ibm.com/catalog/services/speech-to-text

Speech-to-text-service

3. Add the Credentials to the Application

4. Deploy the Application

With Docker Installed - Build the **Dockerfile** as follows : ```bash $ docker image build -t stt-with-diarization . ``` - once the dockerfile is built run the dockerfile as follows : ```bash $ docker run -p 8080:8080 stt-with-diarization ``` - The Application will be available on
Without Docker - Install the python libraries as follows: - change directory to repo parent folder ```bash $ cd build-custom-stt-model-with-diarization/ ``` - use `python pip` to install the libraries ```bash $ pip install -r requirements.txt ``` - Finally run the application as follows: ```bash $ python app.py ``` - The Application will be available on

5. Run the Application

sample_output

We can Train the custom Speech To Text model in just 4 steps:

  1. Delete the audio files earnings-call-test-data.mp4 & earnings-call-Q-and-A.mp4 as shown.

After clicking on delete file, it will take some time. Check logs on terminal, if required.

We delete the earnings-call-test-data.mp4 & earnings-call-Q-and-A.mp4 audio files since we do not require these files for training the Speech To text Model.

NOTE: Make sure you have downloaded the earnings-call-test-data.flac & earnings-call-Q-and-A.flac audio files in the previous code pattern of the series. If you have not downloaded then kindly download the files before proceeding as the files will be used in later part of the code pattern.

step1

  1. Click on the Drag and drop files here or click here to upload, choose the earnings-call-corpus-file.txt corpus file from data directory in the repo parent folder and click on Upload as shown.

Corpus file is used to train the language model with out of vocabulary words. In this code pattern we train the model with 7 out of vocabulary words like Kubernetes, Data and AI, RedHat, etc.

step2

  1. It will take about 1-2 min to upload the earnings-call-train-data.flac audio file and earnings-call-corpus-file.txt corpus file. The corpus file and audio files are now being uploaded to the Speech-To-Text service. Once it is uploaded successfully click on Refresh as shown.

step3

Audio file is used to train the acoustic model which understands the accent of the speaker.

  1. The status of language model and acoustic model will be ready at this point, indicating that the model contains data and is ready to be trained. Click on both the Train Model buttons to train the language model and acoustic model as shown.

It will take about 5 min to train both the models.
Please be patient.

step4

stepx

Transcribe audio to get Diarized textual output as follows:

NOTE: It will take about 1-2 Min to transcribe the earnings-call-Q-and-A.flac audio file.
Please be patient.

The data that we have provided to train the model is just 24:40 Minutes and hence the Transcription and Diarization may not be 100% accurate. Provided more training data, the accuracy will increase.

After clicking on Save Text to Cloud Object Storage, it will take some time. Check logs on terminal, if required. Once it is saved to your Cloud Object Storage you will get a notification as shown.

NOTE: The application will always consider the last uploaded file.

NOTE: It will take about 15-20 Min to transcribe the earnings-call-test-data.flac audio file.
Please be patient.

Summary

We have seen how to build a custom speech to text model to transcribe audio and get diarized textual output. In the next code pattern of the series we will learn how extract meaningful insights from the transcribed text files.

License

This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.

Apache License FAQ