<figure><img src="image_1.png" /></figure>

HAL
open science

SPPAS - the automatic annotation and analysis of
speech (version 4.7)

Brigitte Bigi

► To cite this version:

Brigitte Bigi. SPPAS - the automatic annotation and analysis of speech (version 4.7). 2022. hal-01414600v8

HAL Id: hal-01414600

https://hal.science/hal-01414600v8

Preprint submitted on 21 Nov 2022

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

Public Domain
<figure><img src="image_2.png" /></figure>

SPPAS

the automatic annotation
and analysis of speech

<figure><img src="image_3.png" /></figure>

Brigitte Bigi

contact@sppas.org

Copyright © 2011-2022 – Brigitte Bigi
Laboratoire Parole et Langage – France

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".

Any and all constructive comments are welcome.
# Contents

<table><tr><td>1</td><td>Introduction</td><td>1</td></tr><tr><td>1.1</td><td>About this documentation</td><td>1</td></tr><tr><td>1.2</td><td>What is SPPAS?</td><td>1</td></tr><tr><td>1.2.1</td><td>Overview</td><td>1</td></tr><tr><td>1.2.2</td><td>User engagement</td><td>2</td></tr><tr><td>1.2.3</td><td>Need help</td><td>2</td></tr><tr><td>1.2.4</td><td>About the author</td><td>2</td></tr><tr><td>1.2.5</td><td>Licenses</td><td>3</td></tr><tr><td>1.2.6</td><td>Supports</td><td>3</td></tr><tr><td>1.3</td><td>Getting and installing</td><td>4</td></tr><tr><td>1.3.1</td><td>Websites</td><td>4</td></tr><tr><td>1.3.2</td><td>Download and install SPPAS</td><td>5</td></tr><tr><td>1.3.3</td><td>The package</td><td>5</td></tr><tr><td>1.3.4</td><td>Update</td><td>6</td></tr><tr><td>1.4</td><td>Features</td><td>6</td></tr><tr><td>1.4.1</td><td>How to use SPPAS?</td><td>6</td></tr><tr><td>1.4.2</td><td>What SPPAS can do?</td><td>7</td></tr><tr><td>1.5</td><td>Main and important recommendations</td><td>7</td></tr><tr><td>1.5.1</td><td>About files</td><td>7</td></tr><tr><td>1.5.2</td><td>About automatic annotations</td><td>7</td></tr><tr><td>1.5.3</td><td>About linguistic resources</td><td>7</td></tr><tr><td>2</td><td>User interfaces</td><td>9</td></tr><tr><td>2.1</td><td>Introduction</td><td>9</td></tr><tr><td>2.2</td><td>Workspaces</td><td>9</td></tr><tr><td>2.2.1</td><td>Overview</td><td>9</td></tr><tr><td>2.2.2</td><td>Create and save a workspace</td><td>9</td></tr></table>
<table>
  <tbody>
    <tr>
      <td>2.2.3 Files</td>
      <td>9</td>
    </tr>
    <tr>
      <td>2.2.4 References</td>
      <td>11</td>
    </tr>
    <tr>
      <td>2.2.5 Associate files and references</td>
      <td>11</td>
    </tr>
    <tr>
      <td>2.3 The Command-Line user Interface - CLI</td>
      <td>11</td>
    </tr>
    <tr>
      <td>2.3.1 Overview</td>
      <td>11</td>
    </tr>
    <tr>
      <td>2.3.2 Usage</td>
      <td>12</td>
    </tr>
    <tr>
      <td>2.3.3 Arguments for input/output</td>
      <td>12</td>
    </tr>
    <tr>
      <td>2.3.4 preinstall.py</td>
      <td>13</td>
    </tr>
    <tr>
      <td>2.4 The graphical user interface</td>
      <td>13</td>
    </tr>
    <tr>
      <td>2.4.1 Important</td>
      <td>13</td>
    </tr>
    <tr>
      <td>2.4.2 Launch the GUI</td>
      <td>13</td>
    </tr>
    <tr>
      <td>2.4.3 The GUI of SPPAS</td>
      <td>14</td>
    </tr>
    <tr>
      <td>2.4.4 The main frame</td>
      <td>14</td>
    </tr>
    <tr>
      <td><b>3 Automatic Annotations</b></td>
      <td><b>19</b></td>
    </tr>
    <tr>
      <td>3.1 Introduction</td>
      <td>19</td>
    </tr>
    <tr>
      <td>3.1.1 About this chapter</td>
      <td>19</td>
    </tr>
    <tr>
      <td>3.1.2 THE recommended corpus construction workflow</td>
      <td>19</td>
    </tr>
    <tr>
      <td>3.1.3 Recordings</td>
      <td>20</td>
    </tr>
    <tr>
      <td>3.1.4 File formats and tier names</td>
      <td>21</td>
    </tr>
    <tr>
      <td>3.2 Resources required to annotate</td>
      <td>21</td>
    </tr>
    <tr>
      <td>3.2.1 Download and install linguistic resources</td>
      <td>22</td>
    </tr>
    <tr>
      <td>3.2.2 New language support</td>
      <td>22</td>
    </tr>
    <tr>
      <td>3.3 Annotate with the GUI</td>
      <td>22</td>
    </tr>
    <tr>
      <td>3.4 Annotate with the CLI</td>
      <td>23</td>
    </tr>
    <tr>
      <td>3.5 The procedure outcome report</td>
      <td>24</td>
    </tr>
    <tr>
      <td>3.6 Orthographic Transcription</td>
      <td>26</td>
    </tr>
    <tr>
      <td>3.7 Search for Inter-Pausal Units (IPUs)</td>
      <td>27</td>
    </tr>
    <tr>
      <td>3.7.1 Overview</td>
      <td>27</td>
    </tr>
    <tr>
      <td>3.7.2 The parameters</td>
      <td>27</td>
    </tr>
    <tr>
      <td>3.7.3 Perform "Search for IPUs" with the GUI</td>
      <td>28</td>
    </tr>
    <tr>
      <td>3.7.4 Perform "Search for IPUs" with the CLI</td>
      <td>28</td>
    </tr>
    <tr>
      <td>3.8 Fill in Inter-Pausal Units (IPUs)</td>
      <td>30</td>
    </tr>
    <tr>
      <td>3.8.1 Overview</td>
      <td>30</td>
    </tr>
    <tr>
      <td>3.8.2 How does it work</td>
      <td>30</td>
    </tr>
  </tbody>
</table>
<table><tr><td>3.8.3</td><td>Perform "Fill in IPUs" with the GUI</td><td>31</td></tr><tr><td>3.8.4</td><td>Perform "Fill in IPUs" with the CLI</td><td>31</td></tr><tr><td>3.9</td><td>Text normalization</td><td>32</td></tr><tr><td>3.9.1</td><td>Overview</td><td>32</td></tr><tr><td>3.9.2</td><td>Adapt Text normalization</td><td>32</td></tr><tr><td>3.9.3</td><td>Support of a new language</td><td>32</td></tr><tr><td>3.9.4</td><td>Perform Text Normalization with the GUI</td><td>33</td></tr><tr><td>3.9.5</td><td>Perform Text Normalization with the CLI</td><td>33</td></tr><tr><td>3.10</td><td>Phonetization</td><td>35</td></tr><tr><td>3.10.1</td><td>Overview</td><td>35</td></tr><tr><td>3.10.2</td><td>Adapt Phonetization</td><td>36</td></tr><tr><td>3.10.3</td><td>Support of a new language</td><td>36</td></tr><tr><td>3.10.4</td><td>Perform Phonetization with the GUI</td><td>36</td></tr><tr><td>3.10.5</td><td>Perform Phonetization with the CLI</td><td>37</td></tr><tr><td>3.11</td><td>Alignment</td><td>38</td></tr><tr><td>3.11.1</td><td>Overview</td><td>39</td></tr><tr><td>3.11.2</td><td>Adapt Alignment</td><td>39</td></tr><tr><td>3.11.3</td><td>Support of a new language</td><td>39</td></tr><tr><td>3.11.4</td><td>Perform Alignment with the GUI</td><td>40</td></tr><tr><td>3.11.5</td><td>Perform Alignment with the CLI</td><td>40</td></tr><tr><td>3.12</td><td>Activity</td><td>42</td></tr><tr><td>3.12.1</td><td>Overview</td><td>42</td></tr><tr><td>3.12.2</td><td>Perform Activity with the GUI</td><td>42</td></tr><tr><td>3.12.3</td><td>Perform Alignment with the CLI</td><td>42</td></tr><tr><td>3.13</td><td>RMS</td><td>42</td></tr><tr><td>3.13.1</td><td>Overview</td><td>42</td></tr><tr><td>3.13.2</td><td>Perform RMS with the GUI</td><td>43</td></tr><tr><td>3.13.3</td><td>Perform RMS with the CLI</td><td>43</td></tr><tr><td>3.14</td><td>Interval Values Analysis - IVA</td><td>43</td></tr><tr><td>3.14.1</td><td>Overview</td><td>43</td></tr><tr><td>3.14.2</td><td>Perform IVA with the GUI</td><td>43</td></tr><tr><td>3.14.3</td><td>Perform IVA with the CLI</td><td>44</td></tr><tr><td>3.15</td><td>Lexical Metric</td><td>44</td></tr><tr><td>3.15.1</td><td>Overview</td><td>44</td></tr><tr><td>3.15.2</td><td>Perform Lexical Metric with the GUI</td><td>44</td></tr></table>
<table><tr><td>3.16</td><td>Syllabification</td><td>44</td></tr><tr><td>3.16.1</td><td>Overview</td><td>44</td></tr><tr><td>3.16.2</td><td>Adapt Syllabification</td><td>45</td></tr><tr><td>3.16.3</td><td>Support of a new language</td><td>45</td></tr><tr><td>3.16.4</td><td>Perform Syllabification with the GUI</td><td>46</td></tr><tr><td>3.16.5</td><td>Perform Syllabification with the CLI</td><td>46</td></tr><tr><td>3.17</td><td>TGA - Time Groups Analyzer</td><td>47</td></tr><tr><td>3.17.1</td><td>Overview</td><td>47</td></tr><tr><td>3.17.2</td><td>Result of TGA into SPPAS</td><td>48</td></tr><tr><td>3.17.3</td><td>Perform TAG with the GUI</td><td>49</td></tr><tr><td>3.17.4</td><td>Perform TGA with the CLI</td><td>49</td></tr><tr><td>3.18</td><td>Stop words</td><td>50</td></tr><tr><td>3.19</td><td>Self-Repetitions</td><td>50</td></tr><tr><td>3.19.1</td><td>Overview</td><td>50</td></tr><tr><td>3.19.2</td><td>Adapt to a new language</td><td>51</td></tr><tr><td>3.19.3</td><td>Perform Self-Repetitions with the GUI</td><td>51</td></tr><tr><td>3.19.4</td><td>Perform SelfRepetitions with the CLI</td><td>51</td></tr><tr><td>3.20</td><td>Other-Repetitions</td><td>52</td></tr><tr><td>3.20.1</td><td>Overview</td><td>52</td></tr><tr><td>3.20.2</td><td>Adapt to a language and support of a new one</td><td>52</td></tr><tr><td>3.20.3</td><td>Perform Other-Repetitions with the GUI</td><td>53</td></tr><tr><td>3.20.4</td><td>Perform Other-Repetitions with the CLI</td><td>53</td></tr><tr><td>3.21</td><td>Re-Occurrences</td><td>53</td></tr><tr><td>3.21.1</td><td>Perform Re-Occurrences with the GUI</td><td>54</td></tr><tr><td>3.21.2</td><td>Perform Re-Occurrences with the CLI</td><td>54</td></tr><tr><td>3.22</td><td>Momel (modelling melody)</td><td>54</td></tr><tr><td>3.22.1</td><td>Perform Momel with the GUI</td><td>55</td></tr><tr><td>3.22.2</td><td>Perform Momel with the CLI</td><td>55</td></tr><tr><td>3.23</td><td>INTSINT: Encoding of F0 anchor points</td><td>57</td></tr><tr><td>3.23.1</td><td>Perform INTSINT with the GUI</td><td>57</td></tr><tr><td>3.23.2</td><td>Perform INTSINT with the CLI</td><td>57</td></tr><tr><td>3.24</td><td>Hand&Pose</td><td>59</td></tr><tr><td>3.24.1</td><td>Overview</td><td>59</td></tr><tr><td>3.24.2</td><td>Perform annotation with the GUI</td><td>60</td></tr><tr><td>3.24.3</td><td>Perform with the CLI</td><td>60</td></tr></table>
<table><tr><td>3.25 Face Detection</td><td>61</td></tr><tr><td>3.25.1 Overview</td><td>61</td></tr><tr><td>3.25.2 Result of Face Detection</td><td>61</td></tr><tr><td>3.25.3 Perform Face Detection with the GUI</td><td>62</td></tr><tr><td>3.25.4 Perform Face Detection with the CLI</td><td>62</td></tr><tr><td>3.26 Face Identity</td><td>64</td></tr><tr><td>3.26.1 Overview</td><td>64</td></tr><tr><td>3.26.2 Perform annotation with the GUI</td><td>64</td></tr><tr><td>3.26.3 Perform with the CLI</td><td>64</td></tr><tr><td>3.27 Face Landmarks</td><td>65</td></tr><tr><td>3.27.1 Overview</td><td>65</td></tr><tr><td>3.27.2 Perform annotation with the GUI</td><td>65</td></tr><tr><td>3.27.3 Perform with the CLI</td><td>65</td></tr><tr><td>3.28 Cued speech - LfPC</td><td>66</td></tr><tr><td>3.28.1 Overview</td><td>66</td></tr><tr><td>3.28.2 Perform annotation with the GUI</td><td>66</td></tr><tr><td>3.28.3 Perform with the CLI</td><td>66</td></tr><tr><td>4 Convert files</td><td>69</td></tr><tr><td>4.1 Interoperability and compatibility: an introduction</td><td>69</td></tr><tr><td>4.2 SPPAS conversion method</td><td>69</td></tr><tr><td>4.3 Supported file formats</td><td>70</td></tr><tr><td>4.4 Convert with the UI of SPPAS</td><td>70</td></tr><tr><td>5 Data Analyses</td><td>71</td></tr><tr><td>5.1 Introduction</td><td>71</td></tr><tr><td>5.2 The page Analyze of the GUI</td><td>71</td></tr><tr><td>5.2.1 Displayed files content</td><td>71</td></tr><tr><td>5.2.2 The toolbar</td><td>72</td></tr><tr><td>6 Scripting with Python and SPPAS</td><td>77</td></tr><tr><td>6.1 Introduction</td><td>77</td></tr><tr><td>6.2 A gentle introduction to programming</td><td>77</td></tr><tr><td>6.2.1 Introduction</td><td>78</td></tr><tr><td>6.2.2 Variables: Assignment and Typing</td><td>78</td></tr><tr><td>6.2.3 Basic Operators</td><td>79</td></tr></table>
<table>
  <tbody>
    <tr>
      <td>6.2.4</td>
      <td>Data types</td>
      <td>79</td>
    </tr>
    <tr>
      <td>6.2.5</td>
      <td>Conditions</td>
      <td>80</td>
    </tr>
    <tr>
      <td>6.2.6</td>
      <td>Loops</td>
      <td>81</td>
    </tr>
    <tr>
      <td>6.2.7</td>
      <td>Dictionaries</td>
      <td>82</td>
    </tr>
    <tr>
      <td>6.3</td>
      <td>Scripting with Python</td>
      <td>82</td>
    </tr>
    <tr>
      <td>6.3.1</td>
      <td>Comments and documentation</td>
      <td>83</td>
    </tr>
    <tr>
      <td>6.3.2</td>
      <td>Getting started with scripting in Python</td>
      <td>83</td>
    </tr>
    <tr>
      <td>6.3.3</td>
      <td>Blocks</td>
      <td>83</td>
    </tr>
    <tr>
      <td>6.3.4</td>
      <td>Functions</td>
      <td>84</td>
    </tr>
    <tr>
      <td>6.3.5</td>
      <td>Reading/Writing files</td>
      <td>85</td>
    </tr>
    <tr>
      <td>6.3.6</td>
      <td>Python tutorials</td>
      <td>87</td>
    </tr>
    <tr>
      <td>6.3.7</td>
      <td>Exercises to practice</td>
      <td>87</td>
    </tr>
    <tr>
      <td>6.4</td>
      <td>anndata, an API to manage annotated data</td>
      <td>87</td>
    </tr>
    <tr>
      <td>6.4.1</td>
      <td>Overview</td>
      <td>87</td>
    </tr>
    <tr>
      <td>6.4.2</td>
      <td>Why developing a new API?</td>
      <td>87</td>
    </tr>
    <tr>
      <td>6.4.3</td>
      <td>The "anndata" API class diagram</td>
      <td>88</td>
    </tr>
    <tr>
      <td>6.5</td>
      <td>Creating scripts with anndata</td>
      <td>89</td>
    </tr>
    <tr>
      <td>6.5.1</td>
      <td>Preparing the data</td>
      <td>89</td>
    </tr>
    <tr>
      <td>6.5.2</td>
      <td>Read/Write annotated files</td>
      <td>89</td>
    </tr>
    <tr>
      <td>6.5.3</td>
      <td>Manipulating a sppasTranscription object</td>
      <td>90</td>
    </tr>
    <tr>
      <td>6.5.4</td>
      <td>Manipulating a sppasTier object</td>
      <td>90</td>
    </tr>
    <tr>
      <td>6.5.5</td>
      <td>Manipulating a sppasAnnotation object</td>
      <td>91</td>
    </tr>
    <tr>
      <td>6.5.6</td>
      <td>Search in annotations: Filters</td>
      <td>91</td>
    </tr>
    <tr>
      <td>6.6</td>
      <td>More with SPPAS...</td>
      <td>94</td>
    </tr>
    <tr>
      <td>7</td>
      <td>References</td>
      <td>97</td>
    </tr>
    <tr>
      <td>7.1</td>
      <td>References</td>
      <td>97</td>
    </tr>
    <tr>
      <td>7.1.1</td>
      <td>How to cite SPPAS?</td>
      <td>97</td>
    </tr>
    <tr>
      <td>7.1.2</td>
      <td>SPPAS software description</td>
      <td>97</td>
    </tr>
    <tr>
      <td>7.1.3</td>
      <td>About linguistic resources</td>
      <td>98</td>
    </tr>
    <tr>
      <td>7.1.4</td>
      <td>About Search for IPUs</td>
      <td>98</td>
    </tr>
    <tr>
      <td>7.1.5</td>
      <td>About Text Normalization</td>
      <td>98</td>
    </tr>
    <tr>
      <td>7.1.6</td>
      <td>About Phonetization</td>
      <td>98</td>
    </tr>
    <tr>
      <td>7.1.7</td>
      <td>About Forced-Alignment</td>
      <td>99</td>
    </tr>
    <tr>
      <td>7.1.8</td>
      <td>About Syllabification</td>
      <td>99</td>
    </tr>
  </tbody>
