Example #1
0
static SObject *MapPyValUnlink(SMap *self, const char *key, s_erc *error)
{
	const SMapPy *pMap = (const SMapPy *)self;
	PyObject *pKey;
	PyObject *pobject = NULL;
	SObject *tmp;


	S_CLR_ERR(error);
	S_CHECK_PY_MAP(pMap, "MapPyValUnlink");

	pKey = s_set_pyobject_str(key, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "MapPyValUnlink",
				  "Call to \"s_set_pyobject_str\" failed"))
		goto error;

	pobject = PyObject_GetItem(S_PY_DICT(pMap), pKey);
	if (pobject == NULL)
	{
		char *py_error = s_get_python_error_str();

		if (py_error)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValUnlink",
					  "Call to \"PyObject_GetItem\" failed. Reported error: %s",
					  py_error);
			S_FREE(py_error);
		}
		else
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValUnlink",
					  "Call to \"PyObject_GetItem\" failed");
		}

		goto error;
	}

	if (PyObject_DelItem(S_PY_DICT(pMap), pKey) == -1)
	{
		char *py_error = s_get_python_error_str();

		if (py_error)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValUnlink",
					  "Call to \"PyObject_DelItem\" failed. Reported error: %s",
					  py_error);
			S_FREE(py_error);
		}
		else
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValUnlink",
					  "Call to \"PyObject_DelItem\" failed");
		}

		goto error;
	}

	/* decrement reference of pKey */
	Py_XDECREF(pKey);

	/* convert to Speect object type */
	tmp = s_pyobject_2_sobject(pobject, error);

	/* decrement reference of pobject */
	Py_XDECREF(pobject);

	/* all ok */
	return tmp;


error:
	/* decrement reference of pKey */
	Py_XDECREF(pKey);

	/* decrement reference of pobject */
	Py_XDECREF(pobject);

	/* for S_CHECK_PY_MAP */
