Multi align examples
This page illustrates usage of the multi_align
command for forced alignment. For the full set of options execute:
multi_align --help
The examples on this page use audio that contains the utterance 'The north wind and the sun', either as a single channel or a stereo recording in which the first two words are in the first channel and the remaining words are in the second channel.
Default behavior of multi_align
The only required argument of multi_align
is the name of a .wav
file to be aligned. By default the transcript of the audio is expected to be provided by the labels of a textgrid with the same basename as the .wav
file and with the extension .Textgrid
. The screenshot shows audio and associated textgrid.
If the audio in the screenshot is saved as nws_mono.wav
and the textgrid as nws_mono.TextGrid
, then the following command performs alignment:
multi_align nws_mono.wav
The resulting textgrid contains three tiers, named 'phone', 'word', and 'trs'. The first contains the phone alignments, the second contains the word alignments, and the last contains the original transcript labels.
The output filename uses the same name as the inputs, with the extension .multi_align.TextGrid
.
Specifying a non-default input transcript
The input transcript does not have to have the same basename as the .wav
file. Use the --input
parameter to specify the name of the input transcript. The basename of --input
is used to form the output filename:
multi_align --input nws_mono.v2.TextGrid nws_mono.wav # output file is nws_mono.v2.multi_align.TextGrid
Simple alignment of a single utterance
If the audio file contains a single utterance, you might prefer to skip creating a textgrid file and provide the transcript in a simple text file or on the command line. For example, if you have a simple text file named nws_mono.txt
:
The north wind and the sun.
Then you can align by specifying that the --input-type
is a text file:
multi_align --input-type text nws_mono.wav
By default multi_align
looks for a .txt
file that matches the .wav
name when --input text
is used. You can of course override this default with the --input
parameter.
A second way to do simple alignment is to include the transcript on the command line. To do this, specify that the --input-type
is raw
. When raw
is used, then the --input
parameter should contain the transcript rather than a filename:
multi_align --input-type raw --input 'The north wind and the sun' nws_mono.wav
Aligning multiple speakers
If your transcript contains utterances from multiple speakers, use a separate textgrid tier for each speaker, as in the screenshot:
The tiers are named 'spkr1' and 'spkr2'. If this textgrid is named nws_mono.TextGrid
, then we align with:
multi_align nws_mono.wav
multi_align
aligns each tier separately, and the output contains two sets of 'phone', 'word', and 'trs' tiers, each set prefixed with the original tier name and an underscore, e.g. 'spkr1_phone' (notice that Praat interprets '_p' as a subscript character).
Aligning multiple speakers in multiple channels
If you are fortunate your recording was made with a dedicated microphone focused on each speaker. For example, you might have two speakers in a stereo recording in which one speaker appears in the left channel and one in the right. The screenshot shows such a recording with each speaker annotated on a separate tier.
Use the --tiers
option to provide a comma-separated (no spaces!) list of tier names to align. For this example, also suffix each tier name with :N
, where N
is the number of the audio channel to align (numbering starts with '1'):
multi_align --tiers spk1:1,spk2:2 nws_stereo.wav # input transcript in nws_stereo.TextGrid
The output file nws_stereo.multi_align.TextGrid
contains the result:
Handling errors
There are many reasons why alignment of one or more of your textgrids might fail: noisy audio, mistranscription, missing words in the dictionary, unrecognized sequence of phones, etc. When an error occurs the error message returned from pyalign
is stored in the 'phone' and 'word' tiers.
As an example, if the rough transcript is poorly synchronized with the audio:
then the poorly synchronized portion will not align and an error will appear:
The error message reads:
**ERROR** Command '['pyalign', '-s', '1.1477972199646949', '-e', '1.2788045196338285', '-c', '1', 'nws_mono.wav', 'temp_transcript.txt', 'temp_textgrid.TextGrid']' returned non-zero exit status 1