</table>
<table><tr><td>7.1.9</td><td>About Repetitions</td><td>100</td></tr><tr><td>7.1.10</td><td>About analyses tools</td><td>100</td></tr><tr><td>7.1.11</td><td>About the API</td><td>100</td></tr><tr><td>7.1.12</td><td>Related references</td><td>100</td></tr><tr><td><b>8</b></td><td><b>SPPAS Release notes</b></td><td><b>103</b></td></tr><tr><td>8.1</td><td>The early versions</td><td>103</td></tr><tr><td>8.1.1</td><td>Version 1.0</td><td>103</td></tr><tr><td>8.1.2</td><td>Version 1.1</td><td>103</td></tr><tr><td>8.1.3</td><td>Version 1.2</td><td>103</td></tr><tr><td>8.1.4</td><td>Version 1.3</td><td>103</td></tr><tr><td>8.2</td><td>The birth of SPPAS</td><td>104</td></tr><tr><td>8.2.1</td><td>SPPAS 1.4.0</td><td>104</td></tr><tr><td>8.2.2</td><td>SPPAS 1.4.1</td><td>105</td></tr><tr><td>8.2.3</td><td>SPPAS 1.4.2</td><td>106</td></tr><tr><td>8.2.4</td><td>SPPAS 1.4.3</td><td>106</td></tr><tr><td>8.2.5</td><td>SPPAS 1.4.4</td><td>107</td></tr><tr><td>8.2.6</td><td>SPPAS 1.4.5</td><td>107</td></tr><tr><td>8.2.7</td><td>SPPAS 1.4.6</td><td>108</td></tr><tr><td>8.2.8</td><td>SPPAS 1.4.7</td><td>108</td></tr><tr><td>8.2.9</td><td>SPPAS 1.4.8</td><td>109</td></tr><tr><td>8.2.10</td><td>SPPAS 1.4.9</td><td>109</td></tr><tr><td>8.2.11</td><td>SPPAS 1.5.0</td><td>110</td></tr><tr><td>8.2.12</td><td>SPPAS 1.5.1</td><td>110</td></tr><tr><td>8.2.13</td><td>SPPAS 1.5.2</td><td>110</td></tr><tr><td>8.2.14</td><td>SPPAS 1.5.3</td><td>111</td></tr><tr><td>8.2.15</td><td>SPPAS 1.5.4</td><td>111</td></tr><tr><td>8.2.16</td><td>SPPAS 1.5.5</td><td>112</td></tr><tr><td>8.2.17</td><td>SPPAS 1.5.6</td><td>112</td></tr><tr><td>8.2.18</td><td>SPPAS 1.5.7</td><td>112</td></tr><tr><td>8.2.19</td><td>SPPAS 1.5.8</td><td>113</td></tr><tr><td>8.2.20</td><td>SPPAS 1.5.9</td><td>113</td></tr><tr><td>8.2.21</td><td>SPPAS 1.6.0</td><td>114</td></tr><tr><td>8.2.22</td><td>SPPAS 1.6.1</td><td>114</td></tr><tr><td>8.2.23</td><td>SPPAS 1.6.2</td><td>114</td></tr></table>
<table><tbody><tr><td>8.2.24</td><td>SPPAS 1.6.3</td><td>115</td></tr><tr><td>8.3</td><td>The beginnings of SPPAS</td><td>115</td></tr><tr><td>8.3.1</td><td>SPPAS 1.6.4</td><td>115</td></tr><tr><td>8.3.2</td><td>SPPAS 1.6.5</td><td>116</td></tr><tr><td>8.3.3</td><td>SPPAS 1.6.6</td><td>116</td></tr><tr><td>8.3.4</td><td>SPPAS-1.6.7</td><td>118</td></tr><tr><td>8.3.5</td><td>SPPAS-1.6.8</td><td>118</td></tr><tr><td>8.4</td><td>The development phase</td><td>119</td></tr><tr><td>8.4.1</td><td>SPPAS-1.6.9</td><td>119</td></tr><tr><td>8.4.2</td><td>SPPAS-1.7.0</td><td>120</td></tr><tr><td>8.4.3</td><td>SPPAS-1.7.1</td><td>120</td></tr><tr><td>8.4.4</td><td>SPPAS-1.7.2</td><td>121</td></tr><tr><td>8.4.5</td><td>SPPAS-1.7.3</td><td>121</td></tr><tr><td>8.4.6</td><td>SPPAS-1.7.4</td><td>122</td></tr><tr><td>8.4.7</td><td>SPPAS-1.7.5</td><td>122</td></tr><tr><td>8.4.8</td><td>SPPAS-1.7.6</td><td>123</td></tr><tr><td>8.4.9</td><td>SPPAS-1.7.7</td><td>123</td></tr><tr><td>8.4.10</td><td>SPPAS-1.7.8</td><td>124</td></tr><tr><td>8.4.11</td><td>SPPAS-1.7.9</td><td>124</td></tr><tr><td>8.5</td><td>The stabilization phase</td><td>125</td></tr><tr><td>8.5.1</td><td>SPPAS-1.8.0</td><td>125</td></tr><tr><td>8.5.2</td><td>SPPAS-1.8.1</td><td>125</td></tr><tr><td>8.5.3</td><td>SPPAS-1.8.2</td><td>126</td></tr><tr><td>8.5.4</td><td>SPPAS-1.8.3</td><td>126</td></tr><tr><td>8.5.5</td><td>SPPAS 1.8.4</td><td>126</td></tr><tr><td>8.5.6</td><td>SPPAS 1.8.5</td><td>127</td></tr><tr><td>8.5.7</td><td>SPPAS 1.8.6</td><td>127</td></tr><tr><td>8.5.8</td><td>SPPAS 1.9.0</td><td>127</td></tr><tr><td>8.5.9</td><td>SPPAS 1.9.1</td><td>128</td></tr><tr><td>8.5.10</td><td>SPPAS 1.9.2</td><td>129</td></tr><tr><td>8.5.11</td><td>SPPAS 1.9.3</td><td>129</td></tr><tr><td>8.5.12</td><td>SPPAS 1.9.4</td><td>129</td></tr><tr><td>8.5.13</td><td>SPPAS 1.9.5</td><td>130</td></tr><tr><td>8.5.14</td><td>SPPAS 1.9.6</td><td>130</td></tr><tr><td>8.5.15</td><td>SPPAS 1.9.7</td><td>130</td></tr></tbody></table>
<table><tbody><tr><td>8.5.16</td><td>SPPAS 1.9.8</td><td>131</td></tr><tr><td>8.5.17</td><td>SPPAS 1.9.9</td><td>132</td></tr><tr><td>8.5.18</td><td>SPPAS 2.0</td><td>133</td></tr><tr><td>8.5.19</td><td>SPPAS 2.1</td><td>133</td></tr><tr><td>8.5.20</td><td>SPPAS 2.2</td><td>134</td></tr><tr><td>8.5.21</td><td>SPPAS 2.3</td><td>134</td></tr><tr><td>8.5.22</td><td>SPPAS 2.4</td><td>135</td></tr><tr><td>8.5.23</td><td>SPPAS 2.5</td><td>135</td></tr><tr><td>8.5.24</td><td>SPPAS 2.6</td><td>136</td></tr><tr><td>8.5.25</td><td>SPPAS 2.7</td><td>136</td></tr><tr><td>8.5.26</td><td>SPPAS 2.8</td><td>137</td></tr><tr><td>8.5.27</td><td>SPPAS 2.9</td><td>137</td></tr><tr><td>8.6</td><td>Migrate to Python 3</td><td>138</td></tr><tr><td>8.6.1</td><td>SPPAS-3.0</td><td>138</td></tr><tr><td>8.6.2</td><td>SPPAS-3.1</td><td>138</td></tr><tr><td>8.6.3</td><td>SPPAS-3.2</td><td>139</td></tr><tr><td>8.6.4</td><td>SPPAS-3.3</td><td>140</td></tr><tr><td>8.6.5</td><td>SPPAS-3.4</td><td>140</td></tr><tr><td>8.6.6</td><td>SPPAS-3.5</td><td>141</td></tr><tr><td>8.6.7</td><td>SPPAS-3.6</td><td>142</td></tr><tr><td>8.6.8</td><td>SPPAS-3.7</td><td>142</td></tr><tr><td>8.6.9</td><td>SPPAS-3.8</td><td>143</td></tr><tr><td>8.6.10</td><td>SPPAS-3.9</td><td>144</td></tr><tr><td>8.7</td><td>Stable</td><td>145</td></tr><tr><td>8.7.1</td><td>SPPAS-4.0</td><td>145</td></tr><tr><td>8.7.2</td><td>SPPAS-4.1</td><td>146</td></tr><tr><td>8.7.3</td><td>SPPAS-4.2</td><td>147</td></tr><tr><td>8.7.4</td><td>SPPAS-4.3</td><td>149</td></tr><tr><td>8.7.5</td><td>SPPAS-4.4</td><td>150</td></tr><tr><td>8.7.6</td><td>SPPAS-4.5</td><td>150</td></tr><tr><td>8.7.7</td><td>SPPAS-4.6</td><td>151</td></tr><tr><td>8.7.8</td><td>SPPAS-4.7</td><td>152</td></tr></tbody></table>
<table><tr><td>9</td><td>Appendix</td><td>155</td></tr><tr><td>9.1</td><td>List of error messages</td><td>155</td></tr><tr><td>9.1.1</td><td>Global errors</td><td>155</td></tr><tr><td>9.1.2</td><td>From "annotations" package</td><td>155</td></tr><tr><td>9.1.3</td><td>From "utils" package</td><td>156</td></tr><tr><td>9.1.4</td><td>From "audiodata" package</td><td>156</td></tr><tr><td>9.1.5</td><td>From "calculus" package</td><td>157</td></tr><tr><td>9.1.6</td><td>From "plugins" package</td><td>157</td></tr><tr><td>9.1.7</td><td>From "resources" package</td><td>157</td></tr><tr><td>9.1.8</td><td>From "structs" package</td><td>158</td></tr><tr><td>9.1.9</td><td>From "models" package</td><td>158</td></tr><tr><td>9.2</td><td>GNU Free Documentation License</td><td>158</td></tr></table>
# Introduction

## 1.1 About this documentation

This documentation is governed by GNU Free Documentation License, version 1.3. It will assume that you are using a relatively recent version of SPPAS. There's no reason not to download the latest version whenever released: it's easy and fast!

Any and all constructive comments are welcome.

## 1.2 What is SPPAS?

### 1.2.1 Overview

SPPAS - the automatic annotation and analyses of speech is a scientific computer software package. SPPAS is daily developed with the aim to provide a robust and reliable software. Available for free, with open source code, there is simply no other package for linguists to simple use in both the automatic annotations of speech, the analyses of any kind of annotated data and the conversion of annotated file formats. You can imagine the annotations or analyses you need, SPPAS does the rest!

SPPAS ensures flexibility rather than a one-size-fits all approach in the implementation of the proposed features. There are no fixed or unique solutions, but a bunch of customizable features to make choices according to the user requirements.

Annotating recordings is very labor-intensive and cost-ineffective since it has to be performed manually by experienced researchers with many hours of work. As the primary functionality, SPPAS proposes a set of **automatic or semi-automatic annotations of recordings**. In the present context, annotations are “defined as the practice of adding interpretative, linguistic information to an electronic corpus of spoken and/or written language data. ‘Annotation’ can also refer to the end-product of this process” (Leech, 1997). SPPAS automatizes the annotation processes and allows users to save time. In order to be used efficiently, SPPAS expects a rigorous methodology to collect data and to prepare them.

Linguistics annotation, especially when dealing with multiple domains, makes use of different tools within a given project. This implies a rigorous annotation framework to ensure compatibilities between annotations and time-saving. SPPAS annotation files are in a specific XML format with extension xra. **Annotations**
can be imported from and exported to a variety of other formats including Praat (TextGrid, PitchTier, IntensityTier), Elan (eaf), Transcriber (trs), Annotation Pro (antx), Phonedit (mrk), Sclite (ctm, stm), HTK (lab, mlf), subtitles formats (srt, sub), CSV files...

"[...] when multiple annotations are integrated into a single data set, inter-relationships between the anno-
tations can be explored both qualitatively (by using database queries that combine levels) and quantitatively
(by running statistical analyses or machine learning algorithms)" (Chiarcos 2008). As a consequence, the an-
notations must be time-synchronized: annotations need to be time-aligned in order to be useful for purposes
such as analyses. Some special features are offered in SPPAS for **managing annotated files and analyzing
data**. Among others, it includes a tool to filter multi-levels annotations. Other included tools are to estimate
descriptive statistics, to manage annotated files, to manage audio files, etc. These data analysis tools of SP-
PAS are mainly proposed in the Graphical User Interface. However, advanced users can also access directly
the Application Programming Interface, for example to estimate statistics or to manipulate annotated data.

1.2.2 User engagement

By using SPPAS, **you agree to cite a reference in your publications.** The full list of references is available
in Chapter 7.

1.2.3 Need help

1. Many problems can be solved by updating the version of SPPAS.

2. When looking for more detail about some subject, one can search this documentation. This documentation is available in-line - see the SPPAS website, it is also included in the package in PDF format.

3. There are: a F.A.Q., tutorials and slides in the SPPAS web site.

1.2.4 About the author

Since January 2011, **Brigitte Bigi** is the main author of SPPAS. She has a tenured position of researcher at the French CNRS - **Centre National de la Recherche Scientifique**. She's working since 2009 at Laboratoire Parole et Langage in Aix-en-Provence, France.

More about the author:

• http://www.sppas.org/bigi

- https://orcid.org/0000-0003-1834-6918

Contact the author by e-mail:

* to improve the quality of the linguistic resources;

• to add new linguistic resources;

* to help in development;

• to add new annotations or analysis methods;

* to propose to collaborate for a research purpose;

• to declare an issue;

* to send a constructive comment.
Do not contact the author if:

* you failed to install Python or wxPython;

* you didn't follow the tutorials;

* you didn't read both the documentation and the tutorials.

Possible e-mails are:

* contact@sppas.org for general purposes;

* develop@sppas.org for developer questions or for a bug alert.

## Contributors

Here is the list of other contributors in programming:

* April 2012-June 2012: Alexandre Ranson (1st website)

* April 2012-July 2012: Cazembé Henry (1st GUI)

* April 2012-June 2013: Bastien Herbaut (help system)

* March 2013-March 2014: Tatsuya Watanabe (annotated data support)

* April 2015-June 2015: Nicolas Chazeau (audio support)

* April 2015-June 2015: Jibril Saffi (annotated data support)

* April 2019-June 2019: Barthélémy Drabczuk (workspaces and num2letter)

* April 2020-June 2020: Laurent Vouriot (a SPEAKER annotation)

* April 2020-June 2020: Florian Hocquet (installer and video support)

### 1.2.5 Licenses

SPPAS software, except documentation and resources, are distributed under the terms of the GNU GENERAL PUBLIC LICENSE v3.

Linguistic resources of SPPAS are either distributed:

* under the terms of the “GNU GENERAL PUBLIC LICENSE, v3”, or

* on the terms of the “Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License”.

See the documentation of the resources for details about individual license.

To summarize, SPPAS users are:

* free to study the source code and the resources of the software they use,

* free to share the software and resources with other people,

* free to modify the software and resources.

### 1.2.6 Supports

SPPAS is regularly supported by the Laboratoire Parole et Langage in many ways.
**2011-2012:**

Partly supported by ANR OTIM project (Ref. Nr. ANR-08-BLAN-0239), Tools for Multimodal Information Processing. Read more at: http://www.lpl-aix.fr/~otim/

**2013-2015:**

Partly supported by ORTOLANG (Ref. Nr. ANR-11-EQPX-0032) funded by the « Investissements d'Avenir » French Government program managed by the French National Research Agency (ANR). Read more at: http://www.ortolang.fr/

**2014-2016:**

SPPAS was also partly carried out thanks to the support of the following projects or groups:

* CoFee - Conversational Feedback http://cofee.hypotheses.org

* Variamu - Variations in Action: a Multilingual approach http://variamu.hypotheses.org

* Campus France, Procore PHC.

**2017-2020:**

The introduction of Naija language is supported by the ANR NaijaSynCor.

**2019-2020:**

The introduction of workspaces to manage files and the SPEAKER annotation type were both supported by the Vapvisio ANR project (ANR-18-CE28-0011-01).

**2020:**

Both the Proof of Concept of the Cued Speech automatic annotation and the package for the dependencies' installation was supported by the LPL.

**1.3 Getting and installing**

**1.3.1 Websites**

The main website of SPPAS is located at the following URL:

http://www.sppas.org

Click on “Get it -> Download” to get access to the last release and to some recent ones.

The source code is hosted by SourceForge at:

http://sppas.sf.net/
### 1.3.2 Download and install SPPAS

The main website contains the Download page to download recent versions of the SPPAS software package.

**Download and decompress the SPPAS package:**

There is a unique version of SPPAS which does not depend on the operating system. SPPAS is ready to run, so it does not need elaborate installation. All you need to do is to copy the SPPAS package from the website to somewhere on your computer. Choose a location with preferably only US-ASCII characters in the name - it obviously includes the path. The package of SPPAS is compressed and zipped, so you will need to decompress and unpack it once you've got it.

**Install external programs**

An installation guide is available and must be followed carefully.

Notice that administrator rights can be required.

**To summarize it:**

* STEP 1: install the recommended version of **Python 3.x ONCE**

* STEP 2:

- GUI: launch the `setup.bat` (Windows) or `setup.command` (Linux, MacOS) to continue the installation in GUI mode and follows instructions.

- CLI: you have first to create a Python venv with name ".sppaspyenv~", then use the program `sppas\bin\preinstall.py`. It allows installing external programs to enable some features, and the linguistic resources.

In case of difficulty arising from this installation, you're invited to consult the web first. It probably will provide the solution. If, however, the problems were to persist, ask a technician for help.

### 1.3.3 The package

SPPAS is a Research Software, distributed in the context of the **“Open Science”**. Then, unlike many other software tool, SPPAS is not distributed as an executable program. Instead, **everything is done so that users can check / change operation**.

It is particularly suitable for automatic annotations: it allows anyone to customize automatic annotations to its own needs and to implement its custom annotation solution.

The package of SPPAS is a directory with content as files and folders. It contains the followings:

* the `README.txt` file, which aims to be read!

* the files `setup.bat` and `setup.command` to install some external programs

* the files `sppas.bat` and `sppas.command` to launch the Graphical User Interface

* the `samples` directory contains data of various languages: they are proposed in order to test various features of SPPAS
* the `demo` folder contains an audio file, its corresponding orthographic transcription and the video file. It also contains a large amount of annotations automatically created by SPPAS.

* the `plugins` directory with one plugin. Others are available on the website.

* the `workspaces` directory with an example of a workspace

* the `sppas` directory contains the program itself, it's the SPPAS software itself

* the `resources` directory contains data that are used by automatic annotations (lexicons, dictionaries, ...)

* the `documentation` directory contains:

- the terms of the licenses

- the printable documentation

- the printable resources documentation

- the printable XRA file format documentation

- the printable version of the main reference published in "the Phonetician" journal

- the orthographic transcription convention

- the folder `scripting_solutions` is a set of python scripts corresponding to the exercises proposed in the chapter "Scripting with Python and SPPAS"

### 1.3.4 Update

SPPAS is constantly being improved and new packages are published frequently (about 10 versions a year). It is important to update regularly in order to get the latest features and corrections.

Updating SPPAS consists of downloading, decompressing and launching the setup.

## 1.4 Features

### 1.4.1 How to use SPPAS?

There are three main ways to use SPPAS:

1. The Graphical User Interface (GUI) is as user-friendly as possible:

* double-click on the `sppas.bat` file, under Windows;

* double-click on the `sppas.command` file, under MacOS or Linux.

2. The Command-line User Interface (CLI), with a set of programs, each one essentially independent of the others, that can be run on its own at the level of the shell.

3. Scripting with Python and SPPAS provides the more powerful way.

Features of SPPAS can then be used either with a Command-line User Interface (CLI) or a Graphical User Interface (GUI). This latter requires `wxPython` to be installed but not the former. So, there's no specific difficulty by using this software.

Advanced users can also access directly the Application Programming Interface - API.
1.4.2 What SPPAS can do?

Features of SPPAS can be divided into 3 main categories:

1. Annotate

2. Analyze

3. Convert

The SPPAS website contains the list of the features and how most of the automatic annotations can be
organized in an annotation workflow. See http://www.sppas.org/features.html

1.5 Main and important recommendations

1.5.1 About files

There is a list of important things to keep in mind while annotating with SPPAS. They are summarized as
follows and detailed in the chapters of this documentation:

1. Speech audio files for automatic annotations:

- only wav and au files are supported

- only mono (= one channel) files are supported

• frame rate is *preferably* 16000hz

• bit rate is *preferably* 16 bits

* good recording quality is expected. It is obviously required to never convert from a compressed file, as mp3 for example.

2. Annotated data files:

• UTF-8 encoding only

3. It is recommended to use only US-ASCII characters in file names, obviously it includes its path.

1.5.2 About automatic annotations

The quality of the results for most of the automatic annotations is highly influenced by **the quality of the data the annotation takes in input**. This is a politically correct way to say: *Garbage in, garbage out!*

Annotations are based on the use of linguistic resources. Resources for several languages are gently shared and freely available or downloadable. The quality of the automatic annotations is largely influenced by **the quality of the linguistic resources.**

1.5.3 About linguistic resources

Users are of crucial importance for resource development.

Do not hesitate to help in checking resource files and sharing your corrections with the community.

The users of SPPAS are invited to contribute to improve them. They can release the improvements to the public, so that the whole community benefits.
Any help is welcome to improve existing resources or to create new ones.
# User interfaces

## 2.1 Introduction

The current chapter describes how to manage workspaces, i.e a set of files and their description. Then it describes how to use the Graphical User Interface (GUI) and the Command-line User Interface (CLI).

## 2.2 Workspaces

### 2.2.1 Overview

A workspace is a manager of a set of files and of manually defined references. Several workspaces can be created but only one at a time is enabled when using SPPAS. All the features of SPPAS are using such currently enabled workspace.

### 2.2.2 Create and save a workspace

A workspace is described in a configuration file into the folder "workspaces" of the SPPAS package. This file is made of the name of the workspace followed by the extension ".json". It includes all properties of a workspace that are described here.

This configuration file can be copied into any other directory and re-imported into SPPAS.

### 2.2.3 Files

A workspace is managing a set of files. Each time a file is added into the currently selected workspace, its "root" and its "path" are extracted and stored into a tree-like architecture.

The data are structured as follows:

* a workspace contains a list of paths,

* each path contains the list of roots sharing this path,
* each root contains the list of filenames sharing this root.

For example, when adding the file `"/sppas/samples/samples-eng/oriana1.wav"` into the workspace, the following next actions will be performed:

* the path `"/sppas/samples/samples-eng/"` is added,

* the root `"/sppas/samples/samples-eng/oriana1"` is added into the path,

* the filename `"/sppas/samples/samples-eng/oriana1.wav"` is added into the root. Several properties of the file are also stored, including its size or the date of modification.

When SPPAS is creating a new file - like when annotating automatically, the filename is automatically added into the workspace. For example, when the automatic annotation "Fill in IPUs" has finished, the newly created file `"/sppas/samples/samples-eng/oriana1.xra"` is added into the workspace:

* the path `"/sppas/samples/samples-eng/"` is already existing so it's not added,

* the root `"/sppas/samples/samples-eng/oriana1"` is not added into the path because it's also already existing,

* the filename `"/sppas/samples/samples-eng/oriana1.xra"` is added into the root.

All files sharing the same root are then stored in the same place in the tree because there're sharing properties: they are all related to the same recording. The only difference between files sharing the same root are:

1. the extension (`.wav`, `.mp4`, `.mkv`, `.xra`, `.TextGrid`, ...)

2. the pattern (`-ipus`, `-token`, `-phon`, `-palign`, `-lexm`, `-orepet`, ...)

Notice that a pattern:

* must start by the character "-";

* must contain at least 1 character.

Thanks to this new management of files, the patterns used by the automatic annotations are not fixed anymore. Both the input and output patterns of the annotations can be modified at the time of configuring the annotations.

The second advantage of such management of files into a workspace is to add all files of a corpus only once into a workspace and to save it. It is then ready-to-use each time SPPAS is started.

To summarize, the file `"/sppas/samples/samples-eng/oriana1-token.TextGrid"` will be represented as follow:

1. `"/sppas/samples/samples-eng/"` is the *path*

2. `"/sppas/samples/samples-eng/oriana1"` is the *root*

3. `"/sppas/samples/samples-eng/oriana1-token.TextGrid"` is the *filename*, in which: `-"-token"` is the *pattern*, `-".TextGrid"` is the *extension*.

The workspace is also managing the state of each of these items: checked or not for filenames, checked/at least one checked/not checked for roots or paths.
### 2.2.4 References

The “references” are information that can be associated to files.

There are 3 different types of references: STANDALONE, SPEAKER and INTERACTION. Each of them corresponds to an annotation type. The annotations of both SPEAKER and INTERACTION type require to associate roots with these references.

Each reference can contain a list of attributes with an identifier key to define them, a value and its type, and a description. Here is an example of a reference “Oriana” of type SPEAKER with its list of attributes in the form “key: values (type)”:

* firstname: Oriana (str)

* gender: female (str)

* recorded_in: 2012 (int)

* L1: eng (str)

* L2: fra (str)

It is recommended to use only `us-ascii` characters and no whitespace for the key.

### 2.2.5 Associate files and references

Roots and references should be associated. In the previous example, it could allow to declare the list of files related to a given speaker. In that example, the reference “Oriana” should be associated to the roots: `"/sppas/samples/samples-eng/oriana1"` and `"/sppas/samples/samples-eng/oriana2"`.

In the specific case of interactions, a reference of the interaction has to be created and associated to the roots of the filenames.

The definition of such references, and their link to the corresponding roots allow to perform an elaborated way to check files of a workspace. It's very easy for example to check all files with file extension `.wav` of “female” gender more than 30 years old.

## 2.3 The Command-Line user Interface - CLI

### 2.3.1 Overview

A command-line user interface (CLI) is a means of interacting with a computer program where the user issues commands to the program in the form of successive lines of text (command lines). Command-line interfaces provide a more concise and powerful means to control the program than the GUI.

Operating system command line interfaces are called a command-line interpreter, command processor or shell. It displays a prompt, accept a “command line” typed by the user terminated by the Enter key, then execute the specified command and provide textual display of results or error messages. When a shell is active a program is typically invoked by typing its name followed by command-line arguments (if any).

Such CLI programs are located in the `bin` folder of the `sppas` directory of the package. All these programs are written with the programming language Python and are compatible with version 3.4+.

Installing Python is then the only required other program in order to work with SPPAS CLI except the `alignment.py` program which requires either Julius CSR or HVite (see installation instructions).
### 2.3.2 Usage