failure:
	return NULL;
}
Example #2
0
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SItem *itrItem;
	sint32 count;

	SWordsToNextPuncFeatProc *castSelf = S_CAST(self, SWordsToNextPuncFeatProc, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to S_CAST failed"))
		goto quit_error;

	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	itrItem = SItemPathToItem (item, "R:Token.parent", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemPathToItem\" failed"))
		goto quit_error;

	SMap* posPunctuation = S_CAST( SMapGetObject ( castSelf->symbols, "pos punctuation", error ), SMap, error );
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SMapGetObject\" failed"))
		goto quit_error;
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"S_CAST\" failed"))
		goto quit_error;

	count = -1;
	s_bool found = FALSE;

	while (found == FALSE && itrItem != NULL)
	{
		count++;

		s_bool hasPos = SItemFeatureIsPresent ( itrItem, "POS", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemFeatureIsPresent\" failed"))
			goto quit_error;

		if (hasPos)
		{
			const char* keyPos = SItemGetString (itrItem, "POS", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemGetString\" failed"))
				goto quit_error;

			found= SMapObjectPresent(posPunctuation, keyPos, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SMapObjectPresent\" failed"))
				goto quit_error;
		}

		itrItem = SItemNext(itrItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			goto quit_error;
	}

	extractedFeat = SObjectSetInt(count, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetInt\" failed"))
		goto quit_error;

	/* all OK here */
	return extractedFeat;

	S_UNUSED(self);

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;
}
Example #3
0
int main(void)
{
	s_erc error = S_SUCCESS; /* start of with a clean slate */
	int i;
	int *tmp;


	/* initialize speect */
	error = speect_init(NULL);
	if (error != S_SUCCESS)
	{
		printf("Failed to initialize Speect\n");
		return 1;
	}

	for (i = 0; i < 3; i++)
	{
		if (i == 0)
		{
			/* clear the error variable */
			S_CLR_ERR(&error);

			/* change the debugging level */
			s_set_errdbg_level(S_DBG_INFO, &error);

			/* check error and continue it */
			S_CHK_ERR(&error, S_CONTERR,
				     "main",
				     "Failed to set debug level, trying to continue");

			tmp = make_numbers(i, &error);

			/* check error from make_numbers and set a new error and context */
			if (S_CHK_ERR(&error, S_FAILURE,
					 "main",
					 "Number is not valid"))
			{
				/* debug with S_DBG_INFO level */
				S_DEBUG(S_DBG_INFO, "Found error with i = %d", 1);

				if (tmp != NULL)
					S_FREE(tmp);
			}

			if (tmp != NULL)
				S_FREE(tmp);

			continue;
		}

		if (i == 1)
			/* set an new error with a context */
			S_CTX_ERR(&error, S_FAILURE,
				     "main",
				     "i = %d, is invalid", i);
		else
		{
			/* clear the error variable */
			S_CLR_ERR(&error);

			tmp = make_numbers(i, &error);

			/* check error from make_numbers and set a new error and context */
			if (S_CHK_ERR(&error, S_FAILURE,
					 "main",
					 "Number is not valid"))
			{
				/*
				 * debug with S_DBG_TRACE level,
				 * this debug will not do anything as it's level
				 * is higher than the debug level set at i = 0
				 */
				S_DEBUG(S_DBG_TRACE, "Found error with i = %d", 1);

				if (tmp != NULL)
					S_FREE(tmp);
			}

			if (tmp != NULL)
				S_FREE(tmp);
		}
	}


	/* quit speect */
	error = speect_quit();
	if (error != S_SUCCESS)
	{
		printf("Call to 'speect_quit' failed\n");
		return 1;
	}

	return 0;
}
Example #4
0
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;
	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;

	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;
	}

	/* 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;
}
Example #5
0
static void read_col_data(SEbmlRead *reader, SMatrixFloat *self, uint32 row_counter, s_erc *error)
{
	uint32 id;
	s_bool container_exhausted;
	uint32 col_counter;


	S_CLR_ERR(error);

	/* read S_MATRIX_FLOAT_EBML_COL_DATA container */
	id = S_EBMLREAD_CALL(reader, container)(reader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_col_data",
				  "Call to SEbmlRead \"container\" failed"))
		return;

	col_counter = 0;
	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(reader, container_at_end)(reader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_col_data",
					  "Call to SEbmlRead \"container_at_end\" failed"))
			return;

		if (container_exhausted)
			break; /* we are finished reading the column data */

		/* peek id for column data elements */
		id = S_EBMLREAD_CALL(reader, peek_id)(reader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_col_data",
					  "Call to SEbmlRead \"peek_id\" failed"))
			return;

		switch(id)
		{
		case S_MATRIX_FLOAT_EBML_DATA_ELEMENT:
		{
			self->f[row_counter][col_counter++] = S_EBMLREAD_CALL(reader,
																  read_float)(reader,
																			  &id,
																			  error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_col_data",
						  "Call to SEbmlRead \"read_float\" failed"))
				return;

			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_col_data",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(reader, element_skip)(reader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_col_data",
						  "Call to SEbmlRead \"element_skip\" failed"))
				return;
		}
	}
}
Example #6
0
S_LOCAL void _s_load_voice_utterance_processors(const SMap *voiceConfig, SVoice *voice, s_erc *error)
{
	SMap *uttProcessors;
	const SObject *tmp;
	const SMap *voiceConfigUttProcessors;
	s_bool key_present;
	SIterator *itr;
	const char *uttproc_name;
	const char *uttproc_class;
	const char *uttproc_plugin;
	const SMap *uttProcInfo;
	const SMap *uttProcFeats;
	SUttProcessor *uProcessor;
	SPlugin *plugin;
	SList *uttProcPlugins;


	S_CLR_ERR(error);

	/* create a map container for utterance-processors */
	uttProcessors = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Failed to create new map for voice utterance-processors"))
		return;

	/* look for "utterance-processors" key in voiceConfig map */
	key_present = SMapObjectPresent(voiceConfig, "utterance-processors", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"SMapObjectPresent\" failed for \'utterance-processors\' key"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	if (!key_present)
	{
		/* no defined utterance-processors  */
		voice->uttProcessors = uttProcessors;
		return;
	}

	/* get utterance-processors from voiceConfig */
	tmp = SMapGetObject(voiceConfig, "utterance-processors", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"SMapGetObject\" failed"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	voiceConfigUttProcessors = S_CAST(tmp, SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"S_CAST (SMap)\" failed for \'utterance-processors\' object"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	/*
	 * iterate through the voiceConfigUttProcessors, create the
	 * utterance-processors and add their features (if any), and add
	 * them to the uttProcessors map
	 */
	itr = S_ITERATOR_GET(voiceConfigUttProcessors, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	if (itr)
	{
		/* create a plug-in list */
		uttProcPlugins = S_LIST(S_NEW(SListList, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Failed to create new list for voice utterance-processor plug-ins"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			return;
		}
	}
	else
		uttProcPlugins = NULL;

	while (itr)
	{
		/* the utterance-processor name */
		uttproc_name = SIteratorKey(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SIteratorKey\" failed"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* the utterance-processor info (SMap) */
		tmp = SIteratorObject(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uttProcInfo = S_CAST(tmp, SMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"S_CAST (SMap)\" failed for utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/*
		 * uttProcInfo must have "class" and "plug-in" and
		 * optionally "features"
		 */
		uttproc_class = SMapGetString(uttProcInfo, "class", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapGetString\" failed for \'class\' name of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uttproc_plugin = SMapGetString(uttProcInfo, "plug-in", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapGetString\" failed for \'plug-in\' name of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/*
		 * load the plug-in, add it to the list of utterance-processor plug-ins and create
		 * the utterance-processor object
		 */
		plugin = s_pm_load_plugin(uttproc_plugin, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"s_pm_load_plugin\" failed for utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		SListPush(uttProcPlugins, S_OBJECT(plugin), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SListPush\" failed for utterance-processor plug-ins"))
		{
			S_DELETE(plugin, "_s_load_voice_utterance_processors", error);
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uProcessor = S_UTTPROCESSOR(S_NEW_FROM_NAME(uttproc_class, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Failed to create new utterance-processor of class \'%s\'",
					  uttproc_class))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* add the utterance-processor to the map of utterance-processors */
		SMapSetObject(uttProcessors, uttproc_name, S_OBJECT(uProcessor), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapSetObject\" failed"))
		{
			S_DELETE(uProcessor, "_s_load_voice_utterance_processors", error);
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* Check if this utterance-processor has any defined features */
		key_present = SMapObjectPresent(uttProcInfo, "features", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapObjectPresent\" failed for \'features\' key of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		if (key_present)
		{
			/* get utterance-processors "features" */
			tmp = SMapGetObject(uttProcInfo, "features", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"SMapGetObject\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}

			uttProcFeats = S_CAST(tmp, SMap, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"S_CAST (SMap)\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}

			/* copy them to the utterance-processor */
			SMapCopy(uProcessor->features, uttProcFeats, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"SMapCopy\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}
		}

		/* initialize the utterance processor */
		SUttProcessorInit(&uProcessor, voice, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SUttProcessorInit\" failed for utterance-processor of class \'%s\'",
					  uttproc_class))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		itr = SIteratorNext(itr);
	}

	if (uttProcPlugins != NULL)
	{
		SListMerge(voice->plugins, uttProcPlugins, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SListMerge\" failed"))
		{
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
	}

	voice->uttProcessors = uttProcessors;
}
Example #7
0
static void s_get_lexical_objects(const SUttProcessor *self, SUtterance *utt,
								  SG2P **g2p, SLexicon **lexicon, SAddendum **addendum,
								  SSyllabification **syllab, s_erc *error)
{
	const SVoice *voice;


	S_CLR_ERR(error);

	voice = SUtteranceVoice(utt, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SUtteranceVoice\" failed"))
		return;

	*g2p = (SG2P*)SVoiceGetData(voice , "g2p", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	*lexicon = (SLexicon*)SVoiceGetData(voice , "lexicon", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	*addendum = (SAddendum*)SVoiceGetData(voice , "addendum", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	/* first try for syllabification in voice data, new method */
	*syllab = (SSyllabification*)SVoiceGetData(voice , "syllabification", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	/* if not found try old method */
	if ((*syllab) == NULL)
	{
		*syllab = (SSyllabification*)SMapGetObjectDef(self->features , "_syll_func", NULL,
													  error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_get_lexical_objects",
					  "Call to \"SMapGetObjectDef\" failed"))
			return;
	}

	/* now check for least requirements */
	if ((*addendum == NULL)
		&& (*lexicon == NULL)
		&& (*g2p == NULL))
	{
		S_CTX_ERR(error, S_FAILURE,
				  "s_get_lexical_objects",
				  "No grapheme to phoneme conversion options (lexicon, addendum, g2p) "
				  "found in voice");
		return;
	}
}
Example #8
0
static void Run(const SUttProcessor *self, SUtterance *utt,
				s_erc *error)
{
	SHTSEngineMESynthUttProc105 *HTSsynth = (SHTSEngineMESynthUttProc105*)self;
	SPlugin *audioPlugin;
	const SRelation *segmentRel;
	SAudio *audio = NULL;
	s_bool is_present;
	char **label_data = NULL;
	int label_size;
	const SItem *item;
	const SItem *itemItr;
	int counter;
	uint i;
	int frame;
	int state;
	const double rate = HTSsynth->engine.global.fperiod * 1e+7 / HTSsynth->engine.global.sampling_rate;
	int nstate;


	S_CLR_ERR(error);

	/* we require the segment relation */
	is_present = SUtteranceRelationIsPresent(utt, "Segment", 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 'Segment' relation in utterance");
		goto quit_error;
	}

	segmentRel = SUtteranceGetRelation(utt, "Segment", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceGetRelation\" failed"))
		goto quit_error;

	item = SRelationHead(segmentRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SRelationHead\" failed"))
		goto quit_error;

	itemItr = item;
	label_size = 0;
	while (itemItr != NULL)
	{
		label_size++;
		itemItr = SItemNext(itemItr, error);
	}

	label_data = S_CALLOC(char*, label_size);

	itemItr = item;
	counter = 0;
	while (itemItr != NULL)
	{
		SObject *dFeat;
		const char *tmp;


		dFeat = SItemPathToFeatProc(itemItr, "hts_labels", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemPathToFeatProc\" failed"))
			goto quit_error;

		if (dFeat == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "Run",
					  "Failed to generate hts labels for segment item");
			goto quit_error;
		}

		tmp = SObjectGetString(dFeat, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectGetString\" failed"))
			goto quit_error;

		label_data[counter++] = s_strdup(tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_strdup\" failed"))
			goto quit_error;

		SItemSetObject((SItem*)itemItr, "hts_label", dFeat, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemSetObject\" failed"))
			goto quit_error;

		itemItr = SItemNext(itemItr, error);
	}

	/* speech synthesis part */
	HTS_Engine_load_label_from_string_list(&(HTSsynth->engine), label_data, label_size);
	check_and_change_rate_volume(HTSsynth, utt, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"check_and_change_rate_volume\" failed"))
		goto quit_error;

	HTS_Engine_create_sstream(&(HTSsynth->engine));
	check_and_change_tone(HTSsynth, utt, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"check_and_change_tone\" failed"))
		goto quit_error;

	HTS_Engine_create_pstream(&(HTSsynth->engine));

	if (HTSsynth->me == TRUE) /* mixed excitation */
	{
		HTS_Engine_create_gstream_me(&(HTSsynth->engine),
									 HTSsynth->me_num_filters, HTSsynth->me_filter_order,
									 HTSsynth->me_filter, HTSsynth->xp_sig, HTSsynth->xn_sig,
									 HTSsynth->hp, HTSsynth->hn,
									 HTSsynth->pd_filter, HTSsynth->pd_filter_order);
	}
	else
	{
		HTS_Engine_create_gstream(&(HTSsynth->engine));
	}

	nstate = HTS_Speect_ModelSet_get_nstate(&(HTSsynth->engine));
	itemItr = item;
	counter = 0;
	frame = 0;
	state = 0;
	while (itemItr != NULL)
	{
		int j;
		int duration = 0;
		float tmp;

		for (j = 0; j < nstate; j++)
			duration += HTS_Speect_SStreamSet_get_duration(&(HTSsynth->engine), state++);

		tmp = frame * rate;
		SItemSetFloat((SItem*)itemItr, "start", tmp/1e+7, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemSetFloat\" failed"))
			goto quit_error;

		tmp = (frame + duration) * rate;
		SItemSetFloat((SItem*)itemItr, "end", tmp/1e+7, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemSetFloat\" failed"))
			goto quit_error;

		frame += duration;
		itemItr = SItemNext(itemItr, error);
		counter++;
	}

	/* We need to give the utterance the audio plug-in. If we don't do
	 * this and the voice is deleted before the utterance, then the
	 * utterance can't do *anything* with the audio. Not even delete
	 * it (segfault). This should be fast because it is already
	 * loaded.
	 * Note that this happens before the audio is set. This is because
	 * utt features are a list implementation.
	 */
	audioPlugin = s_pm_load_plugin("audio.spi", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceSetFeature\" failed"))
		goto quit_error;

	SUtteranceSetFeature(utt, "audio_plugin", S_OBJECT(audioPlugin), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceSetFeature\" failed"))
	{
		S_DELETE(audioPlugin, "Run", error);
		goto quit_error;
	}

	/* create an audio object */
	audio = S_NEW(SAudio, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Failed to create new 'SAudio' object"))
		goto quit_error;

	/* set audio feature in utterance */
	SUtteranceSetFeature(utt, "audio", S_OBJECT(audio), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceSetFeature\" failed"))
	{
		S_DELETE(audio, "Run", error);
		goto quit_error;
    }

	audio->sample_rate = HTSsynth->engine.global.sampling_rate;
	audio->num_samples = (uint32)HTS_Speect_GStreamSet_get_total_nsample(&(HTSsynth->engine));
	audio->samples = S_MALLOC(float, audio->num_samples);
	if (audio->samples == NULL)
	{
		S_FTL_ERR(error, S_MEMERROR,
				  "Run",
				  "Failed to allocate memory for 'float' object");
		goto quit_error;
	}

	/* write data */
	for (i = 0; i < audio->num_samples; i++)
		audio->samples[i] = (float)(HTS_Speect_GStreamSet_get_speech(&(HTSsynth->engine), i) * 1.0);

	for (counter = 0; counter < label_size; counter++)
		S_FREE(label_data[counter]);
	S_FREE(label_data);

	HTS_Engine_refresh(&(HTSsynth->engine));

	/* all OK here */
	return;

	/* error clean-up code */
quit_error:
	if (label_data != NULL)
	{
		for (counter = 0; counter < label_size; counter++)
		{
			if (label_data[counter] != NULL)
				S_FREE(label_data[counter]);
		}

		S_FREE(label_data);
	}

	return;
}
Example #9
0
static hts_params *get_hts_engine_params(const SMap *features, s_bool *me, s_erc *error)
{
	hts_params *engine_params;
	const char *tmp;


	S_CLR_ERR(error);

	engine_params = S_CALLOC(hts_params, 1);
	if (engine_params == NULL)
	{
		S_FTL_ERR(error, S_MEMERROR,
				  "get_hts_engine_params",
				  "Failed to allocate memory for 'hts_params' object");
		return NULL;
	}

	engine_params->sampling_rate = (int)SMapGetIntDef(features, "sampling_rate",
													  SPCT_DEF_SAMPLING_RATE, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetIntDef\" failed"))
		goto quit_error;

	engine_params->fperiod = (int)SMapGetIntDef(features, "fperiod",
												SPCT_DEF_FPERIOD, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetIntDef\" failed"))
		goto quit_error;

	engine_params->alpha = (double)SMapGetFloatDef(features, "alpha",
												   SPCT_DEF_ALPHA, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetFloatDef\" failed"))
		goto quit_error;

	engine_params->stage = (double)SMapGetFloatDef(features, "stage",
												   SPCT_DEF_STAGE, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetFloatDef\" failed"))
		goto quit_error;

	engine_params->beta = (double)SMapGetFloatDef(features, "beta",
												   SPCT_DEF_BETA, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetFloatDef\" failed"))
		goto quit_error;

	engine_params->audio_buff_size = (int)SMapGetIntDef(features, "audio_buff_size",
														SPCT_DEF_AUDIO_BUFF_SIZE, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetIntDef\" failed"))
		goto quit_error;

	engine_params->uv_threshold = (double)SMapGetFloatDef(features, "uv_threshold",
														  SPCT_DEF_UV_THRESHOLD, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetFloatDef\" failed"))
		goto quit_error;

	engine_params->gv_weight_lf0 = (double)SMapGetFloatDef(features, "gv_weight_lf0",
														   SPCT_DEF_GV_WEIGHT_LF0, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetFloatDef\" failed"))
		goto quit_error;

	engine_params->gv_weight_mcp = (double)SMapGetFloatDef(features, "gv_weight_mcp",
														   SPCT_DEF_GV_WEIGHT_MCP, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetFloatDef\" failed"))
		goto quit_error;


	(*me) = SMapObjectPresent(features, "gv_weight_str", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapObjectPresent\" failed"))
		goto quit_error;

	if (*me)
	{
		engine_params->gv_weight_str = (double)SMapGetFloat(features, "gv_weight_str",
															error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "get_hts_engine_params",
					  "Call to \"SMapGetFloat\" failed"))
			goto quit_error;
	}

	/* set "use_log_gain" to FALSE as default */
	engine_params->use_log_gain = FALSE;

	tmp = SMapGetStringDef(features, "use_log_gain", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_hts_engine_params",
				  "Call to \"SMapGetStringDef\" failed"))
		goto quit_error;

	if (tmp != NULL)
	{
		int scomp;


		scomp = s_strcmp("TRUE", tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "get_hts_engine_params",
					  "Call to \"s_strcmp\" failed"))
			goto quit_error;

		if (scomp == 0)
			engine_params->use_log_gain = TRUE;
	}

	/* all OK, no errors */
	return engine_params;

	/* error clean up */
