Beispiel #1
0
static void InitUtterance(void *obj, s_erc *error)
{
	SUtterance *self = obj;


	S_CLR_ERR(error);

	self->voice = NULL;

	self->features = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "InitUtterance",
				  "Failed to create new map-list features"))
		return;

	self->relations = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "InitUtterance",
				  "Failed to create new map-list relations"))
		return;

	/* item id's */
	SMapSetInt(self->features, "_id", 0, error);
	S_CHK_ERR(error, S_CONTERR,
			  "InitUtterance",
			  "Call to SMapSetInt failed");

	s_mutex_init(&(self->utt_mutex));
	s_mutex_init(&(self->utt_id_mutex));
}
Beispiel #2
0
static void InitVoice(void *obj, s_erc *error)
{
	SVoice *self = obj;


	S_CLR_ERR(error);

	self->info = NULL;
	self->plugins =  NULL;
	self->features = NULL;
	self->featProcessors = NULL;
	self->uttProcessors = NULL;
	self->uttTypes = NULL;

	self->data = S_CALLOC(s_voice_data, 1);
	if (self->data == NULL)
	{
		S_FTL_ERR(error, S_MEMERROR,
				  "InitVoice",
				  "Failed to allocate memory for 's_voice_data' object");
		return;
	}

	self->data->dataObjects = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "InitVoice",
				  "Failed to create new data objects map"))
		return;

	s_mutex_init(&self->voice_mutex);
}
Beispiel #3
0
static void InitItmContent(void *obj, s_erc *error)
{
	SItmContent *self = obj;


	S_CLR_ERR(error);

	self->features = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "InitItmContent",
				  "Failed to create features map"))
		return;

	self->relations = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "InitItmContent",
				  "Failed to create relations map"))
		return;

	/* so that it will only be deleted with S_FORCE_DELETE */
	SObjectIncRef(obj);

	s_mutex_init(&(self->content_mutex));
}
Beispiel #4
0
static void Init(void *obj, s_erc *error)
{
	SViterbiPath *self = obj;


	S_CLR_ERR(error);
	self->score = 0.0;
	self->state = 0;
	self->c = NULL;
	self->from = NULL;
	self->next = NULL;

	self->features = S_MAP(S_NEW(SMapList, error));
	S_CHK_ERR(error, S_CONTERR,
			  "Init",
			  "Failed to create new 'SMap' object");
}
Beispiel #5
0
static void create_new_entry(SAddendum *addendum, s_erc *error)
{
	SMap *features = NULL;
	SList *phones = NULL;
	int i;
	SObject *stringObject = NULL;


	S_CLR_ERR(error);

	/* create a word features map */
	features = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Failed to create new 'SMapList' object"))
		goto quit_error;

	/* now create a phones list */
	phones = S_LIST(S_NEW(SListList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Failed to create new 'SListList' object"))
		goto quit_error;

	SMapSetObject(features, "phones", S_OBJECT(phones), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Failed to initialize new 'SListList' object"))
	{
		S_DELETE(phones, "create_new_entry", error);
		goto quit_error;
	}

	/* add the phones to list */
	for (i = 0; test_word_phones[i] != NULL; i++)
	{
		/* create a string object */
		stringObject = SObjectSetString(test_word_phones[i], error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_new_entry",
					  "Call to \"SObjectSetString\" failed"))
			goto quit_error;

		/* add string object to list */
		SListAppend(phones, stringObject, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_new_entry",
					  "Call to \"SListAppend\" failed"))
		{
			S_DELETE(stringObject, "create_new_entry", error);
			goto quit_error;
		}
	}

	/* add entry to addendum */
	S_ADDENDUM_CALL(addendum, add_word)(addendum, test_word, features, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_new_entry",
				  "Call to method \"add_word\" failed"))
		goto quit_error;

	return;

quit_error:
	if (features != NULL)
		S_DELETE(features, "create_new_entry", error);
}
Beispiel #6
0
static void Initialize(SFeatProcessor *self, const SMap* features, s_erc *error)
{
	S_CLR_ERR(error);

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

	castSelf->symbols =  S_CAST( SMapGetObject(features , "list definitions", error),
								SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "Initialize",
			  "Call to \"SMapGetObject\" failed"))
		goto quit_error;

	castSelf->symbols = SMapCopy ( NULL , castSelf->symbols , 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;
}
Beispiel #7
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;
}
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);
	}
}
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);
}
Beispiel #10
0
static void Initialize(SUttProcessor *self, const SVoice *voice, s_erc *error)
{
	SHunposUttProc *hunposProc = (SHunposUttProc*)self;
	const SMap *hunpos_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 hunpos data map */
	hunpos_data = S_MAP(SVoiceGetFeature(voice, "hunpos data", error));
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to \"SVoiceGetFeature\" failed"))
		goto quit_error;

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

	load_hunpos_data(hunpos_data, hunposProc, voice_base_path, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to \"load_hunpos_data\" failed"))
		goto quit_error;


	/* create the hunpos instance */
	int hunpos_error = 0;
	hunposProc->hunpos_instance = hunpos_tagger_new( hunposProc->model_file, NULL, hunposProc->max_guessed_tags, hunposProc->theta, &hunpos_error );
	if (hunpos_error !=0)
	{
		S_CTX_ERR(error, S_FAILURE,
			  "Initialize",
			  "Call to \"hunpos_tagger_new\" failed");
		goto quit_error;
	}

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

	/* error clean up */