It is usual for a program to be able to display a brief summary of its parameters. Each program included in SPPAS provides its usage by using the option `--help`, as for example:

```
prompt> python .\sppas\bin\trsconvert.py --help
```

```
usage: trsconvert.py [files] [options]
```

```
... a program to export annotated files.
```

optional arguments:

-h, --help show this help message and exit

- quiet Disable the verbosity

- debug Highest level of verbosity

Files:

-i file Input annotated file name.

-o file Output annotated file name.

Options:

-n value Number of a tier (use as many -n options as wanted). Positive or negative value: 1=first tier, -1=last tier.

-t tiername Name of a tier (use as many -t options as wanted).

This program is part of SPPAS version 2.0. Copyright (C) 2011-2019 Brigitte Bigi.

Contact the author at: contact@sppas.org

### 2.3.3 Arguments for input/output

In most of the programs, there is an option `-i` for the input file. There's no specific constraint on this file name. For example, the following program will execute the Momel automatic annotation:

```
python .\sppas\bin\momel.py -i .\samples\samples-eng\ENG_M15_ENG_T02.PitchTier
```

With this option `-i`, a name of an output file can be given with the option `-o`; if not, the main part of the result is printed on the standard output.

In several programs, an option `-I` can also be available to execute the program, and several files can be processed with this option. Moreover, there is some flexibility in file names with this option. SPPAS will search for the appropriate file from the given file name. For example, the next commands will process the same:

```
python .\sppas\bin\intsint.py -I .\samples\samples-eng\ENG_M15_ENG_T02.wav
```

```
python .\sppas\bin\intsint.py -I .\samples\samples-eng\ENG_M15_ENG_T02.PitchTier
```

```
python .\sppas\bin\intsint.py -I .\samples\samples-eng\ENG_M15_ENG_T02-momel.xra
```

With the option `-I`, the name of the output file is fixed and can't be changed. For example, the previous example will create a file with name `.\samples\samples-eng\ENG_M15_ENG_T02-intsint.xra`. An option `-e` allows to choose the extension of the file, `.xra` is the default one.

The options to manage input/output files can be summarized as follows:
Files (manual mode):

-i file An input file.

-o file Output file name (optional).

Files (auto mode):

-I file Input file (append).

-e .ext Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

### 2.3.4 preinstall.py

This program allows to:

1. install external programs to enable some of the features of SPPAS - including the GUI;

2. install linguistic resources for the supported languages;

3. install resources required to enable some of the annotations.

## 2.4 The graphical user interface

### 2.4.1 Important

Once the installation is completed - including wxpython, the GUI feature is enabled. Do not launch the GUI of SPPAS if the installation is not finished, i.e. launch the setup first: see the tutorial series 2 and to follow instructions.

### 2.4.2 Launch the GUI

#### Under Windows

Once the SPPAS package is opened in the File Explorer, double-click on the `sppas.bat` file.

In recent versions of Windows (e.g. 10), the first time you try to run SPPAS you may get a window with title "Windows protected your PC" and the following message: "Windows SmartScreen prevented an unrecognized app from starting. Running this app might put your PC at risk. More info". Click More info message and then Run anyway button. The file will now run SPPAS, and you will now no longer get a Windows protected your PC prompt when you run this specific file next time. This warning message comes from the fact that SPPAS is a free software and we did not paid to Microsoft commercial fees which would remove the "Unknown Publisher" warnings.

#### Under MacOS

Once the SPPAS package is opened in the Finder, double-click on the `sppas.command` file.

The first time you try to run SPPAS you may get a message: "sppas.command can't be opened because it is from an unidentified developer.". This warning message comes from the fact that SPPAS is a free software and we did not paid to Apple commercial fees. The solution is to run SPPAS with a right click (alt-click) on sppas.command file. This time you will get a message: "sppas.command is from an unidentified developer. Are you sure you want to open it?" Then click on Open. It will also now work each time you run it.
Under Linux

Once the SPPAS package is opened in the File Explorer, double-click on the `sppas.command` file. Either, open a terminal and run it. Last solution is to directly execute `sppas/bin/sppasgui.py`.

2.4.3 The GUI of SPPAS

Both the main windows and a “Log window” will open. The main frame is made of a menubar at top, a main content in the middle and buttons for actions at bottom.

Most of the existing/incoming tutorials are explaining how to access features of SPPAS with this GUI. This chapter only summarizes some of them.

2.4.4 The main frame

The top menu allows to open various pages like “Files”, “Annotate” or “Analyze”. There are 2 ways to browse through the items of the menu: with the mouse or with the keyboard. To open a page with the mouse, just click on the item button in the menubar. To open a page with the keyboard, under Windows, press CTRL and under MacOS, press COMMAND. Click left-right arrows to navigate to the previous/next page. Use up-arrow to go to the 1st page and Down-arrow to the last page. Use “CTRL+F”/“COMMAND+F” to go to the “Files” page.

To change colors and fonts, click the Settings icon at bottom. These settings are saved in a file which is used each time SPPAS is executed.

The About action button allows displaying information about SPPAS: author, license, a link to the web site, etc.

Home page

The home page shows a welcome message and gives a quick access to a set of external links. Clicking on the buttons will open the default web-browser of the OS to this link.

The links are pointing to:

* the SPPAS home web site: http://www.sppas.org

* the in-line version of this documentation

* the in-line tutorials

* the frequently asked questions

* the home page of the author, including the whole list of publications related to SPPAS: http://www2.lpl-aix.fr/~bigi/

Files page

The page “Files” is dealing with the workspaces (see the previous section about workspaces).
**Workspaces:** A column at left with green buttons contains a list of buttons to perform actions related to the workspaces then the list of existing ones.

The actions to perform are:

1. "Import from": select a workspace file (`.wjson`) somewhere on the computer and add it into the SPPAS workspaces directory.

2. "Export to": save the currently enabled workspace somewhere in the computer

3. "Pin & Save": The currently selected workspace is saved. If the currently selected workspace is "Blank", clicking this action will ask for a workspace name and create it ("Pin"), then select it.

4. "Rename": change the name of the currently selected workspace. Can't be applied on the "Blank" workspace.

The list of workspaces allows to select a workspace among the existing ones or to work with the "Blank" one (default).

**Files:** The files area with a pinky color displays the tree of files of the currently selected workspace, and a toolbar with action buttons.

The actions to perform are:

1. "Add": add new files into the workspace

2. "Remove checked": remove the checked files of the workspace

3. Remove missing files of the workspace. The tree of paths/roots/files is explored and if a filename does not correspond to an existing file on the disk, it is removed of the workspace tree

4. All files of the disk sharing the checked roots will be added to the workspace tree

**References:** The "References" area with a blue color displays the tree of references of the currently selected workspace, and a toolbar with action buttons.

The actions to perform are:

1. "Create": Open a dialog to ask for a name and the reference type among: STANDALONE, INTER-ACTION, SPEAKER. It then creates the corresponding reference and add it to the workspace

2. "Edit": Open a dialog to delete, add or modify the attributes of the checked references.

3. "Delete": Definitively delete the checked references. There's no way to recover them if needed.

**Column of action buttons:** Between the files and references, there's a column with action buttons. The actions to perform are related to files:

1. Open the checked files with a text editor (under development)

2. "Delete checked": remove the checked files of the workspace *and* delete them of the disk. Actually, there are moved and renamed into the trash of SPPAS. To recover a mistaken deleted file, use your OS explorer.

3. Check/unclick all files

4. Check only files matching some patterns.

or to link files and references:

5. Associate the checked roots to the checked references

6. Dissociate the checked roots of the checked references
## Annotate page

This page allows annotating checked files of the currently enabled workspace.

The automatic annotation is a 5-steps process:

1. Choose the output file format. All the automatic annotations are creating files. Choosing the extension means to choose the format of the resulting file. Some formats are more “powerful” than others, some are more “sharable”...

2. Fix the language. Some annotations are language-independent, so they don't need a specific language resource, like “Search for IPUs” or “Face detection”. But some annotations are requiring linguistic resources like a lexicon (Text Normalization), a dictionary (Phonetization), etc. This step allows to choose the language among the list of installed ones.

3. Select and configure annotations. Click any of the STANDALONE, SPEAKER or INTERACTION button. It will change the page content in order to select the annotations SPPAS will perform and to configure them. Click the top arrow to come back to the main page.

4. Perform the annotations. Click the “Let’s go” button to launch the automatic annotation process, and wait!

5. A procedure outcome report is displayed and saved in the logs folder of the SPPAS package.

The previously saved reports are listed in the column at right of the page. Click the button “Show report” to display the content of the checked one.

## Analyze page

This page is a merge of the “DataFilter”, the “DataStats” and the “DataRoamer” of the previous GUI version... with new features added.

It allows to display a summary of each file: either audio or annotated files can be opened and analyzed. The following analyses can be performed:

* manage tiers: duplicate, remove, copy, move, ...

* estimate distribution statistics on tiers;

* create new tiers with the filter systems, either the “simple” or the “relation one”;

* check if an audio file is compatible with the automatic annotations.

## Editor page

This page is a merge of the “IPUScriber” and the “Visualizer” of the previous GUI version... with new features added.

It allows to annotate manually and to view files in a timeline. The features “video” is required to play a video file and the feature “audioplay” is required to play an audio file.

This editor is very useful to play several media at a time synchronously.
## Convert page

The convert page allows to export the checked annotated files of the workspace in any of the supported file format.

The displayed table indicates all the format capabilities, including:

* Metadata: the file format supports metadata, i.e. it can save extra-information, not only annotations. If not, the metadata won't be exported;

* Multi tiers: the file format accepts to save more than one tier;

* No tier: the file format can save a file without tiers;

* Point: the file format can save tiers of type 'Point';

* Interval: the file format can save tiers of type 'Interval'.

* Gaps: the file format supports gaps between annotations of a tier. If not, when exporting the file, SPPAS will fill in the gaps by annotations with an empty label;

* Overlaps: the file format supports overlaps between annotations of a tier. If not, when exporting the file, SPPAS will split annotations to create a sequence of non-overlapping ones.

* Hierarchy: the format can deal with a hierarchy of tiers. If not, the hierarchy won't be saved.

* Ctrl vocab: the format can save a controlled vocabulary of tiers. If not, the controlled vocabularies won't be saved.

* Media: the format can save a reference to a media of tiers. If not, the media information won't be saved.

* Vagueness: the format supports a vagueness value of the localization. If not, the vagueness value won't be saved.

* Alt. loc: the format supports alternative annotation localizations. If not, the alternative localizations won't be saved.

* Alt. tag: the format supports alternative annotation tags. If not, when exporting the annotations, SPPAS will use a "{ | }" system to parse the alternative tags and = for scores.

## Plugins page

Installing plugins is a very useful solution to extend the features of SPPAS. Several plugins are available for download in the main site of SPPAS. The plugins of SPPAS are installed in a folder with name "plugins" in the main directory of the SPPAS package.

To install a new plugin, simply follow this workflow:

1. Create or download the plugin package - e.g. a zip file.

2. Execute SPPAS.

3. Click on 'Plugin' then click on the 'Install' button of the toolbar.

4. Browse to indicate the plugin package.

5. See the new plugin at bottom of the plugins list.

To delete a plugin, click on the "Delete" button of the toolbar. Choose the plugin in the given list then click on the "OK" button. Notice that the plugin is definitively deleted of the disk.

To execute a plug-in, check the file(s) of your current workspace in the File page, then, click on the icon of the plug-in and follow instructions of the plugged program.
# Automatic Annotations

## 3.1 Introduction

### 3.1.1 About this chapter

This chapter describes the followings:

* what is the goal of the annotation;

* what are the requirements (files, tiers);

* what kind of resources are needed;

* what is the expected result;

* how to perform it within SPPAS.

However, this chapter is not a description on how each automatic annotation is working and what to expect about it: there are references for that in chapter 8.

Among others, SPPAS is able to produce automatically annotations from a recorded speech sound and its orthographic transcription. Let us first introduce what is **the recommended way to annotate a corpus with SPPAS**.

### 3.1.2 THE recommended corpus construction workflow

The kind of process to implement in the perspective of obtaining rich and broad-coverage multimodal/multi-levels annotations of a corpus is illustrated in next Figure. It describes each step of the annotation workflow. Obviously, there are other ways to construct a corpus but 1/ do not blame SPPAS if you don't get the results you expected, and 2/ do not contact the author if you have chosen to not follow these recommendations.

This Figure must be read from top to bottom and from left to right, starting by the recordings and ending to the analysis of annotated files. Yellow boxes represent manual annotations, blue boxes represent automatic ones.

Annotation methodology
After the recording an audio file (see recordings recommendations), the first annotation to perform is to search for the IPUs. Indeed, at a first stage, the audio signal must be automatically segmented into Inter-Pausal Units (IPUs) which are sounding segments surrounded by silent pauses of more than X ms, and time-aligned on the speech signal.

An orthographic transcription has to be performed **manually inside the IPUs** (do not expect to use an automatic speech transcription system). Then text normalization automatic annotation will normalize the orthographic transcription. The phonetization process will convert the normalized text in a grammar of pronunciations using X-SAMPA standard. Alignment will perform segmentation at phonemes and tokens levels, etc.

At the end of each automatic annotation process, SPPAS produces a *Procedure Outcome Report*. It contains important information about the annotations. It includes all parameters and eventually warnings and errors that occurred during the annotation process. This window opens in the scope to be read by users (!) and should be saved with the annotated corpus.

### 3.1.3 Recordings

SPPAS performs automatic annotations: It does not make sense to hope for miracles but you can expect good enough results that will allow you to save your precious time! And it *begins by taking care of the recordings...*

#### Audio files

Only `wav` and `au` audio file formats are supported by Python, so does SPPAS;

Only mono audio files are supported by automatic annotations of SPPAS.

SPPAS verifies if the audio file is 16 bits sample rate and 16000 Hz frame rate. Otherwise it automatically creates a new converted audio file. For very long files, this process may take time. If Python can't read the audio file, an error message is displayed: you'll have to convert it with `audacity`, `praat...` A relatively good recording quality is expected (see next Figure).

For example, both "Search for IPUs" and "Fill in IPUs" require a better quality compared to what is expected by "Alignment", and for that latter, it depends on the language. The quality of the result of automatic annotations highly depends on the quality of the audio file.

#### Example of expected recorded speech

Providing a guideline or recommendation of good practices is impossible, because it depends on too many factors. However, the followings are obvious:

* Never, never, never records a lossy audio file. It means that extracting the audio file from a video is feasible only if the embedded audio is either lossless or not compressed: see this page https://en.wikipedia.org/wiki/Comparison_ofVideoContainerFormats.

* The better microphone, the better audio file! Using a headworn microphone is much more better than a clip-on one. At LPL, we get very good results with the AKG C520.

* The recorded volume must be high enough. Ideally, it should be in range [-0.5 ; 0.5]. If all the amplitude values are in range [-0.1 ; 0.1], the difference between speech and silence is very slight and it makes the search for silences very difficult.
* The audio file should not be 32 floating bits. For speech, 32 bits are totally unusefull and - worse, sometimes Python can't read it.

* as you probably don't plan to burn your audio file on a CD-ROM, 44100Hz frame rate does not make sense. 48000hz is a more reasonable choice, particularly because it doesn't need of elaborated interpolation methods when it's converted to 16000hz for automatic annotations.

## Video files

SPPAS is proposing a few automatic annotations of a video if the Python library `opengl` is installed. All of them are annotating the face of recorded people.

### 3.1.4 File formats and tier names

When annotating with the GUI, the file names of each annotation is fixed and can't be customized. A filename is made of a root, followed by a pattern then an extension. For example `"oriana1-palign.TextGrid"` is made of the root `"oriana1"`, the pattern `"-palign"` and the extension `".TextGrid"`. Each annotation allows to fix manually the pattern and to choose the extension among the list of the supported ones. Notice that the pattern must start with the `"-"` (minus) character. It means that the character `"-"` must only be used to separate the root to the pattern:

> The character `-` can't be used in the root of a filename.

The name of the tiers the annotations are expecting for their input are fixed and can't be changed; so does the produced tier names.

## 3.2 Resources required to annotate

All the automatic annotations proposed by SPPAS are designed with language-independent algorithms, but some annotations are requiring language-knowledges. This linguistic knowledge is represented in external files so they can be added, edited or removed easily.

Adding a new language for a given annotation only consists in adding the linguistic resources the annotation needs, like lexicons, dictionaries, models, set of rules, etc. For example, see:

> Mélanie Lancien, Marie-Hélène Côté, Brigitte Bigi (2020). Developing Resources for Automated Speech Processing of Quebec French. In Proceedings of The 12th Language Resources and Evaluation Conference, pp. 5323–5328, Marseille, France.

> Brigitte Bigi, Bernard Caron, Abiola S. Oyelere (2017). Developing Resources for Automated Speech Processing of the African Language Naija (Nigerian Pidgin). In 8th Language and Technology Conference: Human Language Technologies as a Challenge for Computer Science and Linguistics, pp. 441-445, Poznań, Poland.
### 3.2.1 Download and install linguistic resources

Since June 2020, the linguistic resources and models for some annotations are no longer distributed into the package of SPPAS. Instead, they are hosted by Ortolang repository with a public access.

They can be installed automatically into SPPAS by the `preinstall.py` program (CLI) or in the GUI by clicking “Add languages” or “Add annotations” in the toolbar of the “Annotate” page.

They can also be installed manually by downloading them at: https://hdl.handle.net/11403/sppasresources and unpacking the zip file into the `resources` folder of SPPAS package.

A full description of such resources and how to install them is available in the repository: download and read the file Documentation.pdf. It contains details about the list of phonemes, authors, licenses, etc.

### 3.2.2 New language support

Some of the annotations are requiring external linguistic resources in order to work efficiently on a given language: text normalization requires a lexicon, phonetization requires a pronunciation dictionary, etc. It is either possible to install and use the existing resources or to create and use custom ones.

When executing SPPAS, the list of available languages of each annotation is dynamically created by exploring the `resources` directory content. This means that:

* the resources you added or modified are automatically taken into account (ie. there's no need to modify the program itself);

* SPPAS needs to be re-started if new resources are added when it was already being running.

## 3.3 Annotate with the GUI

Performing automatic annotations with SPPAS Graphical User Interface is a step-by-step process.

It starts by checking the list of paths and/or roots and/or files in the currently active workspace of the “Files” page. Then, in the “Annotate” page:

1. Select the output file format, i.e. the file format of the files SPPAS will create;

2. Select a language in the list;

3. Enable each annotation to perform by clicking on the button in red, among STANDALONE, SPEAKER and INTERACTION annotation types. Each button will be turned green if some annotations are selected.

3.1 Configure each annotation by clicking on the “Configure…” link text in blue;

3.2 The language of any annotation can be changed.

4. Click on the *Perform annotations* button, and wait. A progress bar should indicates the annotation steps and files. Some annotations are very very fast but some others are not. For example, Face Detection is 2.5 x real times, i.e. annotating a video of 1 minute will take 2 minutes 30 secs.

5. It is important to read the Procedure Outcome report. It allows to check that everything happened normally during the automatic annotations. This report is saved in the “logs” folder of the SPPAS package.
## 3.4 Annotate with the CLI

To perform automatic annotations with the Command-line User Interface, there is a main program `annotation.py`. This program allows to annotate in an easy-and-fast way but none of the annotations can be configured: their default parameters are used. This program performs automatic annotations on a given file or on all files of a directory. It strictly corresponds to the button Perform annotations of the GUI except that annotations are pre-configured: no specific option can be specified.

```
usage: python .\sppas\bin\annotation.py -I file|folder [options]
```

### optional arguments:

<table><tr><td>-h, --help</td><td>show this help message and exit</td></tr><tr><td>--log file</td><td>File name for a Procedure Outcome Report (default: None)</td></tr><tr><td>--momel</td><td>Activate Momel</td></tr><tr><td>--intsint</td><td>Activate INTSINT</td></tr><tr><td>--fillipus</td><td>Activate Fill in IPUs</td></tr><tr><td>--searchipus</td><td>Activate Search for IPUs</td></tr><tr><td>--textnorm</td><td>Activate Text Normalization</td></tr><tr><td>--phonetize</td><td>Activate Phonetization</td></tr><tr><td>--alignment</td><td>Activate Alignment</td></tr><tr><td>--syllabify</td><td>Activate Syllabification</td></tr><tr><td>--tga</td><td>Activate Time Group Analysis</td></tr><tr><td>--activity</td><td>Activate Activity</td></tr><tr><td>--rms</td><td>Activate RMS</td></tr><tr><td>--selfrepet</td><td>Activate Self-Repetitions</td></tr><tr><td>--stopwords</td><td>Activate Stop Tags</td></tr><tr><td>--lexmetric</td><td>Activate LexMetric</td></tr><tr><td>--otherrepet</td><td>Activate Other-Repetitions</td></tr><tr><td>--reoccurrences</td><td>Activate Re-Occurrences</td></tr><tr><td>--merge</td><td>Create a merged file with all the annotations</td></tr></table>

### Files:

<table><tr><td>-I file|folder</td><td>Input transcription file name (append).</td></tr><tr><td>-l lang</td><td>Language code (iso8859-3). One of: por eng ita kor deu nan vie und hun spa cat pol yue fra pcm yue_chars cmn jpn.</td></tr><tr><td>-e .ext</td><td>Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff</td></tr></table>

### Examples of use:

```
./sppas/bin/annotation.py -I .\samples\samples-eng
-l eng
-e .TextGrid
--fillipus --textnorm --phonetize --alignment
```

A progress bar is displayed for each annotation if the Terminal is supporting it (bash for example). Instead, the progress is indicated line-by-line (Windows PowerShell for example).

CLI: annotation.py output example

Each annotation has also its own program and all options can be fixed. They are all located in the `sppas/bin` folder.
## 3.5 The procedure outcome report

It is very important to read conscientiously this report: it describes exactly what happened during the automatic annotation process. It is recommended to store a copy of the report within the corpus because it contains information that are interesting to know for anyone using the annotations.

By default, all reports are saved in the “logs” folder of the SPPAS package.

The text first indicates the version of SPPAS that was used. This information is very important. Annotations in SPPAS and their related resources are regularly improved and then, the result of the automatic process can change from one version to the other one.

Example:

SPPAS version 3.5
Copyright (C) 2011-2021 Brigitte Bigi
Web site: http://www.sppas.org/
Contact: Brigitte Bigi (contact@sppas.org)

Secondly, the text shows information related to the given input:

1. the selected language of each annotation - only if the annotation is language-dependent. For some language-dependent annotations, SPPAS can still perform the annotation even if the resources for a given language are not available: in that case, select “und”, which is the iso639-3 code for “undetermined”.

2. the selected files and folder to be annotated.

3. the list of annotations, and if each annotation was enabled. In that case, enabled means that the checkbox of the annotation was checked by the user and that the resources are available for the given language. On the contrary, disabled means that either the checkbox was not checked or the required resources are not available.

4. the file format of the resulting files.

Example:

Date: 2020-04-21T11:14:01+02:00

Input languages:

- Momel: ---

- INTSINT: ---

- Fill in IPUs: ---

- Search for IPUs: ---

- Text Normalization: eng

- Phonetization: eng

- Alignment: eng

- Syllabification:

- Time Group Analysis: ---

- Activity: ---

- RMS: ---

- Self-Repetitions:

- Stop Tags:

- LexMetric: ---

- Other-Repetitions:
- Re-Occurrences: ---

Selected files and folders:

- oriana1.wav

Selected annotations:

- Momel: enabled

- INTSINT: enabled

- Fill in IPUs: enabled

- Search for IPUs: disabled

- Text Normalization: enabled

- Phonetization: enabled

- Alignment: enabled

- Syllabification: disabled

- Time Group Analysis: disabled

- Activity: disabled

- RMS: disabled

- Self-Repetitions: disabled

- Stop Tags: disabled

- LexMetric: disabled

- Other-Repetitions: disabled

- Re-Occurrences: disabled

File extension: .xra

Thirdly, each automatic annotation is described in details, for each annotated file. At a first stage, the list of options and their value is summarized. Example:

Text Normalization

The vocabulary contains 121250 tokens.

The replacement dictionary contains 8 items.

Options:

... inputpattern:

... outputpattern: -token

... faked: True

... std: False

... custom: False

... occ_dur: True

Then, a diagnosis of the given file is printed. It can be: 1. "Valid": the file is relevant 2. "Admit": the file is not like expected but SPPAS will convert it and work on the converted file. 3. "Invalid": SPPAS can't work with that file. The annotation is then disabled. In case 2 and 3, a message indicates the origin of the problem.

Then, if any, the annotation procedure prints messages. Four levels of information must draw your attention:

1. "[OK]" means that everything happened normally. The annotation was performed successfully.

2. "[IGNORE]" means that SPPAS ignored the file and didn't do anything.

3. "[WARNING]" means that something happened abnormally, but SPPAS found a solution, and the annotation was performed anyway.

4. "[ERROR]" means that something happened abnormally and SPPAS failed to find a solution. The annotation was either not performed, or performed with a wrong result.
Example of “Warning” message:

... ... Export AP_track_0711.TextGrid
... ... into AP_track_0711.xra
... ... [ IGNORE ] because a previous segmentation is existing.

Example of “Warning” message:

... ... [ WARNING ] chort- is missing of the dictionary and was automatically phonetized as S-O/-R-t

At the end of the report, the “Result statistics” section mentions the number of files that were annotated for each annotation, or -1 if the annotation was disabled.

3.6 Orthographic Transcription

An orthographic transcription is often the minimum requirement for a speech corpus so it is at the top of
the annotation procedure, and it is the entry point for most of the automatic annotations. A transcription
convention is designed to provide rules for writing speech corpora. This convention establishes what are the
phenomena to transcribe and also how to mention them in the orthography.

From the beginning of its development it was considered to be essential for SPPAS to deal with an **Enriched Orthographic Transcription** (EOT). The transcription convention is summarized below and all details are given in the file *TOE-SPPAS.pdf*, available in the *documentation* folder. It indicates the rules and includes examples of what is expected or recommended.

Convention overview:

* truncated words, noted as a '-' at the end of the token string (an ex- example);

• noises, noted by a '*' (not available for some languages);

• laughter, noted by a '@' (not available for some languages);

• short pauses, noted by a '+';

• elisions, mentioned in parenthesis;

• specific pronunciations, noted with brackets [example,eczap];

• comments are preferably noted inside braces {this is a comment!};

• comments can be noted inside brackets without using comma [this and this];

• liaisons, noted between '=' (this =n= example);

• morphological variants with <ice scream,I scream>

• proper name annotation, like $ John S. Doe $.

The symbols * + @ must be surrounded by whitespace.

SPPAS allows to include the regular punctuations. For some languages, it also allows to include numbers:
they will be automatically converted to their written form during Text Normalization process.

From this EOT, several derived transcriptions can be generated automatically, including the two followings:
1. the standard transcription is the list of orthographic tokens (optional);

2. a specific transcription from which the phonetic tokens are obtained to be used by the grapheme-phoneme converter that is named faked transcription (the default).

For example, with the transcribed sentence: *This [is,iz] + hum... an enrich(ed) transcription {loud} number 1!*, the derived transcriptions are:

1. standard: *this is + hum an enriched transcription number one*

2. tokens: *this iz + hum an enrich transcription number one*

Notice that the convention allows to include a large scale of phenomena, for which most of them are optional.
As a minimum, the **transcription must include**:

• filled pauses;

• short pauses;

• repeats;

• noises and laugh items (not available for Japanese and Cantonese).

Finally, it has to be noticed that this convention is not software-dependent. The orthographic transcription
can be manually performed within SPPAS GUI in the “Edit” page, with Praat, with Annotation Pro, Audacity,
...

3.7 Search for Inter-Pausal Units (IPUs)

3.7.1 Overview

The Search for IPUs is a semi-automatic annotation process. This segmentation provides an annotated file
with one tier named “IPUs”. The silence intervals are labelled with the “#” symbol, and IPUs intervals are
labelled with “ipu_” followed by the IPU number. This annotation is semi-automatic: **it should be verified**
**manually**.

Notice that the better recording quality, the better IPUs segmentation.

3.7.2 The parameters

The following parameters must be properly fixed:

*   Minimum volume value (in seconds): If this value is set to zero, the minimum volume is automatically adjusted for each sound file. Try with it first, then if the automatic value is not correct, set it manually. The Procedure Outcome Report indicates the value the system choose. The AudioRoamer component can also be of great help: it indicates min, max and mean volume values of the sound.

*   Minimum silence duration (in seconds): By default, this is fixed to 0.2 sec. This duration mostly depends on the language. It is commonly fixed to at least 0.2 sec for French and at least 0.25 seconds for English language.
* Minimum speech duration (in seconds): By default, this value is fixed to 0.3 sec. A relevant value depends on the speech style: for isolated sentences, probably 0.5 sec should be better, but it should be about 0.1 sec for spontaneous speech.

* IPUs boundary shift (in seconds) for start or end: a duration which is systematically added to IPUs boundaries, to enlarge the IPUs interval, and as a consequence, the neighboring silences are reduced.

The procedure outcome report indicates the values (volume, minimum durations) that were used by the system for each sound file.

### 3.7.3 Perform “Search for IPUs” with the GUI

It is an annotation of STANDALONE type.

Click on the “Search IPUs” activation button and on the “Configure…” blue text to fix options.

Example of result

Notice that the speech segments can be transcribed using SPPAS, in the “Analyze” page.

Orthographic transcription based on IPUs

### 3.7.4 Perform “Search for IPUs” with the CLI

`searchipus.py` is the program to perform this semi-automatic annotation, i.e. silence/IPUs segmentation, either on a single file (-i and optionnally -o) or on a set of files (by using -I and optionnally -e).

#### Usage

searchipus.py [files] [options]

Search for IPUs: Search for Inter-Pausal Units in an audio file.

optional arguments:

-h, --help show this help message and exit

-q, --quiet Disable the verbosity

-l, --log file File name for a Procedure Outcome Report (default: None)

Files (manual mode):

-i file Input wav file name.

-o file Annotated file with silences/units segmentation (default: None)

Files (auto mode):

-I file Input wav file name (append).

-e .ext Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

Options:

-o, --outputpattern OUTPUTPATTERN

Output file pattern (default: )

-w, --win_length WIN_LENGTH
<table><tr><td>--threshold THRESHOLD</td><td>Window size to estimate rms (in seconds) (default:<br>0.020)</td></tr><tr><td>--min_ipu MIN_IPU</td><td>Threshold of the volume value (rms) for the detection<br>of silences, 0=automatic (default: 0)</td></tr><tr><td>--min_sil MIN_SIL</td><td>Minimum duration of an IPU (in seconds) (default:<br>0.300)</td></tr><tr><td>--shift_start SHIFT_START</td><td>Systematically move at left the boundary of the<br>beginning of an IPU (in seconds) (default: 0.01)</td></tr><tr><td>--shift_end SHIFT_END</td><td>Systematically move at right the boundary of the end<br>of an IPU (in seconds) (default: 0.02)</td></tr></table>

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

## Examples of use

A single input file and output on stdout:

```
python .\sppas\bin\searchipus.py -i .\samples\samples-eng\oriana1.wav
2018-12-19 10:49:32,782 [INFO] Logging set up level=15
2018-12-19 10:49:32,790 [INFO] ... Information:
2018-12-19 10:49:32,792 [INFO] ... ... Number of IPUs found: 3
2018-12-19 10:49:32,792 [INFO] ... ... Threshold volume value: 0
2018-12-19 10:49:32,792 [INFO] ... ... Threshold silence duration: 0.200
2018-12-19 10:49:32,792 [INFO] ... ... Threshold speech duration: 0.300
0.000000 1.675000 #
1.675000 4.580000 ipu_1
4.580000 6.390000 #
6.390000 9.880000 ipu_2
9.880000 11.430000 #
11.430000 14.740000 ipu_3
14.740000 17.792000 #
```

Idem without logs:

```
python .\sppas\bin\searchipus.py -i .\samples\samples-eng\oriana1.wav --quiet
0.000000 1.675000 #
1.675000 4.580000 ipu_1
4.580000 6.390000 #
6.390000 9.880000 ipu_2
9.880000 11.430000 #
11.430000 14.740000 ipu_3
14.740000 17.792000 #
```

Several input files, output in Praat-TextGrid file format:
<figure><img src="image_4.png" /></figure>

## 3.8 Fill in Inter-Pausal Units (IPUs)

### 3.8.1 Overview

This automatic annotation consists in aligning macro-units of a document with the corresponding sound.

IPUs are blocks of speech bounded by silent pauses of more than X ms. This annotation searches for a silences/IPUs segmentation of a recorded file (see previous section) and fill in the IPUs with the transcription given in a `txt` file.

### 3.8.2 How does it work

SPPAS identifies silent pauses in the signal and attempts to align them with the units proposed in the transcription file, under the assumption that each such unit is separated by a silent pause. It is based on the search of silences described in the previous section, but in this case, the number of units to find is known. The system adjusts automatically the volume threshold and the minimum durations of silences/IPUs to get the right number of units. The content of the units has no regard, because SPPAS does not interpret them: it can be the orthographic transcription, a translation, numbers, ... This algorithm is language-independent: it can work on any language.

In the transcription file, **silent pauses must be indicated** using both solutions, which can be combined:

* with the symbol '#';

* with newlines.

A recorded speech file must strictly correspond to a `txt` file of the transcription. The annotation provides an annotated file with one tier named "Transcription". The silence intervals are labelled with the "#" symbol, as IPUs are labelled with "ipu_" followed by the IPU number then the corresponding transcription.

The same parameters than those indicated in the previous section must be fixed.

Remark: This annotation was tested on read speech no longer than a few sentences (about 1 minute speech) and on recordings of very good quality.

Fill in IPUs
### 3.8.3 Perform “Fill in IPUs” with the GUI

It is an annotation of STANDALONE type.

Click on the “Fill in IPUs” activation button and on the “Configure…” blue text to fix options.

### 3.8.4 Perform “Fill in IPUs” with the CLI

`fillipus.py` is the program to perform this IPUs segmentation, i.e. silence/ipus segmentation, either on a single file (-i and optionally -o) or on a set of files (by using -I and optionally -e).

#### Usage

```
fillipus.py [files] [options]
```

Fill in IPUs: Search for Inter-Pausal Units and fill in with a transcription.
Requires an audio file and a .txt file with the transcription.

optional arguments:

<table><tr><td>-h, --help</td><td>show this help message and exit</td></tr><tr><td>--quiet</td><td>Disable the verbosity</td></tr><tr><td>--log file</td><td>File name for a Procedure Outcome Report (default: None)</td></tr></table>

Files (manual mode):

<table><tr><td>-i file</td><td>Input wav file name.</td></tr><tr><td>-t file</td><td>Input transcription file name.</td></tr><tr><td>-o file</td><td>Annotated file with filled IPUs</td></tr></table>

Files (auto mode):

<table><tr><td>-I file</td><td>Input wav file name (append).</td></tr><tr><td>-e .ext</td><td>Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff</td></tr></table>

Options:

<table><tr><td>--outputpattern OUTPUTPATTERN</td><td>Output file pattern (default: )</td></tr><tr><td>--min_ipu MIN_IPU</td><td>Initial minimum duration of an IPU (in seconds) (default: 0.300)</td></tr><tr><td>--min_sil MIN_SIL</td><td>Initial minimum duration of a silence (in seconds) (default: 0.200)</td></tr></table>

This program is part of SPPAS version 3.0. Copyright (C) 2011-2020 Brigitte Bigi. Contact the author at: contact@sppas.org

#### Examples of use

A single input file with an input in manual mode:

```
python .\sppas\bin\fillipus.py -i .\samples\samples-eng\oriana1.wav -t .\samples\samples-eng\oriana1.txt 2018-12-19 11:03:15,614 [INFO] Logging set up level=15
2018-12-19 11:03:15,628 [INFO] ... Information:
```
2018-12-19 11:03:15,628 [INFO] ... Threshold volume value: 122
2018-12-19 11:03:15,630 [INFO] ... Threshold silence duration: 0.200
2018-12-19 11:03:15,630 [INFO] ... Threshold speech duration: 0.300
0.000000 1.675000 #
1.675000 4.570000 the flight was 12 hours long and we really got bored
4.570000 6.390000 #
6.390000 9.870000 they only played two movies + which we had both already seen
9.870000 11.430000 #
11.430000 14.730000 I never get to sleep on the airplane because it's so uncomfortable
14.730000 17.792000 #

A single input file in automatic mode:

python .\sppas\bin\fillipus.py -I .\samples\samples-eng\oriana1
python .\sppas\bin\fillipus.py -I .\samples\samples-eng\oriana1.wav
python .\sppas\bin\fillipus.py -I .\samples\samples-eng\oriana1.txt

## 3.9 Text normalization

### 3.9.1 Overview

In principle, any system that deals with unrestricted text need the text to be normalized. Texts contain a variety of “non-standard” token types such as digit sequences, words, acronyms and letter sequences in all capitals, mixed case words, abbreviations, roman numerals, URL’s and e-mail addresses… Normalizing or rewriting such texts using ordinary words is then an important issue. The main steps of the text normalization implemented in SPPAS (Bigi 2011) are:

* Replace symbols by their written form, thanks to a “replacement” dictionary, located into the folder “repl” in the “resources” directory.

* Word segmentation based on the content of a lexicon.

* Convert numbers to their written form.

* Remove punctuation.

* Lower the text.

### 3.9.2 Adapt Text normalization

Word segmentation of SPPAS is mainly based on the use of a lexicon. If a segmentation is not as expected, it is up to the user to modify the lexicon: Lexicons of all supported languages are all located in the folder “vocab” of the “resources” directory. They are in the form of “one word at a line” with UTF-8 encoding and “LF” for newline.

### 3.9.3 Support of a new language

Adding a new language in Text Normalization consists in the following steps:

1. Create a lexicon. Fix properly its encoding (utf-8), its newlines (LF), and fix the name and extension of the file as follow:
* language name with iso639-3 standard

* extension ".vocab"

2. Put this lexicon in the `resources/vocab` folder

3. Create a replacement dictionary for that language (take a look on the ones of the other language!)

4. Optionally, the language can be added into the `num2letter.py` program

That's it for most of the languages! If the language requires more steps, simply write to the author to collaborate, find some funding, etc. like it was already done for Cantonese (Bigi & Fung 2015) for example.

### 3.9.4 Perform Text Normalization with the GUI

It is an annotation of STANDALONE type.

The SPPAS Text normalization system takes as input a file (or a list of files) for which the name strictly match the name of the audio file except the extension. For example, if a file with name "oriana1.wav" is given, SPPAS will search for a file with name "oriana1.xra" at a first stage if ".xra" is set as the default extension, then it will search for other supported extensions until a file is found.

This file must include a tier with an orthographic transcription. At a first stage, SPPAS tries to find a tier with `transcription` as name. If such a tier does not exist, the first tier that is matching one of the following strings is used (case-insensitive search):

1. trans

2. trs

3. ipu

4. ortho

5. toe

Text normalization produces a file with "-token" appended to its name, i.e. "oriana1-token.xra" for the previous example. By default, this file is including only one tier with the resulting normalization and with name "Tokens". To get other versions of the normalized transcription, click on the "Configure" text then check the expected tiers.

Read the "Introduction" of this chapter for a better understanding of the difference between "standard" and "faked" results.

To perform the text normalization process, click on the Text Normalization activation button, select the language and click on the "Configure..." blue text to fix options.

### 3.9.5 Perform Text Normalization with the CLI

`normalize.py` is the program to perform Text Normalization, i.e. the text normalization of a given file or a raw text.

#### Usage

```
normalize.py [files] [options]
```

```
Text Normalization: Text normalization segments the orthographic transcription
```
into tokens and remove punctuation, convert numbers, etc. Requires an
orthographic transcription into IPUs.

optional arguments:

<table>
   <tr>
    <td>
     -h, --help
    </td>
    <td>
     show this help message and exit
    </td>
   </tr>
   <tr>
    <td>
     --quiet
    </td>
    <td>
     Disable the verbosity
    </td>
   </tr>
   <tr>
    <td>
     --log file
    </td>
    <td>
     File name for a Procedure Outcome Report (default: None)
    </td>
   </tr>
  </table>

Files (manual mode):

<table>
   <tr>
    <td>
     -i file
    </td>
    <td>
     Input transcription file name.
    </td>
   </tr>
   <tr>
    <td>
     -o file
    </td>
    <td>
     Annotated file with normalized tokens.
    </td>
   </tr>
  </table>

Files (auto mode):

<table>
   <tr>
    <td>
     -I file
    </td>
    <td>
     Input transcription file name (append).
    </td>
   </tr>
   <tr>
    <td>
     -l lang
    </td>
    <td>
     Language code (iso8859-3). One of: cat cmn deu eng fra hun ita jpn kor nan pcm pol por spa vie yue yue_chars.
    </td>
   </tr>
   <tr>
    <td>
     -e .ext
    </td>
    <td>
     Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff
    </td>
   </tr>
  </table>

Resources:

<table>
  <tr>
    <td>-r vocab</td>
    <td>Vocabulary file name</td>
  </tr>
</table>

Options:

<table>
  <tr>
    <td>--inputpattern INPUTPATTERN</td>
    <td>Input file pattern (orthographic transcription)<br>(default: )</td>
  </tr>
  <tr>
    <td>--outputpattern OUTPUTPATTERN</td>
    <td>Output file pattern (default: -token)</td>
  </tr>
  <tr>
    <td>--faked FAKED</td>
    <td>Create a tier with the faked tokens (required for<br>phonetization) (default: True)</td>
  </tr>
  <tr>
    <td>--std STD</td>
    <td>Create a tier with the standard tokens (useful if EOT)<br>(default: False)</td>
  </tr>
  <tr>
    <td>--custom CUSTOM</td>
    <td>Create a customized tier (default: False)</td>
  </tr>
  <tr>
    <td>--occ_dur OCC_DUR</td>
    <td>Create tiers with number of tokens and duration of<br>each IPU (default: True)</td>
  </tr>
</table>

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

Examples of use

A single input file with a raw transcription input in manual mode:

python .\sppas\bin\normalize.py -r .\resources\vocab\eng.vocab -i .\samples\samples-eng\ordinary
2018-12-19 11:48:34,151 [INFO] Logging set up level=15
2018-12-19 11:48:34,473 [INFO] ... Intervalle numéro 1.
2018-12-19 11:48:34,477 [INFO] ... Intervalle numéro 2.
2018-12-19 11:48:34,480 [INFO] ... Intervalle numéro 3.
Tokens
1, the flight was twelve hours long and we really got bored
2, they only played two movies + which we had both already seen
3, i never get to sleep on the airplane because it's so uncomfortable
A single input file with a transcription time-aligned into the IPUS, in manual mode and no logs:

<figure><img src="image_5.png" /></figure>

The same file in automatic mode can be annotated with one of the following commands:

<figure><img src="image_6.png" /></figure>

This program can also normalize data from the standard input. Example of use, using stdin/stdout under Windows:

<figure><img src="image_7.png" /></figure>

In that case, the comment mentioned with the braces is removed and the number is converted to its written form. The character "_" is used for compound words (it replaces the whitespace).

## 3.10 Phonetization

### 3.10.1 Overview

Phonetization, also called grapheme-phoneme conversion, is the process of representing sounds with phonetic signs. However, converting from written text into actual sounds, for any language, cause several problems that have their origins in the relative lack of correspondence between the spelling of the lexical items and their sound contents. As a consequence, SPPAS implements a dictionary based-solution which consists in storing a maximum of phonological knowledge in a lexicon. This approach is then language-independent. SPPAS phonetization process is the equivalent of a sequence of dictionary look-ups.

Most of the other systems assume that all words of the speech transcription are mentioned in the pronunciation dictionary. On the contrary, SPPAS includes a language-independent algorithm which is able to phonetize unknown words of any language as long as a (minimum) dictionary is available (Bigi 2013). The Procedure Outcome Report reports on such cases with a WARNING message.
### 3.10.2 Adapt Phonetization

Since Phonetization is only based on the use of a pronunciation dictionary, the quality of the result only depends on this resource. If a pronunciation is not as expected, it is up to the user to change it in the dictionary: Dictionaries are located in the folder “dict” of the “resources” directory. They are all with UTF-8 encoding and “LF” for newline. The format of the dictionaries is HTK-like. As example, below is a piece of the eng.dict file:

<table><tr><td>THE</td><td>[THE]</td><td>D @</td></tr><tr><td>THE (2)</td><td>[THE]</td><td>D V</td></tr><tr><td>THE (3)</td><td>[THE]</td><td>D i:</td></tr><tr><td>THEA</td><td>[THEA]</td><td>T i: @</td></tr><tr><td>THEALL</td><td>[THEALL]</td><td>T i: 1</td></tr><tr><td>THEANO</td><td>[THEANO]</td><td>T i: n @U</td></tr><tr><td>THEATER</td><td>[THEATER]</td><td>T i: @ 4 3:r</td></tr><tr><td>THEATER'S</td><td>[THEATER'S]</td><td>T i: @ 4 3:r z</td></tr></table>

The first column indicates the word, followed by the variant number (except for the first one). The second column indicates the word between brackets. The last columns are the succession of phones, separated by a whitespace. SPPAS is relatively compliant with the format and accept empty brackets or missing brackets.

The phoneset of the languages are mainly based on X-SAMPA international standard. See the chapter “Resources” of this documentation to know the list of accepted phones for a given language. This list can’t be extended nor modified by users. However, new phones can be added: Send an e-mail to the author to collaborate in that way.