quit_error:
	S_FREE(engine_params);
	return NULL;
}
Example #10
0
static uint32 GetChar(STokenstream *self, s_erc *error)
{
	uint32 utf8char;
	uchar t;
	int n;
	STokenstreamFile *tf = S_TOKENSTREAM_FILE(self);
	s_erc local_err = S_SUCCESS;


	S_CLR_ERR(error);

	SDatasourceRead(tf->ds, &t, sizeof(uchar), 1, &local_err);
	if (local_err == S_IOEOF)
	{
		self->eof = TRUE;
		self->current_char = 0;
		return 0;
	}
	else if (local_err != S_SUCCESS)
	{
		S_CTX_ERR(error, S_CONTERR,
				  "GetChar",
				  "Call to \"SDatasourceRead\" failed");
		self->current_char = 0;
		return 0;
	}

	utf8char = t;

	if (utf8char & 0x80)
	{
		n = 1;

		while (utf8char & (0x80>>n))
			n++;

		utf8char &= (1 << (8 - n)) - 1;

		while (--n > 0)
		{
			SDatasourceRead(tf->ds, &t, sizeof(uchar), 1, &local_err);
			if (local_err == S_IOEOF)
			{
				self->eof = TRUE;
				self->current_char = 0;
				return 0;
			}
			else if (local_err != S_SUCCESS)
			{
				S_CTX_ERR(error, S_CONTERR,
						  "GetChar",
						  "Call to \"SDatasourceRead\" failed");
				self->current_char = 0;
				return 0;
			}

			if ((!(t & 0x80)) || (t & 0x40))
			{
				self->current_char = '^';
				S_CTX_ERR(error, S_CONTERR,
						  "GetChar",
						  "Read invalid character");
			}

			utf8char = (utf8char << 6) | (t & 0x3F);
		}
	}
Example #11
0
static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error)
{
	hts_params *engine_params;
	SHTSEngineMESynthUttProc105 *HTSsynth = (SHTSEngineMESynthUttProc105*)self;
	const SMap *hts_data;
	const SObject *vcfgObject;
	char *voice_base_path;


	S_CLR_ERR(error);

	/* get voice base path */
	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;

	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;

	/* get the HTS engine settings */
	engine_params = get_hts_engine_params(self->features, &(HTSsynth->me), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"get_hts_engine_params\" failed"))
	{
		S_FREE(voice_base_path);
		return;
	}

	/* initialize the engine */
	if (HTSsynth->me == TRUE)
	{
		/* extra stream for strengths */
		HTS_Engine_initialize(&(HTSsynth->engine), 3);
	}
	else
	{
		HTS_Engine_initialize(&(HTSsynth->engine), 2);
	}

	/* set the engine parameters */
	HTS_Engine_set_sampling_rate(&(HTSsynth->engine), engine_params->sampling_rate);
	HTS_Engine_set_fperiod(&(HTSsynth->engine), engine_params->fperiod);
	HTS_Engine_set_alpha(&(HTSsynth->engine), engine_params->alpha);
	HTS_Engine_set_gamma(&(HTSsynth->engine), engine_params->stage);
	HTS_Engine_set_log_gain(&(HTSsynth->engine), engine_params->use_log_gain);
	HTS_Engine_set_beta(&(HTSsynth->engine), engine_params->beta);
	HTS_Engine_set_audio_buff_size(&(HTSsynth->engine), engine_params->audio_buff_size);
	HTS_Engine_set_msd_threshold(&(HTSsynth->engine), 1, engine_params->uv_threshold);
	HTS_Engine_set_gv_weight(&(HTSsynth->engine), 0, engine_params->gv_weight_mcp);
	HTS_Engine_set_gv_weight(&(HTSsynth->engine), 1, engine_params->gv_weight_lf0);

	if (HTSsynth->me == TRUE)
		HTS_Engine_set_gv_weight(&(HTSsynth->engine), 2, engine_params->gv_weight_str);

	S_FREE(engine_params);

	hts_data = S_MAP(SVoiceGetFeature(voice, "hts engine data", error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SVoiceGetFeature\" failed"))
		goto quit_error;

	if (hts_data == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "Initialize",
				  "Failed to get \"hts engine data\" map from voice features");
		goto quit_error;
	}

	load_hts_engine_data(hts_data, HTSsynth, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"load_hts_engine_data\" failed"))
		goto quit_error;

	HTS_Engine_set_duration_interpolation_weight(&(HTSsynth->engine), 0, 1.0);
	HTS_Engine_set_parameter_interpolation_weight(&(HTSsynth->engine), 0, 0, 1.0);
	HTS_Engine_set_parameter_interpolation_weight(&(HTSsynth->engine), 1, 0, 1.0);

	if (HTSsynth->me == TRUE)
		HTS_Engine_set_parameter_interpolation_weight(&(HTSsynth->engine), 2, 0, 1.0);

	HTS_Engine_set_gv_interpolation_weight(&(HTSsynth->engine), 0, 0, 1.0);
	HTS_Engine_set_gv_interpolation_weight(&(HTSsynth->engine), 1, 0, 1.0);

	if (HTSsynth->me == TRUE)
		HTS_Engine_set_gv_interpolation_weight(&(HTSsynth->engine), 2, 0, 1.0);

	/* all OK */
	S_FREE(voice_base_path);
	return;

	/* error clean up */
