static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error) { SCrfSuiteUttProc *crfsuiteProc = (SCrfSuiteUttProc*)self; const SObject* filepath; S_CLR_ERR(error); s_bool isPresent = SUttProcessorFeatureIsPresent (self, "model_file", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SUtteranceFeatureIsPresent\" failed")) return; if (isPresent) { const SObject * vcfgObject = SVoiceGetFeature(voice, "config_file", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SVoiceGetFeature\" failed, failed to get voice config file")) return; const char * voice_base_path = s_get_base_path(SObjectGetString(vcfgObject, error), error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"s_get_base_path/SObjectGetString\" failed")) return; filepath = SUttProcessorGetFeature (self, "model_file", error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SUtteranceGetFeature\" failed")) return; const char * path = SObjectGetString (filepath, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SObjectGetString\" failed")) return; crfsuiteProc->model_file = s_path_combine(voice_base_path, path, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"s_path_combine\" failed")) return; } else { S_CTX_ERR(error, S_FAILURE, "Initialize", "Failed to load the CRFSuite model."); return; } return; S_UNUSED(voice); }
static void s_get_phrasing_symbols(const SUttProcessor *uttProc, const char **end_punc, s_erc *error) { s_bool have_symbols; const SMap *phrasingSymbols; const char *symbols; S_CLR_ERR(error); /* set to default for now */ *end_punc = s_default_phrasing_end_punc_chars; /* check if symbols are defined */ have_symbols = SUttProcessorFeatureIsPresent(uttProc, "phrasing symbols", error); if (S_CHK_ERR(error, S_CONTERR, "s_get_phrasing_symbols", "Call to \"SUttProcessorFeatureIsPresent\" failed")) return; if (!have_symbols) return; /* no tokenizer symbols defined */ phrasingSymbols = S_CAST(SUttProcessorGetFeature(uttProc, "phrasing symbols", error), SMap, error); if (S_CHK_ERR(error, S_CONTERR, "s_get_phrasing_symbols", "Failed to get 'phrasing symbols' SMap feature")) return; /* check if we have 'end-punctuation' symbols */ have_symbols = SMapObjectPresent(phrasingSymbols, "end-punctuation", error); if (S_CHK_ERR(error, S_CONTERR, "s_get_phrasing_symbols", "Call to \"SMapObjectPresent\" failed")) return; if (have_symbols) { /* get them and set it in end_punc */ symbols = SObjectGetString(SMapGetObject(phrasingSymbols, "end-punctuation", error), error); if (S_CHK_ERR(error, S_CONTERR, "s_get_phrasing_symbols", "Failed to get 'end-punctuation' symbols")) return; *end_punc = symbols; } }
static void Run(const SUttProcessor *self, SUtterance *utt, s_erc *error) { SG2P *g2p = NULL; SLexicon *lexicon = NULL; SAddendum *addendum = NULL; SSyllabification *syllab = NULL; const SRelation *wordRel; SRelation *syllableRel = NULL; SRelation *sylStructRel = NULL; SRelation *segmentRel = NULL; SItem *wordItem; SItem *wordItemcopy; char *downcase_word; SList *phones; s_bool syllabified; SList *syllablesPhones; SItem *sylStructureWordItem; SItem *syllableItem; SItem *sylStructSylItem; SItem *segmentItem; SIterator *sylItr = NULL; SIterator *phoneItr = NULL; const SObject *phone; s_bool is_present; S_CLR_ERR(error); s_get_lexical_objects(self, utt, &g2p, &lexicon, &addendum, &syllab, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_get_lexical_objects\" failed")) goto quit_error; /* we require the word relation */ is_present = SUtteranceRelationIsPresent(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit_error; if (!is_present) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to find 'Word' relation in utterance"); goto quit_error; } wordRel = SUtteranceGetRelation(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceGetRelation\" failed")) goto quit_error; /* create relations */ syllableRel = SUtteranceNewRelation(utt, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; sylStructRel = SUtteranceNewRelation(utt, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; segmentRel = SUtteranceNewRelation(utt, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; /* start at the first item in the word relation, cast away * const, we want to add daughter items. * iterate over the word relation and fill in the * phones and the associated structure. */ wordItem = (SItem*)SRelationHead(wordRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; wordItemcopy = (SItem*)SRelationHead(wordRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; while (wordItem != NULL) { /* get word and downcase it */ downcase_word = s_strlwr(s_strdup(SItemGetName(wordItem, error), error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to down-case word item")) goto quit_error; if (downcase_word == NULL || s_strcmp(downcase_word, "", error) == 0) goto continue_cycle; phones = NULL; syllabified = FALSE; /* get phone sequence for word */ if (addendum != NULL) { phones = S_ADDENDUM_CALL(addendum, get_word)(addendum, downcase_word, NULL, &syllabified, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"get_word\" (SAddendum) failed")) goto quit_error; } if ((phones == NULL) && (lexicon != NULL)) { phones = S_LEXICON_CALL(lexicon, get_word)(lexicon, downcase_word, NULL, &syllabified, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"get_word\" (SLexicon) failed")) goto quit_error; } if ((phones == NULL) && (g2p != NULL)) { phones = S_G2P_CALL(g2p, apply)(g2p, downcase_word, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"apply\" (SG2P) failed")) goto quit_error; } if (phones == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get phone sequence for word '%s'", downcase_word); S_FREE(downcase_word); continue; } S_FREE(downcase_word); /* syllabify phone sequence */ if (syllabified == FALSE) { if (syllab != NULL) { syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab, wordItem, phones, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"syllabify\" failed")) goto quit_error; S_DELETE(phones, "Run", error); } else { syllablesPhones = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to create new 'SList' object")) goto quit_error; SListAppend(syllablesPhones, S_OBJECT(phones), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SListAppend\" failed")) goto quit_error; } } else syllablesPhones = (SList*)phones; /* create new syllable structure word item, shares content * with word item. */ sylStructureWordItem = SRelationAppend(sylStructRel, wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; /* iterate over syllables */ sylItr = S_ITERATOR_GET(syllablesPhones, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_ITERATOR_GET\" failed")) goto quit_error; while (sylItr != NULL) { /* new item in syllable relation */ syllableItem = SRelationAppend(syllableRel, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; SItemSetName(syllableItem, "syl", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetName\" failed")) goto quit_error; /* daughter of above item, but in SylStructure */ sylStructSylItem = SItemAddDaughter(sylStructureWordItem, syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAddDaughter\" failed")) goto quit_error; /* iterate over phones and add segments */ phoneItr = S_ITERATOR_GET((SList*)SIteratorObject(sylItr, error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_ITERATOR_GET/SIteratorObject\" failed")) goto quit_error; while (phoneItr != NULL) { phone = SIteratorObject(phoneItr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SIteratorObject\" failed")) goto quit_error; segmentItem = SRelationAppend(segmentRel, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; SItemSetName(segmentItem, SObjectGetString(phone, error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetName/SObjectGetString\" failed")) goto quit_error; SItemAddDaughter(sylStructSylItem, segmentItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAddDaughter\" failed")) goto quit_error; phoneItr = SIteratorNext(phoneItr); } sylItr = SIteratorNext(sylItr); } S_DELETE(syllablesPhones, "Run", error); continue_cycle: wordItem = SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } wordItem = wordItemcopy; if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToItem\" failed")) goto quit_error; while (wordItem != NULL) { const SFeatProcessor* featproc = SUttProcessorGetFeature(self, "_stress_func", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUttProcessorGetFeature\" failed")) goto quit_error; s_compute_stresses(featproc, wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_compute_stresses\" failed")) goto quit_error; s_compute_phonetic_features(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_compute_phonetic_features\" failed")) goto quit_error; wordItem = SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } /* here all is OK */ return; /* error clean-up code */ quit_error: if (syllableRel != NULL) { SUtteranceDelRelation(utt, "Syllable", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (sylStructRel != NULL) { SUtteranceDelRelation(utt, "SylStructure", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (segmentRel != NULL) { SUtteranceDelRelation(utt, "Segment", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (sylItr != NULL) S_DELETE(sylItr, "Run", error); if (phoneItr != NULL) S_DELETE(phoneItr, "Run", error); self = NULL; }