Actually, some words can correspond to several entries in the dictionary with various pronunciations. These pronunciation variants are stored in the phonetization result. By convention, whitespace separate words, minus characters separate phones and pipe character separate phonetic variants of a word. For example, the transcription utterance:

* Transcription: The flight was 12 hours long.

* Text Normalization: the flight was twelve hours long

* Phonetization: D-@|D-V|D-i: f-l-aI-t w-A-z|w-V-z|w-@-z|w-O:-z t-w-E-l-v
aU-3:r-z|aU-r-z 1-O:-N

### 3.10.3 Support of a new language

The support of a new language in Phonetization only consists in: 1. creating the pronunciation dictionary. The following constraints on the file must be respected: - its format (HTK-like), - its encoding (UTF-8), - its newlines (LF), - its phone set (X-SAMPA), - its file name (iso639-3 of the language and “.dict” extension). 2. adding the dictionary in the “dict” folder of the “resources” directory.

### 3.10.4 Perform Phonetization with the GUI

It is an annotation of STANDALONE type.

The Phonetization process takes as input a file that strictly match the audio file name except for the extension and that “-token” is appended. For example, if the audio file name is “oriana1.wav”, the expected input file name is “oriana1-token.xra” if .xra is the default extension for annotations. This file must include a **normalized** orthographic transcription. The name of such tier must contains one of the following strings:
1. "tok"

2. "trans"

The first tier that matches one of these requirements is used (this match is case-insensitive).

Phonetization produces a file with "-phon" appended to its name, i.e. "oriana1-phon.xra" for the previous example. This file contains only one tier with the resulting phonetization and with name "Phones".

To perform the annotation, click on the Phonetization activation button, select the language and click on the "Configure..." blue text to fix options.

### 3.10.5 Perform Phonetization with the CLI

`phonetize.py` is the program to perform Phonetization on a given file, i.e. the grapheme-conversion of a file or a raw text.

#### Usage

```
phonetize.py [files] [options]
```

Phonetization: Grapheme to phoneme conversion represents sounds with phonetic signs. Requires a Text Normalization.

**optional arguments:**

<table><tr><td>-h, --help</td><td>show this help message and exit</td></tr><tr><td>--quiet</td><td>Disable the verbosity</td></tr><tr><td>--log file</td><td>File name for a Procedure Outcome Report (default: None)</td></tr></table>

**Files (manual mode):**

<table><tr><td>-i file</td><td>Input tokenization file name.</td></tr><tr><td>-o file</td><td>Annotated file with phonetization.</td></tr></table>

**Files (auto mode):**

<table><tr><td>-I file</td><td>Input transcription file name (append).</td></tr><tr><td>-l lang</td><td>Language code (iso8859-3). One of: cat cmn deu eng fra ita jpn kor nan pcm pol por spa yue yue_chars.</td></tr><tr><td>-e .ext</td><td>Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff</td></tr></table>

**Resources:**

<table><tr><td>-r dict</td><td>Pronunciation dictionary (HTK-ASCII format).</td></tr><tr><td>-m map_file</td><td>Pronunciation mapping table. It is used to generate new pronunciations by mapping phonemes of the dictionary.</td></tr></table>

**Options:**

<table><tr><td>--inputpattern INPUTPATTERN</td><td>Input file pattern (tokenization) (default: -token)</td></tr><tr><td>--outputpattern OUTPUTPATTERN</td><td>Output file pattern (default: -phon)</td></tr><tr><td>--unk UNK</td><td>Try to phonetize unknown words (default: True)</td></tr><tr><td>--usedtokens USESTDTokens</td><td>Phonetize from standard spelling (default: False)</td></tr></table>
This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

## Examples of use

A single input file with a normalized text in manual mode:

```
python .\sppas\bin\phonetize.py -r .\resources\dict\eng.dict -i .\samples\samples-eng\oriana1-token.xra --quiet

Phones
0.000000, 1.675000, sil
1.675000, 4.570000, {D-@|D-i:|D-V} f-l-aI-t {w-@-z|w-V-z|w-O:-z|w-A-z} t-w-E-l-v
{aU-3:r-z|aU-r\-z} l-O:-N {{-n-d|@-n-d} w-i: {r\-I-l-i:|r\-i:-l-i:} g-A-t b-O:-r\-d
4.570000, 6.390000, sil
6.390000, 9.870000, D-eI @U-n-l-i: p-l-eI-d t-u m-u-v-i:-z sil {h-w-I-tS|w-I-tS}
w-i: h-{-d b-@U-T {O:-l-r\-E-4-i:|O:-r\-E-4-i:} s-i:-n
9.870000, 11.430000, sil
11.430000, 14.730000, aI n-E-v-3:r {g-I-t|g-E-t} {t-@|t-i|t-u} s-l-i:-p
{O:-n|A-n} {D-@|D-i:|D-V} E-r\-p-l-eI-n {b-i-k-O:-z|b-i-k-V-z} {i-t-s|I-t-s}
s-@U @-n-k-V-m-f-3:r-4-@-b-@-1
14.730000, 17.792000, sil
```

The same file in automatic mode can be annotated with one of the following commands:

```
python .\sppas\bin\phonetize.py -l eng -I .\samples\samples-eng\oriana1-token.xra
python .\sppas\bin\phonetize.py -l eng -I .\samples\samples-eng\oriana1.xra
python .\sppas\bin\phonetize.py -l eng -I .\samples\samples-eng\oriana1.txt
python .\sppas\bin\phonetize.py -l eng -I .\samples\samples-eng\oriana1.wav
python .\sppas\bin\phonetize.py -l eng -I .\samples\samples-eng\oriana1
```

This program can also phonetize data from the standard input. Example of use, using stdin/stdout under Windows:

```
Write-Output "The flight was 12 HOURS {toto} long." |
python .\sppas\bin\normalize.py -r .\resources\vocab\eng.vocab --quiet |
python .\sppas\bin\phonetize.py -r .\resources\dict\eng.dict --quiet
D-@|D-V|D-i:
f-l-aI-t
w-A-z|w-V-z|w-@-z|w-O:-z
t-w-E-l-v
aU-3:r-z|aU-r\-z
l-O:-N
```

## 3.11 Alignment
### 3.11.1 Overview

Alignment, also called phonetic segmentation, is the process of aligning speech with its corresponding transcription at the phone level. The alignment problem consists in a time-matching between a given speech unit along with a phonetic representation of the unit.

**SPPAS Alignment does not perform the segmentation itself. It is a wrapper either for the Julius Speech Recognition Engine (SRE) or for the HVite command of HTK-Toolkit.** In addition, SPPAS can perform a “basic” alignment, assigning the same duration to each sound.

Speech Alignment requires an Acoustic Model in order to align speech. An acoustic model is a file that contains statistical representations of each of the distinct sounds of one language. Each sound is represented by one of these statistical representations. The quality of the alignment result only depends on both this resource and on the aligner. From our past experiences, we got better results with Julius. See the chapter 4 “Resources for Automatic Annotations” to get the list of sounds of each language.

Notice that SPPAS allows to time-align automatically laugh, noises, or filled pauses (depending on the language): No other system is able to achieve this task!

SPPAS alignment output example

### 3.11.2 Adapt Alignment

The better Acoustic Model, the better alignment results. Any user can append or replace the acoustic models included in the “models” folder of the “resources” directory. Be aware that SPPAS only supports HTK-ASCII acoustic models, trained from 16 bits, 16000 Hz wave files.

The existing models can be improved if they are re-trained with more data. To get a better alignment result, any new data is then welcome: send an e-mail to the author to share your recordings and transcripts.

### 3.11.3 Support of a new language

The support of a new language in Alignment only consists in adding a new acoustic model of the appropriate format, in the appropriate directory, with the appropriate phone set.

The articulatory representations of phonemes are so similar across languages that phonemes can be considered as units which are independent from the underlying language (Schultz et al. 2001). In SPPAS package, 9 acoustic models of the same type - i.e. same HMMs definition and acoustic parameters, are already available so that the phoneme prototypes can be extracted and reused to create an initial model for a new language.

Any new model can also be trained by the author, as soon as enough data is available. It is difficult to estimate exactly the amount of data a given language requires. That is said, we can approximate the minimum as follows:

* 3 minutes altogether of various speakers, manually time-aligned at the phoneme level.

* 10 minutes altogether of various speakers, time-aligned at the ipus level with the enriched orthographic transcription.

* more data is good data.
### 3.11.4 Perform Alignment with the GUI

It is an annotation of STANDALONE type.

The Alignment process takes as input one or two files that strictly match the audio file name except for the extension and that “-phon” is appended for the first one and “-token” for the optional second one. For example, if the audio file name is “oriana1.wav”, the expected input file name is “oriana1-phon.xra” with phonetization and optionally “oriana1-token.xra” with text normalization, if .xra is the default extension for annotations.

The speech segmentation process provides one file with name “-palign” appended to its name, i.e. “oriana1-palign.xra” for the previous example. This file includes one or two tiers:

* “PhonAlign” is the segmentation at the phone level;

* “TokensAlign” is the segmentation at the word level (if a file with tokenization was found).

The following options are available to configure Alignment:

* choose the speech segmentation system. It can be either: julius, hvite or basic

* perform basic alignment if the aligner failed, instead such intervals are empty.

* remove working directory will keep only alignment result: it will remove working files. Working directory includes one wav file per unit and a set of text files per unit.

* create the PhnTokAlign will append another tier with intervals of the phonetization of each word.

To perform the annotation, click on the Alignment activation button, select the language and click on the “Configure…” blue text to fix options.

### 3.11.5 Perform Alignment with the CLI

alignment.py is the program to perform automatic speech segmentation of a given phonetized file.

#### Usage

```
alignment.py [files] [options]
```

Alignment: Time-alignment of speech audio with its corresponding transcription at the phone and token levels. Requires a Phonetization.

**optional arguments:**

-h, --help show this help message and exit

-q, --quiet Disable the verbosity

-l, --log file File name for a Procedure Outcome Report (default: None)

**Files (manual mode):**

-i, --input wav file name.

-p, --phone file name with the phonetization.

-t, --token file name with the tokenization.

-o, --output file name with estimated alignments.

**Files (auto mode):**

-I, --input transcription file name (append).

-l, --lang Language code (iso8859-3). One of: cat cmn deu eng
-e .ext

eng-cd fra ita jpn kor nan pcm pol por spa yue.
Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

Resources:

-r model

Directory of the acoustic model of the language of the text

-R model

Directory of the acoustic model of the mother language of the speaker (under development)

Options:

--inputpattern INPUTPATTERN
Input file pattern (phonetization) (default: -phon)

--inputoptpattern INPUTOPTPATTERN
Optional input file pattern (tokenization) (default: -token)

--outputpattern OUTPUTPATTERN
Output file pattern (default: -palign)

--aligner ALIGNER
Speech automatic aligner system (julius, hvite, basic): (default: julius)

--basic BASIC
Perform basic alignment if the aligner fails (default: False)

--clean CLEAN
Remove working directory (default: True)

--activity ACTIVITY
Create the Activity tier (default: True)

--activityduration ACTIVITYDURATION
Create the ActivityDuration tier (default: False)

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

Example of use

python .\sppas\bin\alignment.py -I .\samples\samples-eng\oriana1.wav -l eng
2018-12-19 18:33:38,842 [INFO] Logging set up level=15
2018-12-19 18:33:38,844 [INFO] Options
2018-12-19 18:33:38,844 [INFO] ... activityduration: False
2018-12-19 18:33:38,845 [INFO] ... activity: True
2018-12-19 18:33:38,845 [INFO] ... aligner: julius
2018-12-19 18:33:38,845 [INFO] ... clean: True
2018-12-19 18:33:38,845 [INFO] ... basic: False
2018-12-19 18:33:38,845 [INFO] File oriana1.wav: Valid.
2018-12-19 18:33:38,845 [INFO] File oriana1-phon.xra: Valid.
2018-12-19 18:33:38,846 [INFO] File oriana1-token.xra: Valid.
2018-12-19 18:33:38,846 [WARNING] ... ... A file with name E:\bigi\Projets\sppas\sampled
2018-12-19 18:33:38,855 [INFO] ... Découpage en intervalles.
2018-12-19 18:33:38,901 [INFO] ... Intervalle numéro 1.
2018-12-19 18:33:38,904 [INFO] ... Intervalle numéro 2.
2018-12-19 18:33:38,908 [INFO] ... Intervalle numéro 3.
2018-12-19 18:33:38,913 [INFO] ... Intervalle numéro 4.
2018-12-19 18:33:38,917 [INFO] ... Intervalle numéro 5.
2018-12-19 18:33:38,921 [INFO] ... Intervalle numéro 6.
2018-12-19 18:33:38,926 [INFO] ... Intervalle numéro 7.
2018-12-19 18:33:38,928 [INFO] ... Fusion des alignements des intervalles.
2018-12-19 18:33:38,969 [INFO] ... Création de la tier des activités.
2018-12-19 18:33:38,993 [INFO] ... E:\bigi\Projets\sppas\samples\samples-eng\oriana1-pali

## 3.12 Activity

### 3.12.1 Overview

Activity tier represents speech activities, i.e. speech, silences, laughter, noises... It is based on the analysis of the time-aligned tokens.

### 3.12.2 Perform Activity with the GUI

It is an annotation of STANDALONE type.

The Activity process takes as input a file that strictly match the audio file name except for the extension and that "-palign" is appended. For example, if the audio file name is "oriana1.wav", the expected input file name is "oriana1-palign.xra" if .xra is the default extension for annotations. This file must include time-aligned phonemes in a tier with name "PhonAlign".

The annotation provides an annotated file with "-activity" appended to its name, i.e. "oriana1-activity.xra" for the previous example. This file is including 1 or 2 tiers: Activity, ActivityDuration.

To perform the annotation, click on the Activity activation button and click on the "Configure..." blue text to fix options.

### 3.12.3 Perform Alignment with the CLI

No CLI is available for this annotation.

## 3.13 RMS

### 3.13.1 Overview

The Root-Mean Square - RMS is a measure of the power in an audio signal. It is estimated from the amplitude values by: sqrt(sum(S_i^2)/n).

RMS automatic annotation estimates the rms value on given intervals of an audio file. Empty intervals - i.e. intervals without labels, are ignored. By default, the RMS is estimated on a tier with name "PhonAlign" of an annotated file with pattern "-palign". Both can be modified by configuring the annotations. The annotation provides an annotated file with "-rms" appended to its name. This file is including 3 tiers:

* RMS: indicates the RMS value estimated on each non-empty interval;

* RMS-values: indicates RMS values estimated every 10 ms in each interval;

* RMS-mean: indicates the mean of the previous values.
### 3.13.2 Perform RMS with the GUI

It is an annotation of STANDALONE type.

To perform the annotation, click on the RMS activation button and click on the “Configure…” blue text to fix options.

### 3.13.3 Perform RMS with the CLI

`rms.py` is the program to perform this annotation, either on a single given file (`-i` and `-t`) or on a set of files (`-I`).

## 3.14 Interval Values Analysis - IVA

### 3.14.1 Overview

The Interval Values Analysis - IVA is producing statistical information about a set of values in given intervals. IVA can for example estimate the mean/stddev values on given intervals (IPUs, ...) of a pitch file. Empty intervals - i.e. unlabelled intervals, are ignored and a list of tags to be ignored can be fixed.

By default, the IVA is estimated with the values of a PitchTier inside the intervals defined in a tier with name “TokensAlign” of a file with pattern “-palign”. If a list of separators is given, the intervals are created: an IVA segment is a set of consecutive annotations without separators. Default separators are “# + @ * dummy” in order to ignore silences, laughter items, noises and untranscribed speech. However, if no separator is given, IVA segments are matching the intervals of the given input tier. In the latter case, be aware that some file formats - including TextGrid, are not supporting holes: they create unlabelled intervals between the labelled ones.

Both tiernames and patterns can be modified by configuring the annotation. The annotation provides an annotated file with the “-iva” pattern. This file includes the tiers:

* IVA-Segments: defined intervals;

* IVA-Values: the values extracted for each segment;

* IVA-Occurrences: indicates the number of values of each segment;

* IVA-Total: indicates the sum of values of each segment;

* IVA-Mean: indicates the mean of values of each segment;

* IVA-Median: indicates the median of values of each segment;

* IVA-StdDev: indicates the standard deviation of values of each segment;

* IVA-Intercept: indicates the intercept value of the linear regression of values of each segment;

* IVA-Slope: indicates the slope value of the linear regression of values of each segment.

### 3.14.2 Perform IVA with the GUI

It is an annotation of STANDALONE type.

To perform the annotation, click on the IVA activation button and click on the “Configure…” blue text to fix options.
### 3.14.3 Perform IVA with the CLI

`iva.py` is the program to perform this annotation, either on a single given file (`-i` and `-s`) or on a set of files (`-I`).

## 3.15 Lexical Metric

### 3.15.1 Overview

The Lexical Metric is producing information about the number of occurrences and the rank of each occurrences of annotation labels.

By default, the lexical metrics are estimated on a tier with name "TokensAlign" of a file with pattern "-palign". If a list of separators is given, segments are created to estimate a number of occurrences. Default separators are "`#` + `@` * dummy" in order to ignore silences, laughter items, noises and untranscribed speech.

Both the tiername and the pattern can be modified by configuring the annotation. The annotation provides an annotated file with the "-lexm" pattern. This file includes the tiers:

* LM-OccAnnInSegments: defined intervals with number of occurrences of annotations;

* LM-OccLabInSegments: defined intervals with number of occurrences of labels;

* LM-Occ: the number of occurrences of each label the annotation is representing;

* LM-Rank: the rank of each label the annotation is representing.

### 3.15.2 Perform Lexical Metric with the GUI

It is an annotation of STANDALONE type.

To perform the annotation, click on the Lexical Metric activation button and click on the "Configure..." blue text to fix options.

## 3.16 Syllabification

### 3.16.1 Overview

The syllabification of phonemes is performed with a rule-based system from time-aligned phonemes. This phoneme-to-syllable segmentation system is based on 2 main principles:

* a syllable contains a vowel, and only one;

* a pause is a syllable boundary.

These two principles focus the problem of the task of finding a syllabic boundary between two vowels. Phonemes were grouped into classes and rules are established to deal with these classes.

Syllabification example

For each language, the automatic syllabification requires a configuration file to fix phonemes, classes and rules.
### 3.16.2 Adapt Syllabification

Any user can change the set of rules by editing and modifying the configuration file of a given language. Such files are located in the folder "syll" of the "resources" directory. Files are all with UTF-8 encoding and "LF" for newline.

At first, the list of phonemes and the class symbol associated with each of the phonemes are described as, for example:

* PHONCLASS e V

* PHONCLASS p P

Each association phoneme/class definition is made of 3 columns: the first one is the key-word PHONCLASS, the second is the phoneme symbol (like defined in the tier with the phonemes, commonly X-SAMPA), the last column is the class symbol. The constraints on this definition are that a class-symbol is only one upper-case character, and that the character X if forbidden, and the characters V and W are reserved for vowels.

The second part of the configuration file contains the rules. The first column is a keyword, the second one describes the classes between two vowels and the third column is the boundary location. The first column can be:

* GENRULE

* EXCRULE

* OTHRULE.

In the third column, a "0" means the boundary is just after the first vowel, "1" means the boundary is one phoneme after the first vowel, etc. Here are some examples of the file for French language:

* GENRULE VXV 0

* GENRULE VXXV 1

* EXCRULE VFLV 0

* EXCRULE VOLGV 0

Finally, to adapt the rules to specific situations that the rules failed to model, we introduced some phoneme sequences and the boundary definition. Specific rules contain only phonemes or the symbol "ANY" which means any phoneme. It consists of 7 columns: the first one is the key-word OTHRULE, the 5 following columns are a phoneme sequence where the boundary should be applied to the third one by the rules, the last column is the shift to apply to this boundary. In the following example:

OTHRULE ANY ANY p s k -2

More information are available in (Bigi et al. 2010).

### 3.16.3 Support of a new language

The support of a new language in this automatic syllabification only consists in adding a configuration file (see previous section). Fix properly the encoding (utf-8) and newlines (LF) of this file; then fix the name and extension of the file as follow:

* "syllConfig-" followed by language name with iso639-3 standard,

* with extension ".txt".
### 3.16.4 Perform Syllabification with the GUI

It is an annotation of STANDALONE type.

The Syllabification process takes as input a file that strictly match the audio file name except for the extension and that "-palign" is appended. For example, if the audio file name is "oriana1.wav", the expected input file name is "oriana1-palign.xra" if .xra is the default extension for annotations. This file must include time-aligned phonemes in a tier with name "PhonAlign".

The annotation provides an annotated file with "-salign" appended to its name, i.e. "oriana1-salign.xra" for the previous example. This file is including 2 tiers: SyllAlign, SyllClassAlign. Optionally, the program can add a tier with the syllable structures (V, CV, CCV...).

To perform the annotation, click on the Syllabification activation button, select the language and click on the "Configure..." blue text to fix options.

### 3.16.5 Perform Syllabification with the CLI

`syllabify.py` is the program to perform automatic syllabification of a given file with time-aligned phones.

#### Usage

```
syllabify.py [files] [options]
```

Syllabification: Syllabification is based on a set of rules to convert
phonemes into classes and to group them. Requires time-aligned phones.

**optional arguments:**

-h, --help show this help message and exit

- quiet Disable the verbosity

-log file File name for a Procedure Outcome Report (default: None)

**Files (manual mode):**

-i file Input time-aligned phonemes file name.

-o file Output file name with syllables.

**Files (auto mode):**

-I file Input transcription file name (append).

-l lang Language code (iso8859-3). One of: fra ita pol.

-e .ext Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

**Resources:**

-r rules Configuration file with syllabification rules

**Options:**

-inputpattern INPUTPATTERN
  Input file pattern (time-aligned phonemes) (default: -palign)

-outputpattern OUTPUTPATTERN
  Output file pattern (default: -syll)

-usesphons USESPHONS
  Syllabify inside the IPU intervals (default: True)
```
--usesintervals USESINTERVALS
    Syllabify inside an interval tier (default: False)
```

```
--tiename TIERNAME
    Tier name for such interval tier: (default:
        TokensAlign)
```

```
--createclasses CREATECLASSES
    Create a tier with syllable classes (default: True)
```

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

## Examples of use

```
python .\sppas\bin\syllabify.py -i .\samples\samples-fra\F_F_B003-P8-palign.xra -r .\resources\syll\syllConfig-fra.txt --quiet

SyllAlign
2.497101 2.717101 j-E-R
2.717101 2.997101 s-w-A/-R
...
19.412000 19.692000 P-L-V-P
19.692000 20.010000 P-V-L-P
```

All the following commands will produce the same result:

```
python .\sppas\bin\syllabify.py -I .\samples\samples-fra\F_F_B003-P8-palign.xra -l fra
python .\sppas\bin\syllabify.py -I .\samples\samples-fra\F_F_B003-P8.TextGrid -l fra
python .\sppas\bin\syllabify.py -I .\samples\samples-fra\F_F_B003-P8.wav -l fra
python .\sppas\bin\syllabify.py -I .\samples\samples-fra\F_F_B003-P8 -l fra
```