quit_error:
	HTS_Engine_clear(&(HTSsynth->engine));
	filter_destructor(HTSsynth);
	if (voice_base_path != NULL)
		S_FREE(voice_base_path);
}
Example #12
0
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SItem *itemInSylStructRel;
	const SItem *syllableItem;
	const SItem *itr;
	sint32 count;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	itemInSylStructRel = SItemAs(item, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		goto quit_error;

	if (itemInSylStructRel == NULL)
	{
		extractedFeat = SObjectSetInt(0, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectSetInt\" failed"))
			goto quit_error;

		return extractedFeat;
	}

	syllableItem = SItemParent(itemInSylStructRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemParent\" failed"))
		goto quit_error;

	if (syllableItem == NULL)
	{
		extractedFeat = SObjectSetInt(0, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectSetInt\" failed"))
			goto quit_error;

		return extractedFeat;
	}

	itr = SItemLastDaughter(syllableItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemLastDaughter\" failed"))
		goto quit_error;

	count = 0;
	while (itr != NULL)
	{
		s_bool is_equal;


		is_equal = SItemEqual(itr, itemInSylStructRel, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemEqual\" failed"))
			goto quit_error;

		if (is_equal)
			break;

		count++;
		itr = SItemPrev(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemPrev\" failed"))
			goto quit_error;
	}

	extractedFeat = SObjectSetInt(count, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetInt\" failed"))
		goto quit_error;

	/* all OK here */
	return extractedFeat;

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
}
Example #13
0
int main()
{
	s_erc error;
	STokenstream *ts = NULL;
	s_bool eof;
	const SToken *token;
	const char *tmp;


	S_CLR_ERR(&error);

	/*
	 * initialize speect
	 */
	error = speect_init(NULL);
	if (error != S_SUCCESS)
	{
		printf("Failed to initialize Speect\n");
		return 1;
	}

	/* create file tokenstream */
	ts = (STokenstream*)S_NEW(STokenstreamFile, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to create new file tokenstream"))
		goto quit;

	/* initialize file tokenstream */
	STokenstreamFileInit((STokenstreamFile**)&ts, "test_file.txt", &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to initialize file tokenstream"))
		goto quit;

	eof = STokenstreamQueryEOF(ts, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to query end of file"))
		goto quit;

	while (!eof)
	{
		token = STokenstreamPeekToken(ts, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to peek token"))
			goto quit;

		tmp = STokenGetString(token, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to get token string"))
			goto quit;

		if (tmp == NULL)
			break;
		else
		{
			token = STokenstreamGetToken(ts, &error);
			if (S_CHK_ERR(&error, S_CONTERR,
						  "main",
						  "Failed to get token"))
				goto quit;
		}

		printf("\nTOKEN:\n");

		/* white space */
		tmp = STokenGetWhitespace(token, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to get token white-space"))
			goto quit;

		if (tmp != NULL)
			printf("token whitespace = \"%s\".\n", tmp);
		else
			printf("token whitespace = NULL.\n");

		/* pre-punctuation */
		tmp = STokenGetPrePunc(token, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to get token pre-punctuation"))
			goto quit;

		if (tmp != NULL)
			printf("token pre-punctuation = \"%s\".\n", tmp);
		else
			printf("token pre-punctuation = NULL.\n");

		/* token string */
		tmp = STokenGetString(token, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to get token string"))
			goto quit;

		if (tmp != NULL)
			printf("token string = \"%s\".\n", tmp);
		else
			printf("token string = NULL.\n");

		/* post-punctuation */
		tmp = STokenGetPostPunc(token, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to get token post-punctuation"))
			goto quit;

		if (tmp != NULL)
			printf("token post-punctuation = \"%s\".\n", tmp);
		else
			printf("token post-punctuation = NULL.\n");

		eof = STokenstreamQueryEOF(ts, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to query end of file"))
			goto quit;
	}


	/*
	 * quit
	 */
quit:
	if (ts != NULL)
		S_DELETE(ts, "main", &error);

	/*
	 * quit speect
	 */
	error = speect_quit();
	if (error != S_SUCCESS)
	{
		printf("Call to 'speect_quit' failed\n");
		return 1;
	}


	return 0;
}
Example #14
0
static SList *MapPyValKeys(const SMap *self, s_erc *error)
{
	SMapPy *pMap = (SMapPy*)self;
	SListPy *pyList;
	PyObject *keys;


	S_CLR_ERR(error);
	S_CHECK_PY_MAP(pMap, "MapPyValKeys");

	keys = PyDict_Keys(S_PY_DICT(pMap));
	if (keys == NULL)
	{
		char *py_error = s_get_python_error_str();

		if (py_error)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValKeys",
					  "Call to \"PyDict_Keys\" failed. Reported error: %s",
					  py_error);
			S_FREE(py_error);
		}
		else
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValKeys",
					  "Call to \"PyDict_Keys\" failed");
		}

		return NULL;
	}

	pyList = S_NEW(SListPy, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "MapPyValKeys",
				  "Failed to create new 'SListPy' object"))
	{
		/* decrement reference of keys */
		Py_XDECREF(keys);
		return NULL;
	}

	SListPyInit(&pyList, keys, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "MapPyValKeys",
				  "Call to \"SListPyInit\" failed"))
	{
		/* decrement reference of keys */
		Py_XDECREF(keys);
		return NULL;
	}

	/* decrement reference of keys */
	Py_XDECREF(keys);

	return S_LIST(pyList);


	/* for S_CHECK_PY_MAP */
failure:
	return NULL;
}
Example #15
0
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SItem *itemInSentenceRel;
	const SItem *itr;
	sint32 count;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	itemInSentenceRel = SItemAs(item, "Sentence", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemRelation\" failed"))
		goto quit_error;

	SItem * sentenceItem = SItemParent (itemInSentenceRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemParent\" failed"))
		goto quit_error;

	itr = SItemDaughter (sentenceItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SRelationHead\" failed"))
		goto quit_error;

	count = 0;
	while (itr != NULL)
	{
		s_bool is_equal;


		is_equal = SItemEqual(itr, itemInSentenceRel, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemEqual\" failed"))
			goto quit_error;

		if (is_equal)
			break;

		count++;

		itr = SItemNext(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			goto quit_error;
	}

	extractedFeat = SObjectSetInt(count, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetInt\" failed"))
		goto quit_error;

	/* all OK here */
	return extractedFeat;

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
}
Example #16
0
static void get_windows(const SList *windows, char ***cwindows,
						int *num, const char *voice_base_path, s_erc *error)
{
	size_t tsize;
	SIterator *itr;
	int counter;


	S_CLR_ERR(error);
	tsize = SListSize(windows, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_windows",
				  "Call to \"SListSize\" failed"))
		return;

	*num = tsize;
	*cwindows = S_CALLOC(char*, tsize);
	if (*cwindows == NULL)
	{
		S_FTL_ERR(error, S_MEMERROR,
				  "get_windows",
				  "Failed to allocate memory for 'char*' object");
		return;
	}

	itr = S_ITERATOR_GET(windows, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_windows",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_FREE(*cwindows);
		return;
	}

	counter = 0;
	while (itr != NULL)
	{
		const char *tmp;


		tmp = SObjectGetString(SIteratorObject(itr, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "get_windows",
					  "Call to \"SIteratorObject/SObjectGetString\" failed"))
		{
			S_FREE(*cwindows);
			return;
		}

		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		(*cwindows)[counter++] = s_path_combine(voice_base_path, tmp,
												error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "get_windows",
					  "Call to \"s_path_combine\" failed"))
		{
			S_FREE(*cwindows);
			return;
		}

		itr = SIteratorNext(itr);
	}
}
Example #17
0
static void MoveShape(SShape *self, int newx, int newy, s_erc *error)
{
	S_CLR_ERR(error);
	self->x = newx;
	self->y = newy;
}
Example #18
0
static void load_hts_engine_data(const SMap *data,
								 SHTSEngineMESynthUttProc105 *HTSsynth,
								 const char *voice_base_path, s_erc *error)
{
	const SMap *tmp;
	const SList *trees;
	const SList *pdfs;
	const SList *windows;
	int num;
	int i;
	char **ctrees;
	char **cpdfs;
	char **cwindows;
	int num_win;
	const char *gv;
	const char *gv_tree;
	const char *gv_switch;
	const char *pd_filter;
	HTS_Engine *engine = &(HTSsynth->engine);


	S_CLR_ERR(error);

	/* duration */
	tmp = S_MAP(SMapGetObjectDef(data, "duration", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (tmp == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'duration' HTS Engine data");
		return;
	}

	trees = S_LIST(SMapGetObjectDef(tmp, "trees", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (trees == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'duration:trees' HTS Engine data");
		return;
	}

	pdfs = S_LIST(SMapGetObjectDef(tmp, "pdfs", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (pdfs == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'duration:pdfs' HTS Engine data");
		return;
	}

	get_trees_pdfs(trees, pdfs, &ctrees, &cpdfs, &num, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"get_trees_pdfs\" failed"))
		return;

	HTS_Engine_load_duration_from_fn(engine, cpdfs, ctrees, 1);
	for (i = 0; i < num; i++)
	{
		S_FREE(ctrees[i]);
		S_FREE(cpdfs[i]);
	}

	S_FREE(ctrees);
	S_FREE(cpdfs);


	/* log F0 */
	tmp = S_MAP(SMapGetObjectDef(data, "log F0", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (tmp == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'log F0' HTS Engine data");
		return;
	}

	trees = S_LIST(SMapGetObjectDef(tmp, "trees", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (trees == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'log F0:trees' HTS Engine data");
		return;
	}

	pdfs = S_LIST(SMapGetObjectDef(tmp, "pdfs", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (pdfs == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'log F0:pdfs' HTS Engine data");
		return;
	}

	get_trees_pdfs(trees, pdfs, &ctrees, &cpdfs, &num, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"get_trees_pdfs\" failed"))
		return;

	windows = S_LIST(SMapGetObjectDef(tmp, "windows", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (windows == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'log F0:windows' HTS Engine data");
		return;
	}

	get_windows(windows, &cwindows, &num_win, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"get_windows\" failed"))
		return;

	/* log f0 is stream 1, and msd_flag is TRUE */
	HTS_Engine_load_parameter_from_fn(engine, cpdfs, ctrees, cwindows,
									  1, TRUE, num_win, 1);

	for (i = 0; i < num; i++)
	{
		S_FREE(ctrees[i]);
		S_FREE(cpdfs[i]);
	}

	S_FREE(ctrees);
	S_FREE(cpdfs);

	for (i = 0; i < num_win; i++)
		S_FREE(cwindows[i]);

	S_FREE(cwindows);

	/* log f0 gv */
	gv = SMapGetStringDef(tmp, "gv-lf0", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetStringDef\" failed"))
		return;

	/* log f0 gv tree */
	gv_tree = SMapGetStringDef(tmp, "tree-gv-lf0", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetStringDef\" failed"))
		return;

	if (gv != NULL)
	{
		char *combined_path_gv;
		char *combined_path_gv_tree;


		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		combined_path_gv = s_path_combine(voice_base_path, gv,
										  error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"s_path_combine\" failed"))
			return;

		if (gv_tree != NULL)
		{
			/* get data path, the one in the config file may be relative
			 * to the voice base path
			 */
			combined_path_gv_tree = s_path_combine(voice_base_path, gv_tree,
												   error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "load_hts_engine_data",
						  "Call to \"s_path_combine\" failed"))
			{
				S_FREE(combined_path_gv);
				return;
			}
		}
		else
		{
			combined_path_gv_tree = NULL;
		}


		HTS_Engine_load_gv_from_fn(engine, (char**)&combined_path_gv,
								   (char**)&combined_path_gv_tree, 1, 1);
		S_FREE(combined_path_gv);
		if (combined_path_gv_tree != NULL)
			S_FREE(combined_path_gv_tree);
	}

	/* spectrum */
	tmp = S_MAP(SMapGetObjectDef(data, "spectrum", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (tmp == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'spectrum' HTS Engine data");
		return;
	}

	trees = S_LIST(SMapGetObjectDef(tmp, "trees", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (trees == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'spectrum:trees' HTS Engine data");
		return;
	}

	pdfs = S_LIST(SMapGetObjectDef(tmp, "pdfs", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (pdfs == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'spectrum:pdfs' HTS Engine data");
		return;
	}

	get_trees_pdfs(trees, pdfs, &ctrees, &cpdfs, &num, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"get_trees_pdfs\" failed"))
		return;

	windows = S_LIST(SMapGetObjectDef(tmp, "windows", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (windows == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "load_hts_engine_data",
				  "Failed to find 'spectrum:windows' HTS Engine data");
		return;
	}

	get_windows(windows, &cwindows, &num_win, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"get_windows\" failed"))
		return;

	/* spectrum is stream 0, and msd_flag is FALSE */
	HTS_Engine_load_parameter_from_fn(engine, cpdfs, ctrees, cwindows,
									  0, FALSE, num_win, 1);

	for (i = 0; i < num; i++)
	{
		S_FREE(ctrees[i]);
		S_FREE(cpdfs[i]);
	}

	S_FREE(ctrees);
	S_FREE(cpdfs);

	for (i = 0; i < num_win; i++)
		S_FREE(cwindows[i]);

	S_FREE(cwindows);

	/* spectrum gv */
	gv = SMapGetStringDef(tmp, "gv-mgc", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetStringDef\" failed"))
		return;

	/* spectrum gv tree */
	gv_tree = SMapGetStringDef(tmp, "tree-gv-mgc", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetStringDef\" failed"))
		return;

	if (gv != NULL)
	{
		char *combined_path_gv;
		char *combined_path_gv_tree;


		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		combined_path_gv = s_path_combine(voice_base_path, gv,
										  error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"s_path_combine\" failed"))
			return;

		if (gv_tree != NULL)
		{
			/* get data path, the one in the config file may be relative
			 * to the voice base path
			 */
			combined_path_gv_tree = s_path_combine(voice_base_path, gv_tree,
												   error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "load_hts_engine_data",
						  "Call to \"s_path_combine\" failed"))
			{
				S_FREE(combined_path_gv);
				return;
			}
		}
		else
		{
			combined_path_gv_tree = NULL;
		}


		HTS_Engine_load_gv_from_fn(engine, (char**)&combined_path_gv,
								   (char**)&combined_path_gv_tree, 0, 1);
		S_FREE(combined_path_gv);
		if (combined_path_gv_tree != NULL)
			S_FREE(combined_path_gv_tree);
	}

	/* band strengths */
	if (HTSsynth->me == TRUE)
	{
		const char *me_filter;


		tmp = S_MAP(SMapGetObjectDef(data, "strengths", NULL, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetObjectDef\" failed"))
			return;

		if (tmp == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "load_hts_engine_data",
					  "Failed to find 'strengths' HTS Engine data");
			return;
		}

		trees = S_LIST(SMapGetObjectDef(tmp, "trees", NULL, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetObjectDef\" failed"))
			return;

		if (trees == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "load_hts_engine_data",
					  "Failed to find 'strengths:trees' HTS Engine data");
			return;
		}

		pdfs = S_LIST(SMapGetObjectDef(tmp, "pdfs", NULL, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetObjectDef\" failed"))
			return;

		if (pdfs == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "load_hts_engine_data",
					  "Failed to find 'strengths:pdfs' HTS Engine data");
			return;
		}

		get_trees_pdfs(trees, pdfs, &ctrees, &cpdfs, &num, voice_base_path, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"get_trees_pdfs\" failed"))
			return;

		windows = S_LIST(SMapGetObjectDef(tmp, "windows", NULL, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetObjectDef\" failed"))
			return;

		if (windows == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "load_hts_engine_data",
					  "Failed to find 'strengths:windows' HTS Engine data");
			return;
		}

		get_windows(windows, &cwindows, &num_win, voice_base_path, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"get_windows\" failed"))
			return;

		/* strengths is stream 2, and msd_flag is FALSE */
		HTS_Engine_load_parameter_from_fn(engine, cpdfs, ctrees, cwindows,
										  2, FALSE, num_win, 1);

		for (i = 0; i < num; i++)
		{
			S_FREE(ctrees[i]);
			S_FREE(cpdfs[i]);
		}

		S_FREE(ctrees);
		S_FREE(cpdfs);

		for (i = 0; i < num_win; i++)
			S_FREE(cwindows[i]);

		S_FREE(cwindows);

		/* strengths gv */
		gv = SMapGetStringDef(tmp, "gv-str", NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetStringDef\" failed"))
			return;

		/* strengths gv tree */
		gv_tree = SMapGetStringDef(tmp, "tree-gv-str", NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetStringDef\" failed"))
			return;

		if (gv != NULL)
		{
			char *combined_path_gv;
			char *combined_path_gv_tree;


			/* get data path, the one in the config file may be relative
			 * to the voice base path
			 */
			combined_path_gv = s_path_combine(voice_base_path, gv,
											  error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "load_hts_engine_data",
						  "Call to \"s_path_combine\" failed"))
				return;

			if (gv_tree != NULL)
			{
				/* get data path, the one in the config file may be relative
				 * to the voice base path
				 */
				combined_path_gv_tree = s_path_combine(voice_base_path, gv_tree,
													   error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "load_hts_engine_data",
							  "Call to \"s_path_combine\" failed"))
				{
					S_FREE(combined_path_gv);
					return;
				}
			}
			else
			{
				combined_path_gv_tree = NULL;
			}


			HTS_Engine_load_gv_from_fn(engine, (char**)&combined_path_gv,
									   (char**)&combined_path_gv_tree, 2, 1);
			S_FREE(combined_path_gv);
			if (combined_path_gv_tree != NULL)
				S_FREE(combined_path_gv_tree);
		}

		/* mixed excitation filter */
		me_filter = SMapGetStringDef(tmp, "mixed excitation filter", NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"SMapGetStringDef\" failed"))
			return;

		if (me_filter != NULL)
		{
			char *combined_path;

			/* get data path, the one in the config file may be relative
			 * to the voice base path
			 */
			combined_path = s_path_combine(voice_base_path, me_filter,
										   error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "load_hts_engine_data",
						  "Call to \"s_path_combine\" failed"))
				return;

			HTS_Engine_load_me_filter_from_fn(combined_path, &(HTSsynth->me_filter),
											  &(HTSsynth->me_num_filters), &(HTSsynth->me_filter_order));
			S_FREE(combined_path);

			/* allocate memory for other filter buffers */
			filter_constructor(HTSsynth, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "load_hts_engine_data",
						  "Call to \"filter_constructor\" failed"))
				return;
		}
		else
		{
			S_CTX_ERR(error, S_FAILURE,
					  "load_hts_engine_data",
					  "Failed to find 'strengths:mixed excitation filter' HTS Engine data");
			return;
		}
	}

	/* gv switch */
	gv_switch = SMapGetStringDef(data, "gv-switch", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (gv_switch != NULL)
	{
		char *combined_path;


		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		combined_path = s_path_combine(voice_base_path, gv_switch,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"s_path_combine\" failed"))
			return;

		HTS_Engine_load_gv_switch_from_fn(engine, combined_path);
		S_FREE(combined_path);
	}

	/* pulse dispersion filter */
	pd_filter = SMapGetStringDef(data, "pulse dispersion filter", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "load_hts_engine_data",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (pd_filter != NULL)
	{
		char *combined_path;


		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		combined_path = s_path_combine(voice_base_path, pd_filter,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"s_path_combine\" failed"))
			return;

		HTS_Engine_load_pd_filter_from_fn(combined_path, &(HTSsynth->pd_filter),
										  &(HTSsynth->pd_filter_order));
		S_FREE(combined_path);
	}
}
Example #19
0
int main()
{
	s_erc error;
	SDatasource *ds = NULL;
	SPlugin *plugin = NULL;
	s_ebml_header *header = NULL;
	const char *doc_type = "spct_ebml_test";
	SEbmlWrite *ebmlWriter = NULL;


	S_CLR_ERR(&error);

	/*
	 * initialize speect
	 */
	error = speect_init(NULL);
	if (error != S_SUCCESS)
	{
		printf("Failed to initialize Speect\n");
		return 1;
	}

	/*
	 * load the ebml plug-in
	 */
	plugin = s_pm_load_plugin("ebml.spi", &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to load plug-in at 'ebml.spi'"))
	{
		printf("failed to load plug-in\n");
		goto quit;
	}
	else
	{
		printf("plug-in loaded\n");
	}


	/*
	 * create a data source, "wb" = write, binary
	 */
	ds = SFilesourceOpenFile("ebml_test.bin", "wb", &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to create data source 'ebml_test.bin'"))
	{
		printf("failed to create data source\n");
		goto quit;
	}
	else
	{
		printf("data source created\n");
	}

	/*
	 * create ebml header
	 */
	header = S_MALLOC(s_ebml_header, 1);
	if (header == NULL)
	{
		S_FTL_ERR(&error, S_MEMERROR,
				  "main",
				  "Failed to allocate memory for s_ebml_header object");
		goto quit;
	}
	header->ebml_version = 1;
	header->ebml_read_version = 1;
	header->max_id_width = 4;
	header->max_size_width = 4;
	header->doctype_version = 1;
	header->doctype_read_version = 1;
	header->doctype = s_strdup(doc_type, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to duplicate 'doc_type' for ebml header"))
		goto quit;


	/*
	 * create ebml writer object
	 */
	ebmlWriter = S_NEW(SEbmlWrite, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
				  "main",
				  "Failed to create new SEbmlWrite object"))
	{
		printf("failed to create SEbmlWrite object\n");
		goto quit;
	}
	else
	{
		printf("created SEbmlWrite object\n");
	}

	/*
	 * initialize ebml writer object
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_init))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_init)(&ebmlWriter, ds, header, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to initialize SEbmlWrite object"))
		{
			printf("failed to initialize SEbmlWrite object");
			goto quit;
		}
		else
		{
			printf("initialized SEbmlWrite object\n");

			/*
			 * ebml writer takes hold of the header and the data
			 * source, we dont want a reference to it anymore (for
			 * quit to work).
			 */
			header = NULL;
			ds = NULL;
		}
	}
	else
	{
		S_CTX_ERR(&error, S_METHINVLD,
				  "main",
				  "EbmlWrite method \"write_init\" not implemented");
		printf("cannot do write_init");
		goto quit;
	}

	/*
	 * Start a container
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, start_container))
	{
		S_EBMLWRITE_CALL(ebmlWriter, start_container)(ebmlWriter, 129, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to start ebml container"))
		{
			printf("failed to start container\n");
			goto quit;
		}
		else
		{
			printf("container started, id = %d\n", 129);
		}
	}


	/*
	 * Write a few unsigned int values
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_uint))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_uint)(ebmlWriter, 130, 234, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write uint [%d]", 234))
		{
			printf("failed to write uint [%d]\n", 234);
			goto quit;
		}
		else
		{
			printf("wrote uint [%d], id = %d\n", 234, 130);
		}

		S_EBMLWRITE_CALL(ebmlWriter, write_uint)(ebmlWriter, 130, 31234, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write uint [%d]", 31234))
		{
			printf("Failed to write uint [%d]\n", 31234);
			goto quit;
		}
		else
		{
			printf("wrote uint [%d], id = %d\n", 31234, 130);
		}
	}

	/*
	 * Write a few signed int values
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_sint))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_sint)(ebmlWriter, 131, -69, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write sint [%d]", -69))
		{
			printf("Failed to write sint [%d]\n", -69);
			goto quit;
		}
		else
		{
			printf("wrote sint [%d], id = %d\n", -69, 131);
		}

		S_EBMLWRITE_CALL(ebmlWriter, write_sint)(ebmlWriter, 131, -132769, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write sint [%d]", -132769))
		{
			printf("Failed to write sint [%d]\n", -132769);
			goto quit;
		}
		else
		{
			printf("wrote sint [%d], id = %d\n", -132769, 131);
		}
	}

	/*
	 * Start a container
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, start_container))
	{
		S_EBMLWRITE_CALL(ebmlWriter, start_container)(ebmlWriter, 132, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to start ebml container"))
		{
			printf("failed to start container\n");
			goto quit;
		}
		else
		{
			printf("container started, id = %d\n", 132);
		}
	}

	/*
	 * Write some floats
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_float))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_float)(ebmlWriter, 133, 20.343, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write float [%f]", 20.343))
		{
			printf("Failed to write float [%f]\n", 20.343);
			goto quit;
		}
		else
		{
			printf("wrote float [%f], id = %d\n", 20.343, 133);
		}

		S_EBMLWRITE_CALL(ebmlWriter, write_float)(ebmlWriter, 133, -12320.7603, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write float [%f]", -12320.7603))
		{
			printf("Failed to write float [%f]\n", -12320.7603);
			goto quit;
		}
		else
		{
			printf("wrote float [%f], id = %d\n", -12320.7603, 133);
		}
	}

	/*
	 * Write some doubles
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_double))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_double)(ebmlWriter, 134, -3.145343234223321, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write double [%f]", -3.145343234223321))
		{
			printf("Failed to write double [%f]\n", -3.145343234223321);
			goto quit;
		}
		else
		{
			printf("wrote double [%f], id = %d\n", -3.145343234223321, 134);
		}

		S_EBMLWRITE_CALL(ebmlWriter, write_double)(ebmlWriter, 134, 533.145343234223321145343234223321, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write double [%f]", 533.145343234223321145343234223321))
		{
			printf("Failed to write double [%f]\n", 533.145343234223321145343234223321);
			goto quit;
		}
		else
		{
			printf("wrote double [%f], id = %d\n", 533.145343234223321145343234223321, 134);
		}
	}

	/*
	 * Close container
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, stop_container))
	{
		S_EBMLWRITE_CALL(ebmlWriter, stop_container)(ebmlWriter, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to stop ebml container"))
		{
			printf("failed to stop container\n");
			goto quit;
		}
		else
		{
			printf("container stop\n");
		}
	}


	/*
	 * Write some ascii
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_ascii))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_ascii)(ebmlWriter, 135, "hello world", &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write ascii [%s]", "hello world"))
		{
			printf("Failed to write ascii [%s]\n", "hello world");
			goto quit;
		}
		else
		{
			printf("wrote ascii [%s], id = %d\n", "hello world", 135);
		}
	}


	/*
	 * Write some utf8
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_utf8))
	{
		S_EBMLWRITE_CALL(ebmlWriter, write_utf8)(ebmlWriter, 136, "hello world in Japanese: ハロー世界", &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to write utf8 [%s]", "hello world in Japanese"))
		{
			printf("Failed to write utf8 [%s]\n", "hello world in Japanese: ハロー世界");
			goto quit;
		}
		else
		{
			printf("wrote utf8 [%s], id = %d\n", "hello world in Japanese: ハロー世界", 136);
		}
	}

	/*
	 * Close container
	 */
	if (S_EBMLWRITE_METH_VALID(ebmlWriter, stop_container))
	{
		S_EBMLWRITE_CALL(ebmlWriter, stop_container)(ebmlWriter, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
					  "main",
					  "Failed to stop ebml container"))
		{
			printf("failed to stop container\n");
			goto quit;
		}
		else
		{
			printf("container stop\n");
		}
	}


	/*
	 * quit
	 */
