o
    Xεi71                     @   sj   d Z ddlZddlZddlmZ ddlmZ ddlmZ G dd dej	Z
dd	 Zed
kr3e  dS dS )zTests for SSML    N)	sentences)_DIRprint_graphc                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )SSMLTestCasezTest cases for SSMLc                 C   .   d}dd t |ddD }| |g d dS )z Test SSML example from Wikipediau:  <?xml version="1.0"?>
<speak xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:dc="http://purl.org/dc/elements/1.1/"
       version="1.0">
  <metadata>
    <dc:title xml:lang="en">Telephone Menu: Level 1</dc:title>
  </metadata>

  <p>
    <s xml:lang="en-US">
      <voice name="David" gender="male" age="25">
        For English, press <emphasis>one</emphasis>.
      </voice>
    </s>
    <s xml:lang="es-MX">
      <voice name="Miguel" gender="male" age="25">
        Para español, oprima el <emphasis>dos</emphasis>.
      </voice>
    </s>
  </p>

</speak>c                 S   .   g | ]}|D ]}|j |j|j|j|jfqqS  )sent_idxidxlangvoicetext.0sentwr	   r	   C/home/ubuntu/.local/lib/python3.10/site-packages/tests/test_ssml.py
<listcomp>'       z7SSMLTestCase.test_wikipedia_example.<locals>.<listcomp>Tssml))r   r   en-USDavidFor)r      r   r   English)r      r   r   ,)r      r   r   press)r      r   r   one)r      r   r   .)r   r   es-MXMiguelPara)r   r   r%   r&   u   español)r   r   r%   r&   r   )r   r   r%   r&   oprima)r   r!   r%   r&   el)r   r#   r%   r&   dos)r      r%   r&   r$   Nr   assertEqualselfr   resultsr	   r	   r   test_wikipedia_example   s   
z#SSMLTestCase.test_wikipedia_examplec                 C   r   )zTest lang on <s>uL  <?xml version="1.0" encoding="ISO-8859-1"?>
    <speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                    http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
        xml:lang="en-US">
    <s>Today, 2/1/2000.</s>
    <!-- Today, February first two thousand -->
    <s xml:lang="it">Un mese fà, 2/1/2000.</s>
    <!-- Un mese fà, il due gennaio duemila -->
    <!-- One month ago, the second of January two thousand -->
    </speak>c                 S   *   g | ]}|D ]}|j |j|j|jfqqS r	   r
   r   r   r   r   r	   r	   r   r   O       z,SSMLTestCase.test_lang_s.<locals>.<listcomp>Tr   ))r   r   r   Today)r   r   r   r   )r   r   r   February)r   r   r   first)r   r!   r   r   )r   r#   r   two)r   r+   r   thousandr      r   r$   )r   r   itUn)r   r   r<   mese)r   r   r<   u   fà)r   r   r<   r   )r   r!   r<   due)r   r#   r<   gennaio)r   r+   r<   duemila)r   r;   r<   r$   Nr,   r.   r	   r	   r   test_lang_s@   s   
zSSMLTestCase.test_lang_sc              	   C   s:   d}dd t |ddD }| |ddddg d	fg d
S )zTest manual phoneme insertionu  <?xml version="1.0"?>
<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="en-US">
  <phoneme alphabet="ipa" ph="t&#x259;mei&#x325;&#x27E;ou&#x325;"> tomato </phoneme>
  <!-- This is an example of IPA using character entities -->
  <!-- Because many platform/browser/text editor combinations do not
       correctly cut and paste Unicode text, this example uses the entity
       escape versions of the IPA characters.  Normally, one would directly
       use the UTF-8 representation of these symbols: "təmei̥ɾou̥". -->
</speak>c                 S   r   r	   )r
   r   r   r   phonemesr   r	   r	   r   r   |   r   z-SSMLTestCase.test_phoneme.<locals>.<listcomp>Tr   r   r   tomatot   əmeu   i̥u   ɾou   u̥Nr,   r.   r	   r	   r   test_phonemel   s   
zSSMLTestCase.test_phonemec                 C   r   )zTest <s>a  <?xml version="1.0"?>
<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="en-US">
  <p>
    <s>This is the first sentence of the paragraph.</s>
    <s>Here's another sentence.</s>
  </p>
</speak>c                 S   &   g | ]}|D ]
}|j |j|jfqqS r	   r
   r   r   r   r	   r	   r   r          z/SSMLTestCase.test_sentences.<locals>.<listcomp>Tr   ))r   r   This)r   r   is)r   r   the)r   r   r7   )r   r!   sentence)r   r#   of)r   r+   rQ   )r   r;   	paragraph)r      r$   )r   r   zHere's)r   r   another)r   r   rR   )r   r   r$   Nr,   r.   r	   r	   r   test_sentences   s   
zSSMLTestCase.test_sentencesc                 C   r   )zTest explicit tokenizationu  <?xml version="1.0"?>
<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="zh-CN">

  <!-- The Nanjing Changjiang River Bridge -->
  <token>南京市</token><token>长江大桥</token>。
  <!-- The mayor of Nanjing city, Jiang Daqiao -->
  南京市长<w>江大桥</w>。
  <!-- Shanghai is a metropolis -->
  上海是个<w>大都会</w>。
  <!-- Most Shanghainese will say something like that -->
  上海人<w>大都</w>会那么说。