# 3.17 TGA - Time Groups Analyzer

## 3.17.1 Overview

TGA is originally available at http://wwwhomes.uni-bielefeld.de/gibbon/TGA/. It's a tool developed by Dafydd Gibbon, emeritus professor of English and General Linguistics at Bielefeld University.

Dafydd Gibbon (2013). **TGA: a web tool for Time Group Analysis**, Tools and Resources for the Analysis of Speech Prosody, Aix-en-Provence, France, pp. 66-69.

The original TGA is an online batch processing tool which provides a parametrised mapping from time-stamps in speech annotation files in various formats to a detailed analysis report with statistics and visualisations. TGA software calculates, inter alia, mean, median, rPVI, nPVI, slope and intercept functions within inter-pausal groups, provides visualizations of timing patterns, as well as correlations between these, and parses inter-pausal groups into hierarchies based on duration relations. Linear regression is selected mainly for the slope function, as a first approximation to examining acceleration and deceleration over large data sets.
*The TGA online tool was designed to support phoneticians in basic statistical analysis of annotated speech data.* In practice, the tool provides not only rapid analyses but also the ability to handle larger data sets than can be handled manually.

In addition to the original one, a second version of TGA was implemented in the AnnotationPro software:

Katarzyna Klessa, Dafydd Gibbon (2014). **Annotation Pro + TGA: automation of speech timing analysis**, 9th International conference on Language Resources and Evaluation (LREC), Reykjavik (Iceland). pp. 1499-1505, ISBN: 978-2-9517408-8-4.

The integrated Annotation Pro + TGA tool incorporates some TGA features and is intended to support the development of more robust and versatile timing models for a greater variety of data. The integration of TGA statistical and visualisation functions into Annotation Pro+TGA results in a powerful computational enhancement of the existing AnnotationPro phonetic workbench, for supporting experimental analysis and modeling of speech timing.

So, what's the novelty into the third version implemented into SPPAS...

First of all, it has to be noticed that TGA is only partly implemented into SPPAS. The statistics analyses tool of SPPAS allows to estimate TGA within the SPPAS framework; and it results in the following advantages:

* it can read either TextGrid, csv, Elan, or any other file format supported by SPPAS,

* it can save TGA results in any of the annotation file supported by SPPAS,

* it estimates the two versions of the linear regression estimators: the original one and the one implemented into AnnotationPro:

1. in the original TGA, the x-axis is based on positions of syllables,

2. in the AnnotationPro+TGA, the x-axis is based on time-stamps.

### 3.17.2 Result of TGA into SPPAS

The annotation provides an annotated file with "-tga" appended to its name, i.e. "oriana1-tga.xra" for the example. This file is including 10 tiers:

1. TGA-TimeGroups: intervals with the time groups

2. TGA-TimeSegments: same intervals, indicate the syllables separated by whitespace

3. TGA-Occurrences: same intervals, indicate the number of syllables

4. TGA-Total: same intervals, indicate interval duration

5. TGA-Mean: same intervals, indicate mean duration of syllables

6. TGA-Median: same intervals, indicate median duration of syllables

7. TGA-Stdev: same intervals, indicate stdev of duration of syllables

8. TGA-nPVI: same intervals, indicate nPVI of syllables

9. TGA-Intercept: same intervals, indicate the intercept

10. TGA-Slope: same intervals, indicate the slope

Both tiers 9 and 10 can be estimated in 2 ways (so 2 more tiers can be generated).
### 3.17.3 Perform TAG with the GUI

It is an annotation of STANDALONE type.

The TGA process takes as input a file that strictly match the audio file name except for the extension and that "-align" is appended. For example, if the audio file name is "oriana1.wav", the expected input file name is "oriana1-salign.xra" if .xra is the default extension for annotations. This file must include time-aligned syllables in a tier with name "SyllAlign".

To perform the annotation, click on the TGA activation button and click on the "Configure..." blue text to fix options.

### 3.17.4 Perform TGA with the CLI

`tga.py` is the program to perform TGA of a given file with time-aligned syllables.

#### Usage

```
tga.py [files] [options]
```

TimeGroupAnalysis: Proposed by D. Gibbon, Time Group Analyzer calculates mean, median, nPVI, slope and intercept functions within inter-pausal groups.
Requires time aligned syllables.

**optional arguments:**

-h, --help show this help message and exit

- quiet Disable the verbosity

-log file File name for a Procedure Outcome Report (default: None)

**Files (manual mode):**

-i file An input time-aligned syllables file.

-o file Output file name with TGA.

**Files (auto mode):**

-I file Input time-aligned syllables file (append).

-e .ext Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

**Options:**

-original ORIGINAL Use the original estimation of intercept and slope (default: False)

-annotationpro ANNOTATIONPRO
Use the estimation of intercept and slope proposed in AnnotationPro (default: True)

-tg_prefix_label TG_PREFIXLABEL
Prefix of each time group label: (default: tg_)

-with radius WITHRadius
Duration estimation: Use 0 to estimate syllable durations with midpoint values, use -1 for Radius-, or 1 for Radius+. (default: 0)

This program is part of SPPAS version 2.0. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org
### Example of use

```
python .\sppas\bin\tga.py -i .\samples\samples-fra\F_F_B003-P8-syll.xra
2018-12-20 08:35:21,219 [INFO] Logging set up level=15
TGA-TimeGroups
2.497101 5.683888 tg_1
5.743603 8.460596 tg_2
9.145000 11.948531 tg_3
12.494000 13.704000 tg_4
13.784000 15.036000 tg_5
16.602000 20.010000 tg_6
TGA-TimeSegments
...
13.784000 15.036000 -0.03063
16.602000 20.010000 0.00468
```

### Other commands:

```
python .\sppas\bin\tga.py -I .\samples\samples-fra\F_F_B003-P8-syll.xra
python .\sppas\bin\tga.py -I .\samples\samples-fra\F_F_B003-P8.TextGrid
python .\sppas\bin\tga.py -I .\samples\samples-fra\F_F_B003-P8.wav
```

## 3.18 Stop words

Create a tier with True/False indicating if a token is a stop-word or not.

## 3.19 Self-Repetitions

### 3.19.1 Overview

This automatic detection focus on word self-repetitions which can be exact repetitions (named strict echos) or repetitions with variations (named non-strict echos). The system is based only on lexical criteria. The algorithm is focusing on the detection of the source.

This system can use a list of stop-words of a given language. This is a list of very frequent words like adjectives, pronouns, etc. Obviously, the result of the automatic detection is significantly better if such list of stop-words is available.

Optionnally, SPPAS can add new stop-words in the list: they are deduced from the given data. These new entries in the stop-list are then different for each file (Bigi et al. 2014).

The annotation provides one annotated file with 2 to 4 tiers:

1. TokenStrain: if a replacement file was available, it's the entry used by the system

2. StopWord: if a stop-list was used, it indicates if the token is a stop-word (True or False)

3. SR-Sources: tags of the annotations are prefixed by "S" followed an index

4. SR-Repetitions: tags of the annotations are prefixed by "R" followed an index
### 3.19.2 Adapt to a new language

The list of stop-words of a given language must be located in the "vocab" folder of the "resources" directory with ".stp" extension. This file is with UTF-8 encoding and "LF" for newline.

### 3.19.3 Perform Self-Repetitions with the GUI

It is an annotation of STANDALONE type.

The automatic annotation takes as input a file with (at least) one tier containing the time-aligned tokens. The annotation provides one annotated file with 2 tiers: Sources and Repetitions.

Click on the Self-Repetitions activation button, select the language and click on the "Configure..." blue text to fix options.

### 3.19.4 Perform SelfRepetitions with the CLI

`selfrepetition.py` is the program to perform automatic detection of self-repetitions.

#### Usage

```
selfrepetition.py [files] [options]
```

Self-repetitions: Self-repetitions searches for sources and echos of a speaker. Requires time-aligned tokens.

optional arguments:

<table><tr><td>-h, --help</td><td>show this help message and exit</td></tr><tr><td>--quiet</td><td>Disable the verbosity</td></tr><tr><td>--log file</td><td>File name for a Procedure Outcome Report (default: None)</td></tr></table>

Files (manual mode):

<table><tr><td>-i file</td><td>Input time-aligned tokens file name.</td></tr><tr><td>-o file</td><td>Output file name with syllables.</td></tr></table>

Files (auto mode):

<table><tr><td>-I file</td><td>Input transcription file name (append).</td></tr><tr><td>-e .ext</td><td>Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff</td></tr></table>

Resources:

<table><tr><td>-r file</td><td>List of stop-words</td></tr></table>

Options:

<table><tr><td>--inputpattern INPUTPATTERN</td><td>Input file pattern (time-aligned words or lemmas)<br>(default: -palign)</td></tr><tr><td>--outputpattern OUTPUTPATTERN</td><td>Output file pattern (default: -srepet)</td></tr><tr><td>--span SPAN</td><td>Span window length in number of IPUs (default: 3)</td></tr><tr><td>--stopwords STOPWORDS</td><td>Add stop-words estimated from the given data (default:</td></tr></table>
<table><tr><td>--alpha ALPHA</td><td>True)<br/>Coefficient to add data-specific stop-words (default:<br/>0.5)</td></tr></table>

This program is part of SPPAS version 3.0. Copyright (C) 2011-2020 Brigitte Bigi. Contact the author at: contact@sppas.org

## Examples of use

```
python .\sppas\bin\selfrepetition.py -i .\samples\samples-fra\F_F_B003-P8-palign.xra -r .\resources\vocab\fra.stp
python .\sppas\bin\selfrepetition.py -I .\samples\samples-fra\F_F_B003-P8.wav -l fra
```

## 3.20 Other-Repetitions

### 3.20.1 Overview

This automatic detection focus on other-repetitions, which can be either exact repetitions (named strict echos) or repetitions with variations (named non-strict echos). The system is based only on lexical criteria (Bigi et al. 2014). Notice that the algorithm is focusing on the detection of the source.

This system can use a list of stop-words of a given language. This is a list of very frequent words like adjectives, pronouns, etc. Obviously, the result of the automatic detection is significantly better if such list of stop-words is available.

Optionnaly, SPPAS can add new stop-words in the list: they are deduced from the given data. These new entries in the stop-list are then different for each file (see Bigi et al. 2014).

The detection of the ORs is performed in a span window of N IPUs; by default, N is fixed to 5. It means that if a repetition is after these N IPUs, it won't be detected. Technically, it also means that SPPAS needs to identify the boundaries of the IPUs from the time-aligned tokens: the tier must indicate the silences with the '#' symbol.

A file with the following tiers will be created:

* OR-Source: intervals with the number of the sources

* OR-SrcStrain: intervals with the tokens of the sources

* OR-SrcLen: intervals with the number of tokens in the source

* OR-SrcType: intervals with the type of the echos of the sources

* OR-Echo: intervals with the number of the echos

### 3.20.2 Adapt to a language and support of a new one

This system can use a list of stop-words of a given language. This is a list of very frequent words like adjectives, pronouns, etc. Obviously, the result of the automatic detection is significantly better if such list of stop-words is available. It must be located in the "vocab" folder of the "resources" directory with ".stp" extension. This file is with UTF-8 encoding and "LF" for newline.
### 3.20.3 Perform Other-Repetitions with the GUI

It is an annotation of INTERACTION type.

The automatic annotation takes as input a file with (at least) one tier containing the time-aligned tokens of the main speaker, and another file/tier with tokens of the interlocutor. The annotation provides one annotated file with 2 tiers: Sources and Repetitions.

Click on the Other-Repetitions activation button, select the language and click on the “Configure…” blue text to fix options.

### 3.20.4 Perform Other-Repetitions with the CLI

```
usage: otherrepetition.py -r stopwords [files] [options]
```

#### Files:

<table><tr><td>-i file</td><td>Input file name with time-aligned tokens of the main speaker.</td></tr><tr><td>-s file</td><td>Input file name with time-aligned tokens of the echoing speaker</td></tr><tr><td>-o file</td><td>Output file name with ORs.</td></tr></table>

#### Options:

<table><tr><td>--inputpattern INPUTPATTERN</td><td>Input file pattern (time-aligned words or lemmas)<br>(default: -palign)</td></tr><tr><td>--outputpattern OUTPUTPATTERN</td><td>Output file pattern (default: -orepet)</td></tr><tr><td>--span SPAN</td><td>Span window length in number of IPUs (default: 3)</td></tr><tr><td>--stopwords STOPWORDS</td><td>Add stop-words estimated from the given data<br>(default: True)</td></tr><tr><td>--alpha ALPHA</td><td>Coefficient to add data-specific stop-words<br>(default: 0.5)</td></tr></table>

## 3.21 Re-Occurrences

This annotation is searching for re-occurrences of an annotation of a speaker in the next N annotations of the interlocutor. It is originally used for gestures in (M. Karpinski et al. 2018).

Maciej Karpinski, Katarzyna Klessa Methods, Tools and Techniques for Multimodal Analysis of Accommodation in Intercultural Communication CMST 24(1) 29–41 (2018), DOI:10.12921/cmst.2018.0000006
### 3.21.1 Perform Re-Occurrences with the GUI

The automatic annotation takes as input any annotated file with (at least) one tier, and another file+tier of the interlocutor. The annotation provides one annotated file with 2 tiers: Sources and Repetitions.

Click on the Re-Occurrences activation button, and click on the “Configure…” blue text to fix options.

### 3.21.2 Perform Re-Occurrences with the CLI

```
usage: reoccurrences.py [files] [options]
```

#### Files:

<table><tr><td>-i file</td><td>Input file name with time-aligned annotations of the main speaker.</td></tr><tr><td>-s file</td><td>Input file name with time-aligned annotations of the interlocutor</td></tr><tr><td>-o file</td><td>Output file name with re-occurrences.</td></tr></table>

#### Options:

<table><tr><td>--inputpattern INPUTPATTERN</td><td>Input file pattern (default: )</td></tr><tr><td>--outputpattern OUTPUTPATTERN</td><td>Output file pattern (default: -reocc)</td></tr><tr><td>--tiename TIERNAME</td><td>Tier to search for re-occurrences (default: )</td></tr><tr><td>--span SPAN</td><td>Span window length in number of annotations (default: 10)</td></tr></table>

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

## 3.22 Momel (modelling melody)

Momel is an algorithm for the automatic modeling of fundamental frequency (F0) curves using a technique called asymmetric modal quadratic regression.

This technique makes it possible by an appropriate choice of parameters to factor an F0 curve into two components:

* a macro-prosodic component represented by a quadratic spline function defined by a sequence of target points < ms, hz >.

* a micro-prosodic component represented by the ratio of each point on the F0 curve to the corresponding point on the quadratic spline function.

For details, see the following reference:
**Daniel Hirst and Robert Espesser** (1993). *Automatic modelling of fundamental frequency using a quadratic spline function*. Travaux de l'Institut de Phonétique d'Aix. vol. 15, pages 71-85.

The SPPAS implementation of Momel requires a file with the F0 values sampled at 10 ms. Two file formats are supported:

* “.PitchTier”, from Praat.

* “.hz”, from any tool. It is a file with one F0 value per line.

The following options can be fixed:

* Window length used in the “cible” method

* F0 threshold: Maximum F0 value

* F0 ceiling: Minimum F0 value

* Maximum error: Acceptable ratio between two F0 values

* Window length used in the “reduc” method

* Minimal distance

* Minimal frequency ratio

* Eliminate glitch option: Filter f0 values before ‘cible’

### 3.22.1 Perform Momel with the GUI

It is an annotation of STANDALONE type.

Click on the Momel activation button then click on the “Configure…” blue text to fix options.

### 3.22.2 Perform Momel with the CLI

`momel.py` is the program to perform Momel annotation of a given file with F0 values sampled at 10ms.

#### Usage

`momel.py [files] [options]`

Momel: Proposed by D. Hirst and R. Espesser, Momel - Modelling of fundamental frequency (F0) curves is using a technique called assymetric modal quadratic regression. Requires pitch values.

optional arguments:

-h, --help show this help message and exit

- quiet Disable the verbosity

-log file File name for a Procedure Outcome Report (default: None)

Files (manual mode):

-i file Input file name (extension: .hz or .PitchTier)

-o file Output file name (default: stdout)

Files (auto mode):
-I file Input file name with pitch (append).

-e .ext Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

Options:

<table><tr><td>--outputpattern</td><td>OUTPUTPATTERN</td><td>Output file pattern (default: -momel)</td></tr><tr><td>--win1</td><td>WIN1</td><td>Target window length (default: 30)</td></tr><tr><td>--lo</td><td>LO</td><td>F0 threshold (default: 50)</td></tr><tr><td>--hi</td><td>HI</td><td>F0 ceiling (default: 600)</td></tr><tr><td>--maxerr</td><td>MAXERR</td><td>Maximum error (default: 1.04)</td></tr><tr><td>--win2</td><td>WIN2</td><td>Reduce window length (default: 20)</td></tr><tr><td>--mind</td><td>MIND</td><td>Minimal distance (default: 5)</td></tr><tr><td>--minr</td><td>MINR</td><td>Minimal frequency ratio (default: 0.05)</td></tr></table>

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.rg

Examples of use

python .\sppas\bin\momel.py -i .\samples\samples-eng\ENG_M15_ENG_T02.PitchTier
2018-12-19 15:44:00,437 [INFO] Logging set up level=15
2018-12-19 15:44:00,674 [INFO] ... ... 41 anchors found.
1.301629 109.285503
1.534887 126.157058
1.639614 143.657446
1.969234 102.911464
2.155284 98.550759
2.354162 108.250869
2.595364 87.005994
2.749773 83.577924
2.933222 90.218382
3.356651 119.709142
3.502254 104.104568
3.707747 132.055286
4.000578 96.262109
4.141915 93.741407
4.383332 123.996736
4.702203 89.152708
4.987086 101.561180
5.283864 87.499710
5.538984 92.399690
5.707147 95.411586
5.906895 87.081095
6.705373 121.396919
7.052992 130.821479
7.218415 120.917642
7.670083 101.867028
7.841935 109.094053
8.124574 90.763267
8.455182 114.261067
8.746016 93.704705
9.575359 101.108444
9.996245 122.488120
10.265663 105.244429
10.576394 94.875460
11.730570 99.698799
12.083323 124.002313
12.411790 108.563104
12.707442 101.928297
12.963805 113.980850
13.443483 90.782781
13.921939 90.824376
14.377324 60.126506

Apply Momel on all files of a given folder:

python .\sppas\bin\momel.py -I .\samples\samples-eng

## 3.23 INTSINT: Encoding of F0 anchor points

INTSINT assumes that pitch patterns can be adequately described using a limited set of tonal symbols, T,M,B,H,S,L,U,D (standing for : Top, Mid, Bottom, Higher, Same, Lower, Up-stepped, Down-stepped respectively) each one of which characterises a point on the fundamental frequency curve.

The rationale behind the INTSINT system is that the F0 values of pitch targets are programmed in one of two ways : either as absolute tones T, M, B which are assumed to refer to the speaker's overall pitch range (within the current Intonation Unit), or as relative tones H, S, L, U, D assumed to refer only to the value of the preceding target point.

INTSINT example

The rationale behind the INTSINT system is that the F0 values of pitch targets are programmed in one of two ways : either as absolute tones T, M, B which are assumed to refer to the speaker's overall pitch range (within the current Intonation Unit), or as relative tones H, S, L, U, D assumed to refer only to the value of the preceding target point.

A distinction is made between non-iterative H, S, L and iterative U, D relative tones since in a number of descriptions it appears that iterative raising or lowering uses a smaller F0 interval than non-iterative raising or lowering. It is further assumed that the tone S has no iterative equivalent since there would be no means of deciding where intermediate tones are located.

**D.-J. Hirst (2011). *The analysis by synthesis of speech melody: from data to models*, Journal of Speech Sciences, vol. 1(1), pages 55-83.**

### 3.23.1 Perform INTSINT with the GUI

It is an annotation of STANDALONE type.

Click on the INTSINT activation button and click on the “Configure…” blue text to fix options.

### 3.23.2 Perform INTSINT with the CLI

`intsint.py` is the program to perform INTSINT annotation of a given file with momel anchors.
## Usage

intsint.py [files] [options]

INTSINT: International Transcription System for INTonation codes the intonation of an utterance by means of an alphabet of 8 discrete symbols.
Requires Momel targets.

optional arguments:

-h, --help show this help message and exit

- quiet Disable the verbosity

-log file File name for a Procedure Outcome Report (default: None)

Files (manual mode):

-i file Input file name with anchors.

-o file Output file name (default: stdout)

Files (auto mode):

-I file Input file name with anchors (append).

-e .ext Output file extension. One of: .xra .TextGrid .eaf .csv .mrk .txt .stm .ctm .lab .mlf .sub .srt .antx .arff .xrff

Options:

-inputpattern INPUTPATTERN

Input file pattern (momel anchors) (default: -momel)

-outputpattern OUTPUTPATTERN

Output file pattern (default: -intsint)

This program is part of SPPAS version 2.4. Copyright (C) 2011-2019 Brigitte Bigi. Contact the author at: contact@sppas.org

## Examples of use

Apply INTSINT on a single file and print the result on the standard output:

python .\sppas\bin\intsint.py -i .\samples\samples-eng\ENG_M15_ENG_T02-momel.xra --quiet
1.301629 M
1.534887 U
1.639614 H
1.969234 L
2.155284 S
2.354162 U
2.595364 L
2.749773 S
2.933222 S
3.356651 H
3.502254 D
3.707747 H
4.000578 L
4.141915 S
4.383332 H
4.702203 L
4.987086 U
5.283864 L
5.538984 U
5.707147 D
5.906895 S
6.705373 M
7.052992 U
7.218415 S
7.670083 D
7.841935 S
8.124574 D
8.455182 U
8.746016 D
9.575359 M
9.996245 U
10.265663 D
10.576394 D
11.730570 M
12.083323 U
12.411790 D
12.707442 S
12.963805 U
13.443483 L
13.921939 S
14.377324 B

Apply INTSINT in auto mode:

python .\sppas\bin\intsint.py -I .\samples\samples-eng\ENG_M15_ENG_T02.wav
python .\sppas\bin\intsint.py -I .\samples\samples-eng\ENG_M15_ENG_T02.PitchTier
python .\sppas\bin\intsint.py -I .\samples\samples-eng\ENG_M15_ENG_T02-momel.xra

## 3.24 Hand&Pose

SPPAS is a wrapper for MediaPipe Hand detection and Mediapipe Pose detection. It also proposes a custom solution in order to detect right-left hands of a person.

### 3.24.1 Overview