quit:
	if (ds != NULL)
		S_DELETE(ds, "main", &error);

	if (header != NULL)
	{
		if (header->doctype != NULL)
			S_FREE(header->doctype);
		S_FREE(header);
	}

	if (ebmlWriter != NULL)
		S_DELETE(ebmlWriter, "main", &error);

	/* must be after ebmlWriter */
	if (plugin != NULL)
		S_DELETE(plugin, "main", &error);

	/*
	 * quit speect
	 */
	error = speect_quit();
	if (error != S_SUCCESS)
	{
		printf("Call to 'speect_quit' failed\n");
		return 1;
	}


	return 0;
}
Example #20
0
static void Save(const SObject *object, const char *path, s_erc *error)
{
	int rc;
	SUtterance *utt = S_UTTERANCE(object);
	SDatasource *ds;
	xmlTextWriterPtr writer;
	xmlOutputBufferPtr out;
	const char * xsi = "http://www.w3.org/2001/XMLSchema-instance";


	S_CLR_ERR(error);
	ds = SFilesourceOpenFile(path, "wt", error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Save",
		      "Call to \"SFilesourceOpenFile\" failed"))
		return;

	out = xmlOutputBufferCreateIO(_ds_write,
				      _ds_close,
				      ds,
				      NULL);
	if (out == NULL)
	{
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlOutputBufferCreateIO\" failed");
		return;
	}
	writer = xmlNewTextWriter(out);
	if (writer == NULL)
	{
                xmlOutputBufferClose(out);
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlNewTextWriter\" failed");
		return;
	}

	/* Start Document */
	rc = xmlTextWriterStartDocument(writer, NULL, ENCODING, NULL);
	if (rc < 0) {
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlTextWriterStartDocument\" failed");
		goto s_write_utt_exit;
	}

	/* Write the maryxml namespace */
	rc = xmlTextWriterStartElement(writer, BAD_CAST "xml");
	if (rc < 0) {
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlTextWriterStartElement\" failed");
		goto s_write_utt_exit;
	}

	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xsi", BAD_CAST xsi);
	if (rc < 0) {
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlTextWriterWriteAttribute\" failed");
		goto s_write_utt_exit;
	}

	rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version", BAD_CAST "0.5");
	if (rc < 0) {
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlTextWriterWriteAttribute\" failed");
		goto s_write_utt_exit;
	}


	// print labels
	/* get to the first syllable of the current word */
	const SItem* itrSegments = SRelationHead(SUtteranceGetRelation(utt, "Segment", error), error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Save",
		      "Call to \"SItemPathToItem\" failed"))
 		goto s_write_utt_exit;
	while (itrSegments != NULL)
	{
		/* get segment content */
		const char* label = SItemGetString(itrSegments, "hts_label", error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "Save",
			      "Call to \"SItemGetName\" failed"))
			goto s_write_utt_exit;

		/* get next segment */
		itrSegments = SItemNext(itrSegments, error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "Save",
			      "Call to \"SItemNext\" failed"))
			goto s_write_utt_exit;

		xmlTextWriterWriteElement(writer, BAD_CAST "label", BAD_CAST label);

	}

	/* Close the tag xml */
	rc = xmlTextWriterEndElement(writer);
	if (rc < 0)
	{
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlTextWriterEndDocument\" failed");
		goto s_write_utt_exit;
	}
	/* Close the document */
	rc = xmlTextWriterEndDocument(writer);
	if (rc < 0)
	{
		S_CTX_ERR(error, S_CONTERR,
			  "Save",
			  "Call to \"xmlTextWriterEndDocument\" failed");
		goto s_write_utt_exit;
	}