</speak>c                 S   rL   r	   rM   r   r	   r	   r   r      rN   z+SSMLTestCase.test_token.<locals>.<listcomp>Tr   ))r   r   u	   南京市)r   r   u   长江大桥)r   r      。)r   r   u   南)r   r   u   京)r   r   u   市)r   r   u   长)r   r!   u	   江大桥)r   r#   rX   )r   r      上)r   r      海)r   r   u   是)r   r   u   个)r   r!   u	   大都会)r   r#   rX   )r   r   rY   )r   r   rZ   )r   r   u   人)r   r   u   大都)r   r!   u   会)r   r#   u   那)r   r+   u   么)r   r;   u   说)r   rU   rX   Nr,   r.   r	   r	   r   
test_token   s   
zSSMLTestCase.test_tokenc                 C   r   )z
Test <sub>a  <?xml version="1.0"?>
<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="en-US">
  <sub alias="World Wide Web Consortium">W3C</sub> is an international community
  <!-- World Wide Web Consortium -->
</speak>c                 S   rL   r	   rM   r   r	   r	   r   r      rN   z)SSMLTestCase.test_sub.<locals>.<listcomp>Tr   ))r   r   World)r   r   Wide)r   r   Web)r   r   
Consortium)r   r!   rP   )r   r#   an)r   r+   international)r   r;   	communityNr,   r.   r	   r	   r   test_sub      

zSSMLTestCase.test_subc                 C   r   )zTest <lang>a  <?xml version="1.0"?>
<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="en-US">
  The French word for cat is <w xml:lang="fr">chat</w>.
  He prefers to eat pasta that is <lang xml:lang="it">al dente</lang>.
</speak>c                 S   r2   r	   r3   r   r	   r	   r   r     r4   z2SSMLTestCase.test_lang_element.<locals>.<listcomp>Tr   ))r   r   r   The)r   r   r   French)r   r   r   word)r   r   r   for)r   r!   r   cat)r   r#   r   rP   )r   r+   frchatr:   )r   r   r   He)r   r   r   prefers)r   r   r   to)r   r   r   eat)r   r!   r   pasta)r   r#   r   that)r   r+   r   rP   )r   r;   r<   al)r   rU   r<   dente)r   	   r   r$   Nr,   r.   r	   r	   r   test_lang_element  rd   zSSMLTestCase.test_lang_elementc              	   C   sN   d}dd t |ddD }| |ddg dfddg d	fdd
g dfg dS )zTest <lexicon> and <lookup>u}  <?xml version="1.0"?>
<speak version="1.1"
       xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="en-US">

  <lexicon xml:id="test" alphabet="ipa">
    <lexeme>
      <grapheme>
        tomato
      </grapheme>
      <phoneme>
        <!-- Individual phonemes are separated by whitespace -->
        t ə m ˈɑ t oʊ
      </phoneme>
    </lexeme>
    <lexeme role="fake-role">
      <grapheme>
        tomato
      </grapheme>
      <phoneme>
        <!-- Made up pronunciation for fake word role -->
        t ə m ˈi t oʊ
      </phoneme>
    </lexeme>
  </lexicon>

  <w>tomato</w>
  <lookup ref="test">
    <w>tomato</w>
    <w role="fake-role">tomato</w>
  </lookup>
</speak>c                 S   rL   r	   r
   r   rC   r   r	   r	   r   r   W  rN   z-SSMLTestCase.test_lexicon.<locals>.<listcomp>Tr   r   )rF   rG   rH   u   ˈeɪrF      oʊr   )rF   rG   rH   u   ˈɑrF   rw   r   )rF   rG   rH   u   ˈirF   rw   Nr,   r.   r	   r	   r   test_lexicon1  s   $
zSSMLTestCase.test_lexiconc                 C   sP   t jd d  }d| d}dd t|ddD }| |d	d	g d
fg dS )zTest <lexicon> from URIetczsample_lexicon.xmlap  <?xml version="1.0"?>
<speak version="1.1"
       xmlns="http://www.w3.org/2001/10/synthesis"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.w3.org/2001/10/synthesis
                 http://www.w3.org/TR/speech-synthesis11/synthesis.xsd"
       xml:lang="en-US">

  <lexicon xml:id="test" alphabet="ipa" uri="file://zB" />

  <lookup ref="test">
    <w>tomato</w>
  </lookup>
</speak>c                 S   rL   r	   rv   r   r	   r	   r   r   y  rN   z6SSMLTestCase.test_lexicon_external.<locals>.<listcomp>Tr   r   rE   N)r   parentabsoluter   r-   )r/   lexicon_pathr   r0   r	   r	   r   test_lexicon_externalf  s   
z"SSMLTestCase.test_lexicon_externalN)__name__
__module____qualname____doc__r1   rB   rK   rW   r[   rc   ru   rx   r}   r	   r	   r	   r   r      s    2,'9 *5r   c                 C   s   t | |dd d dS )zPrint graph to stderrc                  W   s   t | dtjiS )Nfile)printsysstderr)pr	   r	   r   <lambda>  s    z$print_graph_stderr.<locals>.<lambda>)
print_funcNr   )graphrootr	   r	   r   print_graph_stderr  s   r   __main__)r   r   unittestgruutr   gruut.resourcesr   gruut.utilsr   TestCaser   r   r~   mainr	   r	   r	   r   <module>   s     {