MediaPipe Hands is a high-fidelity hand and finger tracking solution. It employs machine learning (ML) to infer 21 3D landmarks of a hand from just a single frame. MediaPipe Hands utilizes an ML pipeline consisting of multiple models working together: A palm detection model that operates on the full image and returns an oriented hand bounding box. A hand landmark model that operates on the cropped image region defined by the palm detector and returns high-fidelity 3D hand key points. For details about hand detection, see: https://google.github.io/mediapipe/solutions/hands.html

MediaPipe Pose is a ML solution for high-fidelity body pose tracking, inferring 33 3D landmarks. For details about pose detection, see: https://google.github.io/mediapipe/solutions/pose.html

Important:
* SPPAS is only exporting (x,y)

* SPPAS can export the results in either XRA or CSV formats.

Three detection “mode” are available:

1. hands only: when enabling hands and disabling pose, SPPAS is a simple wrapper for MediaPipe Hand detection. The result of the system is a list of 21 sights for each detected hand.

2. pose only: when disabling hand detection and enabling pose detection, SPPAS is a simple wrapper for MediaPipe Pose detection. Notice that if several persons are on the image, it will detect only one human body. The result of the system is a list of the 33 sights of the human body.

3. hand&pose: when enabling both hand and pose, SPPAS is combining both pose detections and hand detections. It results in two lists of sights: the first list for the right hand and the second list of the left hand. Each list is made either of 21 sights if the hand was properly detected by the hand prediction system, or made of the 4 sights of the pose detection system.

Here is the match between the indexes of the 8 sights of the pose detection and the indexes of the sights of the hand detection:

* right hand: pose 16 is hand 0, pose 18 is hand 8, pose 20 is hand 20 and pose 22 is hand 4.

* left hand: pose 15 is hand 0, pose 17 is hand 8, pose 19 is hand 20 and pose 21 is hand 4.

### 3.24.2 Perform annotation with the GUI

It is a STANDALONE annotation.

The annotation process takes as input an image or a video file. To perform the annotation, click on its activation button and click on the “Configure…” blue text to fix options.

### 3.24.3 Perform with the CLI

The CLI does not work on an image but video recordings only. To perform this annotation on an image, use the script `annotation.py` instead.

usage: handpose.py [files] [options]

optional arguments:

-h, --help show this help message and exit

-q, --quiet Disable the verbosity

-l, --log file File name for a Procedure Outcome Report (default: None)

Files:

-i, --input file Input video.

-o, --output file Output base name.

-I, --input file (append). Input file name (append).

-e, --output extension. One of: .mp4 .avi .mkv .mov

Options:

-i, --input pattern1 INPUT PATTERN 1

Input pattern of the video file. (default: )
<table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>--outputpattern</td><td>OUTPUTPATTERN</td></tr><tr><td>--hand HAND</td><td>Output file pattern with the sights. (default: -hands)</td></tr><tr><td>--pose POSE</td><td>Enable hands detection. (default: True)</td></tr><tr><td>--csv CSV</td><td>Enable pose detection -- for only one human body. (default: True)</td></tr><tr><td>--tag TAG</td><td>Save points in a CSV file instead of XRA (default: False)</td></tr><tr><td>--folder FOLDER</td><td>Draw points on the video (default: True)</td></tr><tr><td></td><td>Save result in a folder with image files -- if video input only (default: False)</td></tr></tbody></table>

## 3.25 Face Detection

This is a state-of-the-art implementation of face detection performed with freely available models and tools. We introduced an original method in order to use any or all of them and to combine their results. This combined result was not evaluated.

### 3.25.1 Overview

FaceDetection annotation allows to search for coordinates of faces in an image or in all images of a video. It requires both to enable the "video" feature in the setup to install the external libraries 'numpy', ' opencv-contrib' and 'mediapipe'. It also requires to check "facedetect" in the list of annotations to be installed at the time of the setup.

On the basis of the detection methods implemented in the opencv library, SPPAS is able to use several systems and to combine their results. These systems are based on 2 different methods:

1. an Artificial Neural Network (DNN);

2. an Haar Cascade Classifier (HCC).

The linguistic resources of this annotation include two DNN models and two models for HCC (a frontal-face model and a profile-face one). SPPAS can also launch the MediaPipe face detection system which is much more faster than the previous ones but results sounds worse.

By default, SPPAS launches two of these detectors: 1 DNN and 1 HCC, and it combines their results. This annotation is about 2.5x real time. Even if it can increase the quality of the final result, other models are not used by default because the detection is very slow: 15x real time to use all of the 5 models. The options allow to choose the models to be used.

### 3.25.2 Result of Face Detection

There are several output files that can be created:

* a copy of the image/video with all the detected faces surrounded by a square indicating a confidence score;

* as many cropped image files as the number of detected faces;

* an XRA or a CSV file with coordinates and confidence score of each detected face.

There's also the possibility to consider the selfie (portrait size) instead of the face.
### 3.25.3 Perform Face Detection with the GUI

It is a STANDALONE annotation.

The Face Detection process takes as input an image file and/or a video. To perform the annotation, click on the FaceDetection activation button and click on the “Configure…” blue text to fix options.

### 3.25.4 Perform Face Detection with the CLI

`facedetection.py` is the program to perform Face Detection annotation of a given media file.

#### Usage

```
usage: facedetection.py [files] [options]
```

**optional arguments:**

<table><tr><td>-h, --help</td><td>show this help message and exit</td></tr><tr><td>--quiet</td><td>Disable the verbosity</td></tr><tr><td>--log file</td><td>File name for a Procedure Outcome Report (default: None)</td></tr></table>

**Files:**

<table><tr><td>-i file</td><td>Input image.</td></tr><tr><td>-o file</td><td>Output base name.</td></tr><tr><td>-I file</td><td>Input file name (append).</td></tr><tr><td>-r model</td><td>Model base name (.caffemodel or .xml models as wishes)</td></tr><tr><td>-e .ext</td><td>Output file extension (image or video)</td></tr></table>

**Options:**

<table><tr><td>--inputpattern INPUTPATTERN</td><td>Input file pattern (default: %)</td></tr><tr><td>--nbest NBEST</td><td>Number of faces to select among those detected (0=auto) (default: 0)</td></tr><tr><td>--score SCORE</td><td>Minimum confidence score to select detected faces (default: 0.2)</td></tr><tr><td>--portrait PORTRAIT</td><td>Consider the portrait instead of the face in outputs (default: False)</td></tr><tr><td>--csv CSV</td><td>Save coordinates of detected faces in a CSV file instead of XRA (default: False)</td></tr><tr><td>--folder FOLDER</td><td>Save result in a folder with image files -- if video input only (default: False)</td></tr><tr><td>--tag TAG</td><td>Surround the detected faces in the output image (default: True)</td></tr><tr><td>--crop CROP</td><td>Save detected faces in cropped images (default: False)</td></tr><tr><td>--width WIDTH</td><td>Resize all the cropped images to a fixed width (0=no) (default: 0)</td></tr><tr><td>--height HEIGHT</td><td>Resize all the cropped images to a fixed height (0=no) (default: 0)</td></tr><tr><td>--model: opencvFaceDetector_uint8.pb MODEL</td><td>Enable the opencv's ANN TensorFlow model. (default: True)</td></tr><tr><td>--model: haarcascade_frontalfaceAlt.xml MODEL</td><td>Enable the opencv's HaarCascade Frontal face model. (default: True)</td></tr></table>
```
--model:res10_300x300_ssd_iter_140000_fp16.caffemodel MODEL
Enable the opencv's ANN Caffe model.
(default: False)
```

```
--model:haarcascade_profileface.xml MODEL
Enable the opencv's HaarCascade Profile face model.
(default: False)
```

```
--model:mediapipe MODEL:MEDIAPIPE
Enable the MediaPipe Face Detection system.
(default: False)
```

This program is part of SPPAS version 4.2. Copyright (C) 2011-2021 Brigitte Bigi. Contact the author at: contact@sppas.org

## Examples of use

```python
python3 ./sppas/bin/facedetection.py -I ./samples/faces/BrigitteBigi_Aix2020.png --tag=True
[INFO] Logging redirected to StreamHandler (level=0).
[INFO] SPPAS version 3.5
[INFO] Copyright (C) 2011-2021 Brigitte Bigi
[INFO] Web site: http://www.sppas.org/
[INFO] Contact: Brigitte Bigi (contact@sppas.org)
[INFO] * * * Annotation step 0 * * *
[INFO] Number of files to process: 1
[INFO] Options:
[INFO] ... inputpattern:
[INFO] ... outputpattern: -face
[INFO] ... nbest: 0
[INFO] ... score: 0.2
[INFO] ... portrait: True
[INFO] ... csv: True
[INFO] ... tag: True
[INFO] ... crop: True
[INFO] ... width: 0
[INFO] ... height: 0
[INFO] File BrigitteBigi_Aix2020.png: Valid.
[INFO] ... ... 3 faces found.
[INFO] ... ./samples/faces/BrigitteBigi_Aix2020-face.jpg
```

It creates the following 5 files in the samples/faces folder:

* BrigitteBigi_Aix2020-face.jpg with the 3 detected faces surrounded by a square and indicating the detection score

* BrigitteBigi_Aix2020_1-face.jpg: image of the face with the highest score

* BrigitteBigi_Aix2020_2-face.jpg: image of the face with the medium score

* BrigitteBigi_Aix2020_3-face.jpg: image of the face with the worse score

* BrigitteBigi_Aix2020-face.csv contains 3 lines with coordinates in columns 3-7 with (x,y) and (w,h) then the confidence score in column 8 ranging [0., 1.]

Notice that the image contains 3 faces and their positions are properly found.
## 3.26 Face Identity

This is a new and original automatic annotation but it's still in progress. It has to be evaluated.

### 3.26.1 Overview

Face Identity automatic annotation assigns a person identity to detected faces of a video. It takes as input a video and a CSV file with coordinates of the detected faces. It produces a CSV file with coordinates of the identified faces. Assigned person names are "id-00x". Obviously, the CSV file can be edited and such names can be changed *a posteriori*.

This annotation requires to enable the "video" feature in the setup, so it will install the external python libraries 'numpy' and 'opencv-contrib'.

No external resources are needed.

### 3.26.2 Perform annotation with the GUI

It is a STANDALONE annotation.

The Face Identity process takes as input a video file. To perform the annotation, click on the Face Identity activation button and click on the "Configure..." blue text to fix options.

### 3.26.3 Perform with the CLI

`faceidentity.py` is the program to perform Face Identity annotation of a given video file, if the corresponding CSV file with detected faces is existing.

#### Usage

```
usage: faceidentity.py [files] [options]
```

**optional arguments:**

-h, --help      show this help message and exit

-q, --quiet     Disable the verbosity

-l, --log file   File name for a Procedure Outcome Report (default: None)

**Files:**

-i, --input file Input video.

-c, --csv file Input CSV file with face coordinates and sights.

-o, --output file Output base name.

-I, --input file name (append).

-e, --ext Output file extension. One of: .mp4 .avi .mkv

**Options:**

-i, --input pattern INPUT PATTERN

-c, --csv pattern INPUT CSV PATTERN (default: -csv)

-o, --output pattern OUTPUT PATTERN (default: -o)
## 3.27 Face Landmarks

This is a state-of-the-art implementation of face landmark performed with freely available models and tools. We introduced a solution to combine the results when several methods are used. The combined result was not evaluated.

### 3.27.1 Overview

SPPAS is using both the MediaPipe Face Mesh and the OpenCV's facial landmark API called Facemark. It includes three different implementations of landmark detection based on three different papers:

* FacemarkKazemi: This implementation is based on a paper titled "One Millisecond Face Alignment with an Ensemble of Regression Trees" by V.Kazemi and J. Sullivan published in CVPR 2014.

* FacemarkAAM: This implementation uses an Active Appearance Model and is based on an the paper titled "Optimization problems for fast AAM fitting in-the-wild" by G. Tzimiropoulos and M. Pantic, published in ICCV 2013.

* FacemarkLBF: This implementation is based on a paper titled "Face alignment at 3000 fps via regressing local binary features" by S. Ren published in CVPR 2014.

The fundamental concept is that any person will have 68 particular points on the face (called sights). SPPAS is able to launch several of them and to combine their results in a single and hopefully better one. Actually, SPPAS is launching MediaPipe Face Mesh and extracting the 68 sights among the 468 that are detected; then this result is combined (weight=6) with the 68 sights of the LBF detection method (weight=1).

This annotation requires both to enable the "video" feature in the setup in order to install the external libraries 'numpy' and 'opengl-contrib', and to check "facemark" in the list of annotations to be installed. Two different models will be downloaded and used: a Kazemi one and a LBF one.

### 3.27.2 Perform annotation with the GUI

It is a STANDALONE annotation.

The Face Sights process takes as input an image file and/or a video. To perform the annotation, click on the Face Sights activation button and click on the "Configure..." blue text to fix options.

### 3.27.3 Perform with the CLI

```
usage: facesights.py [files] [options]
```

**optional arguments:**

-h, --help      show this help message and exit

- quiet          Disable the verbosity

-log file        File name for a Procedure Outcome Report

**Files:**

-i file          Input image.

-o file          Output base name.

-I file          Input file name (append).

-r model         Landmark model name (Kazemi, LBF or AAM)

-R model         FaceDetection model name
-e .ext Output file extension.

Options:

--inputpattern INPUTPATTERN

--inputoptpattern INPUTOPTPATTERN (default: -face)

--outputpattern OUTPUTPATTERN (default: -sights)

## 3.28 Cued speech - LfPC

This automatic annotation is currently under development. It is in progress and it's currently only a Proof of Concept. **It mustn't be used neither for any final application nor evaluation.** It can only be used in order to test it and to contribute in improving it.

### 3.28.1 Overview

Speech reading or lip-reading requires watching the lips of a speaker and is used for the understanding of the spoken sounds. However, various sounds have the same lips movement which implies a lot of ambiguity. In 1966, R. Orin Cornett invented the Cued Speech, a visual system of communication. It adds information about the pronounced sounds that are not visible on the lips.

Thanks to this code, speech reading is encouraged since the Cued Speech (CS) keys match all the spoken phonemes but phonemes with the same movement have different keys. Actually, from both the hand position on the face (representing vowels) and hand shapes, known as cues (representing consonants), CV syllables can be represented. So, a single CV syllable will be generated or decoded through both the lips position and the key of the hand.

LfPC is the French acronym for “Langue française Parlée Complétée”.

The conversion of phonemes into keys of CS is performed using a rule-based system. This RBS phoneme-to-key segmentation system is based on the only principle that a key is always of the form CV.

This annotation requires both to enable the “video” feature in the setup to install the external libraries ‘numpy’ and ‘ opencv-contrib’ and to check “cuedspeech” in the list of annotations.

### 3.28.2 Perform annotation with the GUI

It is a STANDALONE annotation.

The annotation process takes as input a "-palign" file and optionally a video. To perform the annotation, click on its activation button and click on the "Configure..." blue text to fix options.

### 3.28.3 Perform with the CLI

usage: cuedspeech.py [files] [options]

optional arguments:

-h, --help show this help message and exit

-q, --quiet Disable the verbosity

-l, --log file File name for a Procedure Outcome Report (default: None)
Files:

<table><tr><td>-i file</td><td>Input time-aligned phonemes file name.</td></tr><tr><td>-v file</td><td>Input video file name.</td></tr><tr><td>-o file</td><td>Output file name with Cued Speech key codes.</td></tr><tr><td>-r rules</td><td>File with Cued Speech keys description</td></tr></table>

<table><tr><td>-I file</td><td>Input file name (append).</td></tr><tr><td>-l lang</td><td>Language code (iso8859-3). One of: fra.</td></tr><tr><td>-e .ext</td><td>Output file extension. One of: .xra .TextGrid .eaf .ant .antx .mrk .lab .srt .sub .vtt .ctm .stm .csv .txt</td></tr></table>

Options:

-`--inputpattern1 INPUTPATTERN1`
  Pattern of the file with time-aligned phonemes
  (default: -palign)

-`--inputpattern2 INPUTPATTERN2`
  Pattern of the video file (default: )

-`--inputpattern3 INPUTPATTERN3`
  Pattern of the file with sights of the face of
  the person (default: -sights)

-`--outputpattern OUTPUTPATTERN`
  Pattern of the output files (default: -cuedsp)

-`--createvideo CREATEVIDEO`
  Tag the video with the code of the key
  (needs video+csv) (default: False)
# Convert files

## 4.1 Interoperability and compatibility: an introduction

The conversion of a file to another file is the process of changing the form of the presentation of the data, and not the data itself. Every time, when data file is to be used, they must be converted to a readable format for the next application. A data conversion is normally an automated process to some extent. SPPAS provide the possibility to automatically import and export the work done on some various file formats from a wide range of other software tools. For the users, the visible change will be only a different file extension but for software it is the difference between understanding of the contents of the file and the inability to read it.

The conversion of file formats is then a difficult task and it can imply that some data are left. Representing annotated data in SPPAS is of crucial importance for its automatic annotations, its analysis of annotations and for the software to be able to automatically annotate and analyze any kind of data files. SPPAS then includes an original and generic enough annotation representation framework. This framework for annotations is very rich and contain several information like alternative labels or alternative localizations of annotations, a tier hierarchy, controlled vocabularies, etc. A native format named XRA was then developed to fit in such data representation. The physical level of representation of XRA obviously makes use of XML, XML-related standards and stand-off annotation. Due to an intuitive naming convention, XRA documents are human readable as far as possible within the limits of XML.

## 4.2 SPPAS conversion method

In the scope of the compatibility between SPPAS data and annotated data from other software tools or programs, SPPAS is able to open/save and import/export several file formats.

SPPAS makes use of its internal data representation to convert files. A conversion then consists of two steps:

1. the incoming file is loaded and mapped to the SPPAS data framework;

2. such data is saved to the expected format.

These two steps are applied whatever the organization structure of annotations in the original or in the destination file format. This process allows SPPAS to import from and export to a variety of file formats. This is
illustrated by the next Figure which includes the list of file formats and the corresponding software that are supported. Arrows are representing the following actions:

* import from, represented by a continued line with an arrow from the file format to the SPPAS framework;

* partially import from, represented by a dash line with an arrow from the file format to the SPPAS framework;

* export to, represented by an arrow from the SPPAS framework to the file format.

SPPAS conversion method and formats

## 4.3 Supported file formats

SPPAS supports the following software with their file extensions:

* Praat: TextGrid, PitchTier, IntensityTier

* Elan: eaf

* Annotation Pro: ant, antx

* Phonedit: mrk

* Sclite: ctm, stm

* HTK: lab, mlf

* Subtitles: srt, sub

* Signaix: hz

* Spreadsheets, R, ..., csv

* Audacity, notepads: txt

The followings can be imported:

* ANVIL: anvil

* Transcriber: trs

* Xtrans: tdf

The followings can be exported:

* Weka: arff, xrff

* Subtitles: vtt

The support of external formats is regularly extended to new formats by the author on-demand from the users and distributed to the community in the SPPAS regular updates.

## 4.4 Convert with the UI of SPPAS

The page 'Convert' of the GUI allows to convert checked files of the workspace into the selected format. A table is indicating which of the features are supported by each format. It allows to know what to expect when converting from one format to the other one. For example, a Praat TextGrid file does not contain metadata nor media information neither a controlled vocabulary nor a hierarchy. If the file to be converted contains such information, they'll be lost in the TextGrid converted file.

The program `bin/trsconvert.py` allows to convert files with the CLI.
# Data Analyses

## 5.1 Introduction

The analyses of annotated files includes the descriptive statistics, the filtering of the annotated data to get only the annotations you are interested in, see/edit the information about files, etc.

Like the other features of SPPAS, analyzing data can be performed in three different ways:

* the Application Programming Interface, in Python language;

* the Command-Line User Interface;

* the Graphical User Interface.

Among the features implemented in the API, a big majority are included in the GUI but just a few can be performed with the CLI. This chapter then describes only the page "Analyze" of the GUI.

## 5.2 The page Analyze of the GUI

The page "Analyze" of the GUI is divided into 2 main areas: a toolbar and a content to represent files.

### 5.2.1 Displayed files content

Each opened file is displayed in a panel in the content area. The next Figure shows how panels of 4 different files look like. Panels of the annotated files have a yellow background, panels of the audio files are blue and panels of unknown files are pinky-red.

Analyze: open files

Some actions can be performed individually on the panel of a file. A mouse click on the filename or on the arrow at left will show or hide the content of the file.

For transription files, the icons at top-right of the panel allow to:

* edit the metadata of the file - notice that only the XRA file format allows to save the metadata;
* select the file (for example, it's used to paste tiers into);

* save the file - only if it has changed;

* close the file and unlock it in the workspace.

For audio files, the icons at top-right of the panel allow to:

* view audio content and manage channels - available only for files less than a few minutes;

* close the file.

### 5.2.2 The toolbar

The toolbar of the page is made of 3 different parts:

1. "Files:" click on these buttons to perform an action on the checked filenames of the page "Files";

2. "Tiers:" click on these buttons to perform an action on the ckeched tiers of the opened files;

3. "Annotations:" click on these buttons to analyze the annotations of the checked tiers of the opened files.

#### Files: Open files

Open, load and display a panel for each checked file of the current workspace. Some files could need a long time to be loaded (like TextGrid files with a lot of annotations), so a scrollbar should indicate the progression. As soon as a file is opened, it is locked and no other page can perform an action on it.

To open new files, check new files in the current workspace and click again on the "Open files" button. The panels of the newly opened files will be appended to the existing ones.

#### Files: New file

Click on this button to create a new annotated file. A dialog box will ask for a path/filename and for a file extension. The extension defines the file format; any of the supported file format can be used. The file will be created on disk when it will be saved for the first time.

#### Files: Save all

Save all files for which some changes were done, without confirmation.

#### Files: Close all

Close all the opened files. If some files were changed and not saved, a dialog will ask for confirmation.

#### Tiers: Metadata

Open a dialog to edit the metadata of the checked tiers. Notice that most of the file format don't allow to save metadata or it allows only some specific ones; only the XRA format allows to save any tier metadata.
**Tiers: Check**

A click on the “Check” button will open a dialog to enter a tier name and it will check all tiers matching it. The entry is a regular expression.

**Tiers: Uncheck**

A click on the “Uncheck” button will un-check all tiers.

**Tiers: Rename**

A mouse click on the “Rename” button will open a dialog to fix a name of a tier and then to rename all checked tiers. If a file has already a tier with the given name, an index number will be appended to the new name.

**Tiers: Delete**

A mouse click on the “Delete” button will delete all checked tiers. This process is irreversible. To recover a deleted tier, the only way is to close the file and to re-open it but all the un-saved changes are lost.

**Tiers: Cut/Copy/Paste**

The Cut/Copy/Paste buttons allow to use a clipboard to manage tiers. Tiers can then be copied from files to other ones. The files to paste in must be selected first with the “select” button of the individual panels.

**Tiers: Duplicate**

The duplicate button allows to copy/paste a tier into the same file. The name of the duplicated tier will be the same as the original one with an index number at the end.

**Tiers: Move Up/Move Down**

These buttons allow to move checked tiers into a file.

**Annotations: Radius**

The “Radius” button allows to fix a radius for all the localizations of the annotations of the checked tiers, i.e. the vagueness around the fixed point in time. Notice that only XRA file format allows to save it.

Read the following paper for details:

Brigitte Bigi, Tatsuya Watanabe, Laurent Prévot (2014). **Representing Multimodal Linguistics Annotated Data**, 9th International conference on Language Resources and Evaluation (LREC), Reykjavik (Iceland), pages 3386-3392. ISBN: 978-2-9517408-8-4.
**Annotations: View**

Click the button “View” to see all the annotations of the checked tiers in a table.

**Annotations: Statistics**

It allows to estimate the number of occurrences, the duration, etc. of the annotations of the checked tiers,
and allows to save result in CSV (for Excel, OpenOffice, R, MatLab,...).

It offers a serie of sheets organized in a notebook. The first tab is displaying a summary of descriptive statistics of the set of given tiers. The other tabs are indicating one of the statistics over the given tiers. The followings are estimated:

* occurrences: the number of observations

* total durations: the sum of the durations

* mean durations: the arithmetic mean of the duration

* median durations: the median value of the distribution of durations

* std dev. durations: the standard deviation value of the distribution of durations

All of them can be estimated on a single annotation label or on a serie of them. The length of this context
can be optionally changed while fixing the “N-gram” value (available from 1 to 5), just above the sheets.

Each displayed sheet can be saved as a CSV file, which is a useful file format to be read by R, Excel, OpenOf-
fice, LibreOffice, and so... To do so, display the sheet you want to save and click on the button “Save sheet”,
just below the sheets. If you plan to open this CSV file with Excel under Windows, it is recommended to
change the encoding to UTF-16. For the other cases, UTF-8 is probably the most relevant.

The annotation durations are commonly estimated on the Midpoint value, without taking the radius into account; see (Bigi et al, 2012) for explanations about the Midpoint/Radius. Optionally, the duration can either be estimated by taking the vagueness into account, then check “Add the radius value” button, or by ignoring the vagueness and estimating only on the central part of the annotation, then check “Deduct the radius value”.

For those who are estimating statistics on XRA files, you can either estimate stats only on the best label (the label with the higher score) or on all labels, i.e. the best label and all its alternatives (if any).

Descriptive statistics

**Annotations: Single filter**

It allows to create a new tier with only selected annotations: define filters in order to create new tiers with
only the annotations you are interested in!

Pattern selection is an important part to extract data of a corpus and is obviously and important part of any
filtering system. Thus, if the label of an annotation is a string, the following filters are proposed in DataFilter:

* exact match: an annotation is selected if its label strictly corresponds to the given pattern;

* contains: an annotation is selected if its label contains the given pattern;

* starts with: an annotation is selected if its label starts with the given pattern;

* ends with: an annotation is selected if its label ends with the given pattern.
All these matches can be reversed to represent respectively: does not exactly match, does not contain, does not start with or does not end with. Moreover, this pattern matching can be case sensitive or not.

For complex search, a selection based on regular expressions is available for advanced users.

A multiple pattern selection can be expressed in both ways:

* enter multiple patterns at the same time (separated by commas) to mention the system to retrieve either one pattern or the other, etc.

* enter one pattern at a time and choose the appropriate button: “Apply All” or “Apply any”.

Frame to create a filter on annotation label tags: filter annotations that exactly match either a, @ or E

Another important feature for a filtering system is the possibility to retrieve annotated data of a certain duration, and in a certain range of time in the timeline.

Frame to create a filter on annotation durations: filter annotations that are during more than 80 ms

Search can also starts and/or ends at specific time values in a tier.

Frame to create a filter on annotation time values: filter annotations that are starting after the 5th minute

In SPPAS 3.7, a new filter is added: it can select annotation depending on their number of labels. For example, the automatic annotation “Normalization” creates a tier “Tokens” in which each annotation contains a list of labels - one per token; then it is possible to get the annotations with more then 3 tokens, with only one token, etc.

All the given filters are summarized in the “SingleFilter” dialog. To complete the filtering process, it must be clicked on one of the apply buttons and the new resulting tiers are added in the annotation file(s).

In the given example:

* click on “Apply All” to get either a, @ or E vowels during more than 80ms, after the 5th minute.

* click on “Apply Any” to get a, @ or E vowels, and all annotations during more than 80 ms, and all annotations after the 5th minute.

DataFilter: SingleFilter frame

Read the following publications for details:

*Brigitte Bigi (2019). Filtering multi-levels annotated data.* In 9th Language & Technology Conference: Human Language Technologies as a Challenge for Computer Science and Linguistics, pp. 13-14, Poznań, Poland.

*Brigitte Bigi, Jorane Saubesty (2015). Searching and retrieving multi-levels annotated data*,
Proceedings of Gesture and Speech in Interaction, Nantes (France).

## Annotations: Relation filter

Regarding the searching problem, linguists are typically interested in locating patterns on specific tiers, with the possibility to relate different annotations a tier from another. The proposed system offers a powerful way to request/extract data, with the help of Allen's interval algebra.

In 1983 James F. Allen published a paper in which he proposed 13 basic relations between time intervals that are distinct, exhaustive, and qualitative:
* distinct because no pair of definite intervals can be related by more than one of the relationships;

* exhaustive because any pair of definite intervals are described by one of the relations;

* qualitative (rather than quantitative) because no numeric time spans are considered.

These relations and the operations on them form Allen's interval algebra. These relations were extended to Interval-Tiers as Point-Tiers to be used to find/select/filter annotations of any kind of time-aligned tiers.

For the sake of simplicity, only the 13 relations of the Allen's algebra are available in the GUI. But actually, we implemented the 25 relations proposed Pujari and al. (1999) in the INDU model. This model is fixing constraints on INtervals (with Allen's relations) and on DUration (duration are equals, one is less/greater than the other). Such relations are available while requesting with Python.

At a first stage, the user must select the tiers to be filtered and click on “RelationFilter”. The second stage is to select the tier that will be used for time-relations.

### Fix time-relation tier name

The next step consists in checking the Allen's relations that will be applied. The last stage is to fix the name of the resulting tier. The above screenshots illustrates how to select the first phoneme of each token, except for tokens that are containing only one phoneme (in this later case, the “equal” relation should be checked).

### DataFilter: RelationFilter frame

To complete the filtering process, it must be clicked on the “Apply” button and the new resulting tiers are added in the annotation file(s).
# Scripting with Python and SPPAS

## 6.1 Introduction

Since version 1.8.7, SPPAS implements an Application Programming Interface (API), named *anndata*, to deal with annotated files. Previously, SPPAS was based on another API named *annotationdata* which is still distributed in the package but no longer updated or maintained.

*anndata* API is a free and open source Python library to access and search data from annotated data of any of the supported formats (xra, TextGrid, eaf...). It can either be used with the Programming Language Python 2.7 or Python 3.4+. This API is PEP8 and PEP257 compliant and the internationalization of the messages is implemented (English and French are available in the "po" directory).

In this chapter, it is assumed that a version of Python is installed and configured. It is also assumed that the Python IDLE is ready-to-use. For more details about Python, see:

The Python Website: http://www.python.org

This chapter firstly introduces basic programming concepts, then it gradually introduces how to write scripts with Python. Those who are familiar with programming in Python can directly go to the last section related to the description of the *anndata* API and how to use it in Python scripts.

This API can convert file formats like Elan's EAF, Praat's TextGrid and others into a `sppasTranscription` object and convert this object into any of these formats. This object allows unified access to linguistic data from a wide range sources.

This chapter includes exercises. The solution scripts are included in the package directory *documentation*, folder *scripting_solutions*.

## 6.2 A gentle introduction to programming
## 6.2.1 Introduction

This section includes examples in Python programming language. You may want to try out some of the examples that come with the description. In order to do this, execute the Python IDLE - available in the Application-Menu of your operating system, and write the examples after the prompt ">>>".

The Python IDLE logo

To get information about the IDLE, get access to the IDLE documentation

Writing any program consists of writing statements so using a programming language. A *statement* is often known as a line of code that can be one of:

* comment,

* documentation,

* assignment,

* conditions,

* iterations, etc.

Lines of code are grouped in *blocks*. Depending on the programming language, blocks delimited by brackets, braces or by the indentation.

Each language has its own syntax to write these lines and the user has to follow strictly this syntax for the program to be able to interpret the program. However, the amount of freedom the user has to use capital letters, whitespace and so on is very high. Recommendations for Python language are available in the PEP8 - Style Guide for Python Code.

## 6.2.2 Variables: Assignment and Typing

A *variable* is a name to give to a piece of memory with some information inside. Assignment is then the action of setting a variable to a value. The equal sign (`=`) is used to assign values to variables.

```python
>>> a = 1
>>> b = 1.0
>>> c = "c"
>>> hello = "Hello world!"
>>> vrai = True
```

In the previous example, `a`, `b`, `c`, `hello` and `vrai` are variables, `a = 1` is a declaration.

Variable declarations and print in the Python IDLE

Assignments to variables with Python language can be performed with the following operators:

```python
>>> a = 10   # simple assignment operator
>>> a += 2   # add and assignment operator, so a is 12
>>> a -= 7   # minus and assignment, so a is 5
>>> a *= 20  # multiply and assignment, so a is 100
>>> a /= 10  # divide and assignment, so a is 10
>>> a       # verify the value of a...
10
```
### 6.2.3 Basic Operators

Basic operators are used to manipulate variables. The following is the list of operators that can be used with Python, i.e. equal (assignment), plus, minus, multiply, divide:

```python
>>> a = 10
>>> b = 20 # assignment
>>> a + b   # addition
>>> a - b   # subtraction
>>> a * b   # multiplication
>>> a / b   # division
```

### 6.2.4 Data types

The variables are of a data-type. For example, the declarations `a=1` and `a=1.0` are respectively assigning an integer and a real number. In Python, the command `type` allows to get the type of a variable, like in the following:

```python
>>> type(a)
<type 'int'>
>>> type(b)
<type 'float'>
>>> type(c)
<type 'str'>
>>> type(cc)
<type 'unicode'>
>>> type(vrai)
<type 'bool'>
```

Here is a list of some fundamental data types, and their characteristics:

* `str` String of characters

* `unicode` Unicode string of characters

* `int` Integer in range from -2147483648 to 2147483647

* `bool` Boolean value, can take value `True` (=1) or `False` (=0)

* `float` Floating point number (max 15 digits)

Python is assigning data types dynamically. As a consequence, the result of the sum between an `int` and a `float` is a `float`. The next examples illustrate that the type of the variables have to be carefully managed.

```python
>>> a = 10
>>> a += 0.
>>> a
10.0
>>> a += True
>>> a
11.0
```
```python
>>> a += "a"
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: unsupported operand type(s) for +=: 'float' and 'str'
>>> a = "a"
>>> a *= 5
>>> a
'aaaaa'
```

The type of a variable can be explicitly changed. This is called a “cast”:

```python
>>> a = 10
>>> b = 2
>>> a/b
5
>>> float(a) / float(b)
5.0
>>> a = 1
>>> b = 1
>>> str(a) + str(b)
'11'
```

Complex data types are often used to store variables sharing the same properties like a list of numbers, and so on. Common types in languages are lists/arrays and dictionaries. The following is the assignment of a list with name `fruits`, then the assignment of a sub-part of the list to the `to.buy` list:

```python
>>> fruits = ['apples', 'tomatoes', 'peers', 'bananas', 'lemons']
>>> to.buy = fruits[1:3]
>>> to.buy
['tomatoes', 'peers']
```

### 6.2.5 Conditions

Conditions aim to test whether a statement is True or False. The statement of the condition can include a variable, or be a variable and is written with operators. The following shows examples of conditions/comparisons in Python. Notice that the comparison of variables of a different data-type is possible (but not recommended!).

```python
>>> var = 100
>>> if var == 100:
...     print("Value of expression is 100.")
...
Value of expression is 100.
>>> if var == "100":
...     print("This message won't be printed out.")
...
```
Conditions can be expressed in a more complex way like:

```python
>>> if a == b:
...     print('a and b are equals')
...
elif a > b:
...     print('a is greater than b')
...
else:
...     print('b is greater than a')
```

The simple operators for comparisons are summarized in the next examples:

```python
>>> a == b      # check if equals
>>> a != b      # check if different
>>> a > b       # check if a is greater than b
>>> a >= b      # check if a is greater or equal to b
>>> a < b       # check if a is lesser than b
>>> a <= b      # check if a is lesser or equal to b
```

It is also possible to use the following operators:

* `and`: called "Logical AND operator". If both the operands are true then the condition becomes true.

* `or`: called "Logical OR operator". If any of the two operands are non zero then the condition becomes true.

* `not`: called "Logical NOT operator". Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

* `in`: evaluates to true if it finds a variable in the specified sequence and false otherwise.

```python
>>> if a == "apples" and b == "peers":
...     print("You need to buy fruits.")
>>> if a == "apples" or b == "apples":
...     print("You already have bought apples.")
>>> if "tomatoas" not in to.buy:
...     print("You don't have to buy tomatoes.")
```

### 6.2.6 Loops

The `for` loop statement iterates over the items of any sequence. The next Python lines of code print items of a list on the screen:

```python
>>> to.buy = ['fruits', 'viande', 'poisson', 'oeufs']
>>> for item in to.buy:
...     print(item)
...
fruits
viande
poisson
oeufs
```
A `while` loop statement repeatedly executes a target statement as long as a given condition returns `True`. The following example prints exactly the same result as the previous one:

```python
>>> to.buy = ['fruits', 'viande', 'poisson', 'oeufs']
>>> i = 0
>>> while i < len(to.buy):
...     print(to.buy[i])
...     i += 1
...
fruits
viande
poisson
oeufs
```

### 6.2.7 Dictionaries

A dictionary is a very useful data type. It consists of pairs of keys and their corresponding values.

```python
>>> fruits = dict()
>>> fruits['apples'] = 3
>>> fruits['peers'] = 5
>>> fruits['tomatoas'] = 1
```

`fruits['apples']` is a way to get the value - i.e. 3, of the `apple` key. However, an error is sent if the key is unknown, like `fruits[bananas]`. Alternatively, the `get` function can be used, like `fruits.get("bananas", 0)` that returns 0 instead of an error.

The next example is showing how use a simple dictionary:

```python
>>> for key in fruits:
...     value = fruits.get(key, 0)
...     if value < 3:
...         print("You have to buy new {:s}".format(key))
...
You have to buy new tomatoes.
```

To learn more about data structures and how to manage them, get access to the Python documentation

## 6.3 Scripting with Python

This section describes how to create simple Python lines of code in separated files commonly called *scripts*, and run them. Some practical exercises, appropriate to the content of each action, are proposed and test exercises are suggested at the end of the section.

To practice, you have first to create a new folder in your computer - on your Desktop for example; with name "pythonscripts" for example, and to execute the python IDLE.

For an advanced use of Python, the installation of a dedicated IDE is very useful. SPPAS is developed with PyCharm: See the PyCharm Help webpage
### 6.3.1 Comments and documentation

Comments are not required by the program to work. But comments are necessary! Comments are expected to be appropriate, useful, relevant, adequate and always reasonable.

```python
# This script is doing this and that.
# It is under the terms of a license.
# and I can continue to write what I want after the # symbol
# except that it's not the right way to tell the story of my life
```

The documentation of a program complements the comments. Both are not sharing the same goal: comments are used in all kind of programs but documentation is appended to comments for the biggest programs and/or projects. Documentation is automatically extracted and formatted thanks to dedicated tools. Documentation is required for sharing the program. See the Docstring Conventions for details. Documentation must follow a convention like for example the markup language reST - reStructured Text. Both conventions are used into SPPAS API, programs and scripts.

### 6.3.2 Getting started with scripting in Python

In the IDLE, create a new empty file either by clicking on "File" menu, then "New File", or with the shortcut "CTRL"+N.

Copy the following line of code in this newly created file:

```python
print("Hello world!")
```

Hello world! in a Python script

Then, save the file in the "pythonscripts" folder. By convention, Python source files end with a .py extension, and so the name `01_helloworld.py` could be fine.

To execute the program, you can do one of:

* with the mouse: Click on the Menu "Run", then "Run module"

* with the keyboard: Press F5

The expected output is as follow:

Output of the first script

A better practice while writing scripts is to describe by who, what and why this script was done. A nifty trick is to create a skeleton for any future script that will be written. Such ready-to-use script is available in the SPPAS package with the name `skeleton.py`.

### 6.3.3 Blocks

Blocks in Python are created from the indentation. Tab and spaces can be used but using spaces is recommended.

```python
>>> if a == 3:
...     # this is a block using 4 spaces for indentation
...     print("a is 3")
```
### 6.3.4 Functions

#### Simple function

A function does something: it stats with its definition then is followed by its lines of code in a block.

Here is an example of function:

```python
def print_vowels():
    """ Print the list of French vowels on the screen. """
    vowels = ['a', 'e', 'E', 'i', 'o', 'u', 'y', '@', '2', '9', 'a~', 'o~, 'U~']
    print("List of French vowels:")
    for v in vowels:
        print(v)
```

What the `print_vowels()` function is doing? This function declares a list with name `vowels`. Each item of the list is a string representing a vowel in French encoded in X-SAMPA. Of course, this list can be overridden with any other set of strings. The next line prints a message. Then, a loop prints each item of the list.

At this stage, if a script with this function is executed, it will do... nothing! Actually, the function is created, but it must be invoked in the main function to be interpreted by Python. The `main` is as follow:

```python
if __name__ == '__main__':
    print_vowels()
```

**Practice:** create a copy of the file `skeleton.py`, then make a function to print "Hello World!".
(solution: `ex01_hello_world.py`).

**Practice:** Create a function to print plosives and call it in the main function (solution: `ex02_functions.py`).

Output of the second script

One can also create a function to print glides, another one to print affricates, and so on. Hum... this sounds a little bit fastidious!

#### Function with parameters

Rather than writing the same lines of code with only a minor difference over and over, we can declare *parameters* to the function to *make it more generic*. Notice that the number of parameters of a function is not limited!

In the example, we can replace the `print_vowels()` function and the `print_plosives()` function by a single function `print_list(mylist)` where `mylist` can be any list containing strings or characters. If the list contains other typed-variables like numerical values, they must be converted to string to be printed out. This can result in the following function:
```python
def print_list(mylist, message=" -"):
    """ Print a list on the screen.

        :param mylist: (list) the list to print
        :param message: (string) an optional message to print before each element

    """
    for item in mylist:
        print("{:s} {:s}".format(message, item))
```

## Function return values

Functions are used to do a specific job and the result of the function can be captured by the program. In the following example, the function would return a boolean value, i.e. True if the given string has no character.

```python
def is_empty(mystr):
    """ Return True if mystr is empty. """

    return len(mystr.strip()) == 0
```

**Practice:** Add this function in a new script and try to print various lists (solution: `ex03_functions.py`)

Expected output of the 3rd script

### 6.3.5 Reading/Writing files

#### Reading data from a file

Now, we'll try to get data from a file. Create a new empty file with the following lines - and add as many lines as you want; then, save it with the name "phonemes.csv" by using UTF-8 encoding:

```
oclusive s ; b ; b
oclusive s ; d ; d
fricative s ; f ; f
liquid s ; l ; l
nasal s ; m ; m
nasal s ; n ; n
oclusive s ; p ; p
glide s ; w ; w
vowel s ; a ; a
vowel s ; e ; e
```

The following statements are typical statements used to read the content of a file. The first parameter of the `open` function is the name of the file, including the path (relative or absolute); and the second argument is the opening mode ('r' is the default value, used for reading).

**Practice:** Add these lines of code in a new script and try it (solution: `ex04_readings_simple.py`)
```python
fp = open("phonemes.csv", 'r')
for line in fp:
    # do something with the line stored in variable l
    print(line.strip())
f.close()
```

21

22

23

24

25

The following is a solution with the ability to deal with various file encodings, thanks to the `codecs` library:

```python
def read_file(filename):
    """ Get the content of file.

        :param filename: (string) Name of the file to read, including path.
        :returns: List of lines

    """
    with codecs.open(filename, 'r', encoding="utf8") as fp:
        return fp.readline()
```

21

22

23

24

25

26

27

28

29

In the previous code, the `codecs.open` functions got 3 parameters: the name of the file, the mode to open, and the encoding. The `readlines()` function gets each line of the file and store it into a list.

**Practice:** Write a script to print the content of a file (solution: `ex05_readings_file.py`)

Notice that Python `os` module provides useful methods to perform file-processing operations, such as renaming and deleting. See Python documentation for details: https://docs.python.org/3.8/

## Writing data to a file

Writing a file requires to open it in a writing mode:

* 'w' is the mode to write data; it will erase any existing file;

* 'a' is the mode to append data in an existing file.

A file can be opened in an encoding and saved in another one. This could be useful to write a script to convert the encoding of a set of files. The following could help to create such script:

```python
# getting all files of a given folder:
path = 'C:\Users\Me\data'
dirs = os.listdir( path )
```

10

11

12

```python
# Converting the encoding of a file:
file_stream = codecs.open(file_location, 'r', file_encryption)
file_output = codecs.open(file_location+'utf8', 'w', 'utf-8')

for line in file_stream:
    file_output.write(line)
```

15

16

17

18

19

20
### 6.3.6 Python tutorials

Here is a list of web sites with tutorials, from the easiest to the most complete:

1. Learn Python, by DataCamp

2. Tutorial Points

3. The Python documentation

### 6.3.7 Exercises to practice

Exercise 1: How many vowels are in a list of phonemes? (solution: ex06_list.py)

Exercise 2: Write a X-SAMPA to IPA converter. (solution: ex07_dict.py)

Exercise 3: Compare 2 sets of data using NLP techniques (Zipf law, Tf.Idf) (solution: ex08_counter.py)

## 6.4 anndata, an API to manage annotated data

### 6.4.1 Overview

We are now going to write Python scripts using the `anndata` API included in SPPAS. This API is useful to read/write and manipulate files annotated from various annotation tools like SPPAS, Praat or Elan.

First of all, it is important to understand the data structure included into the API to be able to use it efficiently.

### 6.4.2 Why developing a new API?

In the Linguistics field, multimodal annotations contain information ranging from general linguistic to domain specific information. Some are annotated with automatic tools, and some are manually annotated. In annotation tools, annotated data are mainly represented in the form of “tiers” or “tracks” of annotations. Tiers are mostly series of intervals defined by:

* two time points to represent the beginning and the end of the interval;

* a label to represent the annotation itself.

Of course, depending on the annotation tool, the internal data representation and the file formats are different. In Praat, tiers can be represented either by a single point in time (such tiers are named PointTiers) or two (IntervalTiers) In Elan, points are not supported; but contrariwise to Praat, unlabelled intervals are not represented nor saved.

The `anndata` API was designed to be able to manipulate all data in the same way, regardless of the file type. It supports to merge data and annotations from a wide range of heterogeneous data sources.