s_write_utt_exit:
        xmlFreeTextWriter(writer);
}
Example #21
0
static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error)
{
	const SObject *tmp;
	const SMap *syllInfo;
	const char *plugin_name;
	const char *class_name;
	SPlugin *sylPlugin;
	SSyllabification *syllab;


	S_CLR_ERR(error);

	/* check if a syllabification function is defined as a feature,
	 * and if so, create the syllabification object */
	tmp = SMapGetObjectDef(self->features, "syllabification function", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	/* nothing, return */
	if (tmp == NULL)
		return;

	syllInfo = S_CAST(tmp, SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"S_CAST (SMap)\" failed"))
		return;

	plugin_name = SMapGetString(syllInfo, "plug-in", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetString\" failed"))
		return;

	if (plugin_name == NULL)
		return;

	class_name = SMapGetString(syllInfo, "class", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetString\" failed"))
		return;

	if (class_name == NULL)
		return;

	/* load the plug-in */
	sylPlugin = s_pm_load_plugin(plugin_name, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"s_pm_load_plugin\" failed"))
		return;

	/* create a syllabification object */
	syllab = (SSyllabification*)S_NEW_FROM_NAME(class_name, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Failed to create new '%s' object", class_name))
	{
		S_DELETE(sylPlugin, "Initialize", error);
		return;
	}

	/* add them to the features */
	SMapSetObject(self->features, "_syll_func_plugin", S_OBJECT(sylPlugin), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapSetObject\" failed"))
	{
		S_DELETE(syllab, "Initialize", error);
		S_DELETE(sylPlugin, "Initialize", error);
		return;
	}

	SMapSetObject(self->features, "_syll_func", S_OBJECT(syllab), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapSetObject\" failed"))
	{
		/* plugin will be deleted when utt processor is deleted */
		S_DELETE(syllab, "Initialize", error);
		return;
	}

	S_UNUSED(voice);
}
Example #22
0
	void __delitem__(int key, s_erc *error)
	{
		SIterator *itr;
		uint32 i;
		s_bool found_point;
		SObject *toDelete;
		uint32 n = (uint32)key;
		size_t num_objects;


		S_CLR_ERR(error);
		num_objects = SListSize($self, error);
		if (*error != S_SUCCESS)
			return;

		if ((key >= (int)num_objects) || (key < 0))
		{
			PyErr_SetString(PyExc_IndexError, "Given key index out of bounds");
			return;
		}

		itr = S_ITERATOR_GET($self, error);
		if (*error != S_SUCCESS)
		{
			PyErr_SetString(PyExc_RuntimeError, "Failed to get list iterator");
			return;
		}

		i = 0;
		found_point = FALSE;
		while (itr)
		{
			if (i == n)
			{
				found_point = TRUE;
				break;
			}

			i++;
			itr = SIteratorNext(itr);
		}

		if ((!found_point) || (!itr))
		{
			S_CTX_ERR(error, S_FAILURE,
					  "SList::__delitem__()",
					  "Failed to find item to delete");
			if (itr)
				S_DELETE(itr, "SList::__delitem__()", error);
			return;
		}

		toDelete = SIteratorUnlink(itr, error);
		if (*error != S_SUCCESS)
		{
			S_DELETE(itr, "SList::__delitem__()", error);
			return;
		}

		S_DELETE(itr, "SList::__delitem__()", error);
		S_DELETE(toDelete, "SList::__delitem__()", error);
	}
