Auto-CS 2.2

https://sourceforge.net/projects/autocs/

Module sppas.src.annotations.CuedSpeech.whatkey

Class CueingWordKeys

Description

Generates Cued Speech keys for given tokens and their pronunciations.

Unlike :class:sppasWhatKeyPredictor, which works on time-aligned phoneme tiers, this class works directly on pronunciation strings (e.g. from a pronunciation dictionary), without requiring any time alignment.

Constructor

__init__

Create a new instance.

Parameters
  • cued_rules: (CuedSpeechKeys) The rules of the cued speech.
View Source
def __init__(self, cued_rules: CuedSpeechKeys):
    """Create a new instance.

    :param cued_rules: (CuedSpeechKeys) The rules of the cued speech.

    """
    if isinstance(cued_rules, CuedSpeechKeys) is False:
        raise TypeError(f'Given cued_rules must be a CuedSpeechKeys object. Got {type(cued_rules)} instead.')
    self.__cs = cued_rules
    self.__cue_tokenizer = CueingPronTokenizer(self.__cs)
    self.__keys_by_token = CueingKeysByToken()
    self._stops = list(symbols.phone.keys())
    self._stops.append('#')
    self._stops.append('*')
    self._stops.append('@@')
    self._stops.append('+')
    self._stops.append('sil')
    self._stops.append('sp')
    self._stops.append('gb')
    self._stops.append('lg')
    self._stops.append('fp')
    self._stops.append('dummy')
    self._stops.append('noise')
    self._stops.append('laugh')

Public functions

annotate

Return the sequence of keys from the list of tokens and their pronunciations.

Input tokens: ["test", "hello"] Input prons: ['t-E-s-t', 'E-l-o'] Code result: [('5-c.3-s.5-c.6-s', 't-E.s-vnil.t-E.l-o')] Returned keys by token: (('5-c.3-s', '5-c.6-s'), ('t-E.s-vnil', 't-E.l-o'))

Parameters
  • tokens: (list) List of tokens
  • prons: (list) List of pronunciations
Raises
  • TypeError: Invalid text type.
Returns
  • tuple(str) List of keys
View Source
def annotate(self, tokens: list, prons: list) -> tuple:
    """Return the sequence of keys from the list of tokens and their pronunciations.

        Input tokens: ["test", "hello"]
        Input prons: ['t-E-s-t', 'E-l-o']
        Code result: [('5-c.3-s.5-c.6-s', 't-E.s-vnil.t-E.l-o')]
        Returned keys by token: (('5-c.3-s', '5-c.6-s'), ('t-E.s-vnil', 't-E.l-o'))

        :param tokens: (list) List of tokens
        :param prons: (list) List of pronunciations
        :raises: TypeError: Invalid text type.
        :return: tuple(str) List of keys

        """
    if type(prons) not in (list, tuple):
        raise TypeError(f"Given pronunciations must be a list. Got '{type(prons)}' instead.")
    if type(tokens) not in (list, tuple):
        raise TypeError(f"Given tokens must be a list. Got '{type(tokens)}' instead.")
    cued = self._cuer(prons)
    normalized_word_phonemes = self.__cue_tokenizer.normalize_word_phonemes(tuple(prons))
    (codes, phons) = self.__keys_by_token.segment(normalized_word_phonemes, cued)
    return (codes, phons)

Private functions

_cuer

Return the result of "CuedSpeech" on the given phonetized text.

Parameters
  • token_prons: (list) Pronunciation of each token.
Returns
  • (list) List of keys
View Source
def _cuer(self, token_prons: list) -> list:
    """Return the result of "CuedSpeech" on the given phonetized text.

        :param token_prons: (list) Pronunciation of each token.
        :return: (list) List of keys

        """
    results = list()
    prons = list()
    for token_pron in token_prons:
        prons.extend(token_pron.split('-'))
    phonemes = list()
    for p in prons:
        if p in self._stops:
            if len(phonemes) > 0:
                sgmts = self.__cs.syllabify(phonemes)
                phons = self.__cs.phonetize_syllables(phonemes, sgmts)
                keys = self.__cs.keys_phonetized(phons)
                results.append((keys, phons))
                phonemes = list()
            if p in ('#', 'sil', 'lg', 'laugh'):
                results.append(('0-n', 'cnil-' + p))
            else:
                results.append(('0-s', 'cnil-' + p))
        else:
            phonemes.append(p)
    if len(phonemes) > 0:
        sgmts = self.__cs.syllabify(phonemes)
        phons = self.__cs.phonetize_syllables(phonemes, sgmts)
        keys = self.__cs.keys_phonetized(phons)
        results.append((keys, phons))
    return results