quit_error:
	clear_hunpos_data(hunposProc, error);
	if (voice_base_path != NULL)
		S_FREE(voice_base_path);
}
Beispiel #11
0
static void read_g2p_rewrites_rules(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error)
{
	uint32 id;
	s_bool container_exhausted;
	SList *graphemeRuleList = NULL;
	SG2PRewritesRule *rule = NULL;


	S_CLR_ERR(error);

	/* read S_G2PREWRITES_EBML_RULES_CONTAINER container */
	id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_rules",
				  "ebmlRead method \"container\" failed"))
		return;

	/* create rules SMap */
	g2p->rules = S_MAP(S_NEW(SMapHashTable, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_rules",
				  "Failed to create new 'SMap' object"))
		return;

	/* 64 should be enough for graphemes */
	SMapHashTableResize(S_MAPHASHTABLE(g2p->rules), 64, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_rules",
				  "Call to \"SMapHashTableResize\" failed"))
	{
		S_DELETE(g2p->rules, "read_g2p_rewrites_rules", error);
		return;
	}

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_rules",
					  "ebmlRead method \"container_at_end\" failed"))
			return;

		if (container_exhausted)
			break;

		/* peek id  */
		id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_rules",
					  "ebmlRead method \"peek_id\" failed"))
			return;

		switch(id)
		{
		case S_G2PREWRITES_EBML_RULES_GRAPHEME:
		{
			char *grapheme;


			grapheme = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "ebmlRead method \"read_utf8\" failed"))
				return;

			/* create rule list for this grapheme */
			graphemeRuleList = S_LIST(S_NEW(SListList, error));
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "Failed to create new 'SList' object"))
				return;

			/* add it to the rules SMap */
			SMapSetObject(g2p->rules, grapheme, S_OBJECT(graphemeRuleList), error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "Call to \"SMapSetObject\" failed"))
			{
				S_DELETE(graphemeRuleList, "read_g2p_rewrites_rules", error);
				S_FREE(grapheme);
				return;
			}

			S_FREE(grapheme);
			break;
		}
		case S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER:
		{
			/* read S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER container */
			id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "ebmlRead method \"container\" failed"))
				return;

			while (1)
			{
				container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_g2p_rewrites_rules",
							  "ebmlRead method \"container_at_end\" failed"))
					return;

				if (container_exhausted)
					break;

				/* peek id  */
				id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_g2p_rewrites_rules",
							  "ebmlRead method \"peek_id\" failed"))
					return;

				switch(id)
				{
				case S_G2PREWRITES_EBML_SINGLE_RULE_LEFT_CONTEXT:
				{
					/* elements are ordered so we create a rule here */
					rule = S_NEW(SG2PRewritesRule, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "Failed to create new 'SG2PRewritesRule' object"))
						return;

					/* add it to the list */
					SListAppend(graphemeRuleList, S_OBJECT(rule), error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "Call to \"SListAppend\" failed"))
					{
						S_DELETE(rule, "read_g2p_rewrites_rules", error);
						return;
					}

					rule->left_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id,
																				error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"read_utf8\" failed"))
						return;



					break;
				}
				case S_G2PREWRITES_EBML_SINGLE_RULE_RIGHT_CONTEXT:
				{
					rule->right_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id,
																				 error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"read_utf8\" failed"))
						return;

					break;
				}
				case S_G2PREWRITES_EBML_SINGLE_RULE_PHONEME:
				{
					rule->phone = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id,
																		 error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"read_utf8\" failed"))
						return;

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

					S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_g2p_rewrites_rules",
								  "ebmlRead method \"element_skip\" failed"))
						return;
				}
			}
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_g2p_rewrites_rules",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_rules",
						  "ebmlRead method \"element_skip\" failed"))
				return;
		}
	}

	return;
}
Beispiel #12
0
static void load_hts_engine_data(const SMap *data, HTS_Engine *engine,
								 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_switch;


	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;

	if (gv != 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,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"s_path_combine\" failed"))
			return;

		HTS_Engine_load_gv_from_fn(engine, (char**)&combined_path, NULL, 1, 1);
		S_FREE(combined_path);
	}

	/* 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;

	if (gv != 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,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "load_hts_engine_data",
					  "Call to \"s_path_combine\" failed"))
			return;

		HTS_Engine_load_gv_from_fn(engine, (char**)&combined_path, NULL, 0, 1);
		S_FREE(combined_path);
	}

	/* 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);
	}
}
Beispiel #13
0
static void s_get_tokenizer_symbols(SUttBreakUttProc *self, const SMap *features,
									s_erc *error)
{
	const SMap *tokenizerSymbols;
	const char *tmp;


	S_CLR_ERR(error);

	tokenizerSymbols = S_MAP(SMapGetObjectDef(features, "tokenizer symbols", NULL, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (tokenizerSymbols == NULL)
	{
		/* use defaults */
		self->white_space_chars = s_strdup(s_default_whitespacesymbols, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_get_tokenizer_symbols",
					  "Call to \"s_strdup\" failed"))
			goto quit_error;

		self->single_char_symbols = s_strdup(s_default_singlecharsymbols, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_get_tokenizer_symbols",
					  "Call to \"s_strdup\" failed"))
			goto quit_error;

		self->pre_punc_symbols =  s_strdup(s_default_prepunctuationsymbols, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_get_tokenizer_symbols",
					  "Call to \"s_strdup\" failed"))
			goto quit_error;

		self->post_punc_symbols =  s_strdup(s_default_postpunctuationsymbols, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_get_tokenizer_symbols",
					  "Call to \"s_strdup\" failed"))
			goto quit_error;

		return;
	}

	/* get symbols from map */
	tmp = SMapGetStringDef(tokenizerSymbols, "whitespace", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"SMapGetStringDef\" failed"))
		goto quit_error;

	if (tmp == NULL) /* use defaults */
		tmp = s_default_whitespacesymbols;

	self->white_space_chars = s_strdup(tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"s_strdup\" failed"))
		goto quit_error;

	tmp = SMapGetStringDef(tokenizerSymbols, "single-char", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"SMapGetStringDef\" failed"))
		goto quit_error;

	if (tmp == NULL) /* use defaults */
		tmp = s_default_singlecharsymbols;

	self->single_char_symbols = s_strdup(tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"s_strdup\" failed"))
		goto quit_error;


	tmp = SMapGetStringDef(tokenizerSymbols, "pre-punctuation", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"SMapGetStringDef\" failed"))
		goto quit_error;

	if (tmp == NULL) /* use defaults */
		tmp = s_default_prepunctuationsymbols;

	self->pre_punc_symbols = s_strdup(s_default_prepunctuationsymbols, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"s_strdup\" failed"))
		goto quit_error;

	tmp = SMapGetStringDef(tokenizerSymbols, "post-punctuation", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"SMapGetStringDef\" failed"))
		goto quit_error;

	if (tmp == NULL) /* use defaults */
		tmp = s_default_postpunctuationsymbols;

	self->post_punc_symbols = s_strdup(s_default_postpunctuationsymbols, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_tokenizer_symbols",
				  "Call to \"s_strdup\" failed"))
		goto quit_error;

	/* all ok */
	return;

	/* error clean up */
quit_error:
	if (self->white_space_chars != NULL)
		S_FREE(self->white_space_chars);

	if (self->single_char_symbols != NULL)
		S_FREE(self->single_char_symbols);

	if (self->pre_punc_symbols != NULL)
		S_FREE(self->pre_punc_symbols);

	if (self->post_punc_symbols != NULL)
		S_FREE(self->post_punc_symbols);
}