Example #23
0
static long MMapTell(SDatasource *ds, s_erc *error)
{
	S_CLR_ERR(error);

	return (S_MMAPFILESOURCE(ds)->offset);
}
Example #24
0
	void __setitem__(int key, PyObject *val, s_erc *error)
	{
		SIterator *itr;
		uint32 i;
		s_bool found_point;
		SObject *toDelete;
		SObject *newObject;
		uint32 n = (uint32)key;
		size_t num_objects;


		S_CLR_ERR(error);
		num_objects = SListSize($self, error);
		if (*error != S_SUCCESS)
			return;

		if ((key >= (int)num_objects) || (key < 0))
		{
			PyErr_SetString(PyExc_IndexError, "Given key index out of bounds");
			return;
		}

		itr = S_ITERATOR_GET(self, error);
		if (*error != S_SUCCESS)
			return;

		i = 0;
		found_point = FALSE;
		while (itr)
		{
			if (i == n)
			{
				found_point = TRUE;
				break;
			}

			i++;
			itr = SIteratorNext(itr);
		}

		if ((!found_point) || (!itr))
		{
			S_CTX_ERR(error, S_FAILURE,
					  "SList::__setitem__()",
					  "Failed to find item to replace");
			if (itr)
				S_DELETE(itr, "SList::__setitem__()", error);
			return;
		}

		newObject = s_pyobject_2_sobject(val, error);
		if (*error != S_SUCCESS)
			return;

		SListInsertBefore(self, itr, newObject, error);
		if (*error != S_SUCCESS)
		{
			S_DELETE(newObject, "SList::__setitem__()", error);
			S_DELETE(itr, "SList::__setitem__()", error);
			return;
		}

		toDelete = SIteratorUnlink(itr, error);
		if (*error != S_SUCCESS)
		{
			S_DELETE(itr, "SList::__setitem__()", error);
			return;
		}

		S_DELETE(itr, "SList::__setitem__()", error);
		S_DELETE(toDelete, "SList::__setitem__()", error);
	}
Example #25
0
S_LOCAL void read_float_matrix(SEbmlRead *reader, SObject *object, s_erc *error)
{
	SMatrixFloat *self = (SMatrixFloat*)object;
	uint32 id;
	s_bool container_exhausted;
	uint32 counter;


	S_CLR_ERR(error);

	/* read S_EBML_ID_OBJECT_DATA container, id is checked in the
	 * 'read_object' method of the SEbmlRead class
	 */
	id = S_EBMLREAD_CALL(reader, container)(reader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_float_matrix",
				  "Call to SEbmlRead \"container\" failed"))
		return;

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(reader, container_at_end)(reader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_float_matrix",
					  "Call to SEbmlRead \"container_at_end\" failed"))
			return;

		if (container_exhausted)
			break; /* we are finished reading the matrix object */

		/* peek id for matrix object elements */
		id = S_EBMLREAD_CALL(reader, peek_id)(reader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_float_matrix",
					  "Call to SEbmlRead \"peek_id\" failed"))
			return;

		switch(id)
		{
		case S_MATRIX_FLOAT_EBML_ROW_COUNT:
		{
			/* read number of rows */
			self->row_count = S_EBMLREAD_CALL(reader, read_uint)(reader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_float_matrix",
						  "Call to SEbmlRead \"read_uint\" failed"))
				return;
			break;
		}
		case S_MATRIX_FLOAT_EBML_COL_COUNT:
		{
			/* read number of rows */
			self->col_count = S_EBMLREAD_CALL(reader, read_uint)(reader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_float_matrix",
						  "Call to SEbmlRead \"read_uint\" failed"))
				return;
			break;
		}
		case S_MATRIX_FLOAT_EBML_ROW_DATA:
		{
			/* allocate matrix memory */
			self->f = S_MALLOC(float*, self->row_count);
			if (self->f == NULL)
			{
				S_FTL_ERR(error, S_MEMERROR,
						  "read_float_matrix",
						  "Failed to allocate memory for 'float*' object");
				return;
			}

			for (counter = 0; counter < self->row_count; counter++)
			{
				self->f[counter] = S_MALLOC(float, self->col_count);
				if (self->f[counter] == NULL)
				{
					S_FTL_ERR(error, S_MEMERROR,
							  "read_float_matrix",
							  "Failed to allocate memory for 'float' object");
					return;
				}
			}

			read_row_data(reader, self, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_float_matrix",
						  "Call to \"read_row_data\" failed"))
				return;
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_float_matrix",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(reader, element_skip)(reader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_float_matrix",
						  "Call to SEbmlRead \"element_skip\" failed"))
				return;
		}
	}
}
Example #26
0
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SItem *phraseItem;
	const SItem *wordItem;
	const SItem *sylStructWordItem;
	const SItem *syllableItem;
	sint32 num_accented = 0;
	s_bool is_current_syl = FALSE;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	/* get current phrase */
	phraseItem = SItemPathToItem(item, "R:SylStructure.parent.R:Phrase.parent",
								 error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemPathToItem\" failed"))
		goto quit_error;

	if (phraseItem == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "Run",
				  "Failed to get phrase of given syllable");
		goto quit_error;
	}

	/* last word in phrase */
	wordItem = SItemLastDaughter(phraseItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemLastDaughter\" failed"))
		goto quit_error;

	while (wordItem != NULL)
	{
		sylStructWordItem = SItemAs(wordItem, "SylStructure", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemAs\" failed"))
			goto quit_error;

		/* get syllables */
		syllableItem = SItemLastDaughter(sylStructWordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemLastDaughter\" failed"))
			goto quit_error;

		while (syllableItem != NULL)
		{
			s_bool is_accented;


			is_current_syl = SItemEqual(syllableItem, item, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemEqual\" failed"))
				goto quit_error;

			if (is_current_syl)
				break;

			is_accented = syl_is_accented(syllableItem, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"syl_is_accented\" failed"))
				goto quit_error;

			if (is_accented)
				num_accented++;

			syllableItem = SItemPrev(syllableItem, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemPrev\" failed"))
				goto quit_error;
		}

		if (is_current_syl)
			break;

		wordItem = SItemPrev(wordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemPrev\" failed"))
			goto quit_error;
	}

	extractedFeat = SObjectSetInt(num_accented, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetInt\" failed"))
		goto quit_error;

	/* all OK here */
	return extractedFeat;

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
}
Example #27
0
static void Initialize(SFeatProcessor *self, const SMap* features, s_erc *error)
{
	S_CLR_ERR(error);

	SWordsToNextPuncFeatProc *castSelf = S_CAST(self, SWordsToNextPuncFeatProc, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to S_CAST failed"))
		goto quit_error;

	castSelf->symbols = SMapCopy ( NULL , features, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "Initialize",
			  "Call to \"SMapCopy\" failed"))
		goto quit_error;

	/* Get the iterator for the SMap */
	SIterator *itrList = S_ITERATOR_GET(castSelf->symbols, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to \"S_ITERATOR_GET\" failed"))
		goto quit_error;

	while( itrList != NULL ) {

		const char *curStr = SIteratorKey(itrList, error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "Initialize",
			      "Call to \"SIteratorKey\" failed"))
			goto quit_error;

		SList *valueList;
		valueList = S_CAST(SMapGetObject(castSelf->symbols, curStr, error), SList, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetObject\" failed"))
			goto quit_error;

		/* Initializing a new SMap */
		SMap *newCastMap= S_MAP(S_NEW(SMapHashTable, error));

		SIterator *itrValueList = S_ITERATOR_GET(valueList, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"S_ITERATOR_GET\" failed"))
			goto quit_error;

		while(itrValueList != NULL) {
			const SObject *curValueObj = SIteratorObject(itrValueList, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SIteratorObject\" failed"))
				goto quit_error;

			const char *curValueStr = SObjectGetString(curValueObj, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SObjectGetString\" failed"))
				goto quit_error;

			/* Insert the string inside the map */
			SMapSetString(newCastMap, curValueStr, curValueStr, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SMapSetObject\" failed"))
				goto quit_error;

			itrValueList = SIteratorNext(itrValueList);
		}

		/* Insertion of the SMap inside the SMap */
		SMapSetObject(castSelf->symbols, curStr, (SObject *) newCastMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SMapSetObject\" failed"))
				goto quit_error;
		itrList = SIteratorNext(itrList);
	}

	/* error cleanup */
	quit_error:
		return;
}
Example #28
0
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SItem *wordInSylStructRel;
	const SItem *sylInSylStructRel;
	const SItem *segment;
	const SItem *word;
	const SItem *prevItem;
	float start = 0.0;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	wordInSylStructRel = SItemAs(item, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		goto quit_error;

	word = SItemDaughter(wordInSylStructRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemDaughter\" failed"))
		goto quit_error;

	/* the same as the syllable start feature processor */
	sylInSylStructRel = SItemAs(word, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		goto quit_error;

	segment = SItemDaughter(sylInSylStructRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemDaughter\" failed"))
		goto quit_error;

	/* the rest is the same as the segment start feature processor */
	prevItem = SItemPrev(segment, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemPrev\" failed"))
		goto quit_error;

	if (prevItem == NULL)
	{
		/* there is no previous item, start is 0. */
		extractedFeat = SObjectSetFloat(start, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectSetFloat\" failed"))
			goto quit_error;
	}
	else
	{
		start = SItemGetFloat(prevItem, "end", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemGetFloat\" failed"))
			goto quit_error;

		extractedFeat = SObjectSetFloat(start, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectSetFloat\" failed"))
			goto quit_error;
	}

	/* all OK here */
	return extractedFeat;

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
}
Example #29
0
static void Dispose(void *obj, s_erc *error)
{
	S_CLR_ERR(error);
	SObjectDecRef(obj);
}
Example #30
0
static void MapPyValSet(SMap *self, const char *key, const SObject *val,
						s_erc *error)
{
	SMapPy *pMap = (SMapPy*)self;
	PyObject *pKey = NULL;
	PyObject *pobject;
	SObject *tmp;


	S_CLR_ERR(error);
	S_CHECK_PY_MAP(pMap, "MapPyValSet");

	/* cast away const */
 	tmp = (SObject*)val;

	/* increment reference count */
	SObjectIncRef(tmp);

	/* convert to Python object type, list is now owner of object (TRUE) */
	pobject = s_sobject_2_pyobject(tmp, TRUE, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "MapPyValSet",
				  "Call to \"s_sobject_2_pyobject\" failed"))
		goto error;

	pKey = s_set_pyobject_str(key, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "MapPyValSet",
				  "Call to \"s_set_pyobject_str\" failed"))
		goto error;

	if (PyObject_SetItem(S_PY_DICT(pMap), pKey, pobject) == -1)
	{
		char *py_error = s_get_python_error_str();

		if (py_error)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValSet",
					  "Call to \"PyObject_SetItem\" failed. Reported error: %s",
					  py_error);
			S_FREE(py_error);
		}
		else
		{
			S_CTX_ERR(error, S_FAILURE,
					  "MapPyValSet",
					  "Call to \"PyObject_SetItem\" failed");
		}

		goto error;
	}

	/* decrement reference of pobject */
	Py_XDECREF(pobject);

	/* all OK */
	return;

error:
	/* decrement the reference counting on error as the object
	 * has not successfully been set in the map
	 */
	SObjectDecRef(tmp);

	/* decrement reference of pobject */
	Py_XDECREF(pobject);

	/* decrement reference of pkey */
	Py_XDECREF(pKey);

	/* for S_CHECK_PY_MAP */
failure:
	return;
}