Example #1
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 #2
0
static void get_trees_pdfs(const SList *trees, const SList *pdfs,
						   char ***ctrees, char ***cpdfs, int *num,
						   const char *voice_base_path, s_erc *error)
{
	size_t tsize;
	size_t psize;
	SIterator *itr;
	int counter;


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

	psize = SListSize(pdfs, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_trees_pdfs",
				  "Call to \"SListSize\" failed"))
		return;

	if (tsize != psize)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "get_trees_pdfs",
				  "Given trees and pdfs sizes mismatch");
		return;
	}

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

	itr = S_ITERATOR_GET(trees, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_trees_pdfs",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_FREE(*ctrees);
		return;
	}

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


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

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

		itr = SIteratorNext(itr);
	}

	*cpdfs = S_CALLOC(char*, tsize);
	if (*cpdfs == NULL)
	{
		S_FREE(*ctrees);
		S_FTL_ERR(error, S_MEMERROR,
				  "get_trees_pdfs",
				  "Failed to allocate memory for 'char*' object");
		return;
	}

	itr = S_ITERATOR_GET(pdfs, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "get_trees_pdfs",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_FREE(*ctrees);
		S_FREE(*cpdfs);
		return;
	}

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


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

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

		itr = SIteratorNext(itr);
	}
}
Example #3
0
int main(int argc, char **argv)
{
	s_erc error = S_SUCCESS;

	/* the syllabification can be started from the voice */
	const SVoice *voice = NULL;

	SRelation *wordRel = NULL;

	SUtterance *utt = NULL;

	SItem *wordItem = NULL;

	SList *phones = NULL;

	SList *syllablesPhones = NULL;

	char* buffer = NULL;
	size_t buffer_size = 0;
	ssize_t buffer_length = 0;

	/* Config type will handle the command line input */
	struct Config config = {0};

	SPCT_PRINT_AND_WAIT("parsing options, press ENTER\n");

	parse_arguments(&argc, argv, &config);

	SPCT_PRINT_AND_WAIT("going to initialize speect, press ENTER\n");

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

	SPCT_PRINT_AND_WAIT("initialized speect, loading voice, press ENTER\n");

	/* load voice */
	voice = s_vm_load_voice(config.voicefile, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"s_vm_load_voice\" failed"))
		goto quit;

	SPCT_PRINT_AND_WAIT("loaded voice, doing syllabification, press ENTER\n");

	const SUttProcessor *uttProc = SVoiceGetUttProc(voice, "LexLookup", &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"SVoiceGetUttProc\" failed"))
		goto quit;


	utt = S_NEW(SUtterance, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"S_NEW\" failed"))
		goto quit;

	/* Utterance initialization */
	SUtteranceInit(&utt, voice, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"SUtteranceInit\" failed"))
		goto quit;

	/* Create new relation */
	wordRel = SUtteranceNewRelation(utt, "Word", &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"NewRelation\" failed"))
		goto quit;

	wordItem = SRelationAppend(wordRel, NULL, &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"SRelationAppend\" failed"))
		goto quit;

	SItemSetName(wordItem, "", &error);
	if (S_CHK_ERR(&error, S_CONTERR,
		      "main",
		      "Call to \"SItemSetName\" failed"))
		goto quit;

	SPCT_PRINT_AND_WAIT("load syllabification function, press ENTER\n");

	SSyllabification* syllab = (SSyllabification*)SVoiceGetData(voice , "syllabification", &error);
	if (syllab == NULL)
	{
		syllab = (SSyllabification*)SMapGetObjectDef(uttProc -> features , "_syll_func", NULL,
							     &error);

		if (S_CHK_ERR(&error, S_CONTERR,
			      "main",
			      "Call to \"SMapGetObjectDef\" failed"))
			goto quit;
	}

	SPCT_PRINT_AND_WAIT("everything ready to perform syllabification, press ENTER\n");
	char inter_buffer[MAX_PHONEME_LENGTH+1] = {0};

	buffer_length = getline(&buffer, &buffer_size, stdin);
	while (buffer_length != -1)
	{
		phones = S_LIST(S_NEW(SListList, &error));
		if (S_CHK_ERR(&error, S_CONTERR,
			      "main",
			      "Call to \"S_NEW\" failed"))
			goto quit;

		int j = 0;
		while (buffer[j] != '\0')
		{
			int k;
			int inter_buffer_c;

			if (!isspace(buffer[j]))
			{
				inter_buffer[0] = buffer[j];

				k = j + 1;
				inter_buffer_c = 1;

				while (!isspace(buffer[k]) && inter_buffer_c < MAX_PHONEME_LENGTH)
				{
					inter_buffer[inter_buffer_c] = buffer[k];

					inter_buffer_c++;
					k++;
				}

				j += (inter_buffer_c - 1);
				inter_buffer[inter_buffer_c] = '\0';

				/* for each phoneme in the line, put it in 'ph' */
				SObject* ph = SObjectSetString(inter_buffer, &error);

				/* then add ph to the phoneme list */
				SListAppend(phones, ph, &error);
				if (S_CHK_ERR(&error, S_CONTERR,
					      "main",
					      "Call to \"SListAppend\" failed"))
					goto quit;
			}
			j++;
		}

		SPCT_PRINT_AND_WAIT("run syllabification on next phones string, press ENTER\n");
		syllablesPhones = NULL;
		syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab,
									    wordItem,
									    phones,
									    &error);
		if (S_CHK_ERR(&error, S_CONTERR,
			      "main",
			      "Call to method \"syllabify\" failed"))
			goto quit;


		/* PRINT LOOP */
		uint32 k = 0;
		SIterator *itr_syllablesPhones = S_ITERATOR_GET(syllablesPhones, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
				  "Run",
				  "Execution of \"S_ITERATOR_GET\" failed"))
			goto quit;

		size_t syllables_list_size = SListSize(syllablesPhones, &error);
		if (S_CHK_ERR(&error, S_CONTERR,
			      "main",
			      "Call to method \"SListSize\" failed"))
			goto quit;

		while (itr_syllablesPhones != NULL)
		{
			const SList* syl_list = (const SList*) SIteratorObject(itr_syllablesPhones, &error);
			if (S_CHK_ERR(&error, S_CONTERR,
				      "main",
				      "Call to method \"SIteratorObject\" failed"))
				goto quit;

			size_t syl_list_size = SListSize(syl_list, &error);
			if (S_CHK_ERR(&error, S_CONTERR,
				      "main",
				      "Call to method \"SListSize\" failed"))
				goto quit;

			uint32 l = 0;
			SIterator *itr_syl_list = S_ITERATOR_GET(syl_list, &error);
			while (itr_syl_list != NULL)
			{
				const SObject* ph = SIteratorObject(itr_syl_list, &error);

				if (S_CHK_ERR(&error, S_CONTERR,
					      "main",
					      "Call to method \"SIteratorObject\" failed"))
					goto quit;

				const char* phone_string = SObjectGetString(ph, &error);
				if (S_CHK_ERR(&error, S_CONTERR,
					      "main",
					      "Call to method \"SObjectGetString\" failed"))
					goto quit;

				fprintf(stdout, "%s", phone_string);
				if (l < syl_list_size - 1){
					fprintf(stdout, " ");
				}

				itr_syl_list = SIteratorNext(itr_syl_list);
				l++;
			}
			if (k < syllables_list_size - 1)
			{
				fprintf(stdout, " - ");
			}

			itr_syllablesPhones = SIteratorNext(itr_syllablesPhones);
			k++;
		}
		fprintf(stdout, "\n");


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

		if (phones != NULL)
			S_DELETE(phones, "main", &error);
		phones = NULL;
		buffer_length = getline(&buffer, &buffer_size, stdin);
	}

quit:
	SPCT_PRINT_AND_WAIT("deleting iteration support structures, press ENTER\n");

	if (buffer != NULL)
		free(buffer);

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

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

	SPCT_PRINT_AND_WAIT("deleting utterance, press ENTER\n");

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

	SPCT_PRINT_AND_WAIT("deleting voice, press ENTER\n");

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

	SPCT_PRINT_AND_WAIT("quitting speect, press ENTER\n");

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

	SPCT_PRINT_AND_WAIT("done, press ENTER\n");

	return 0;
}
Example #4
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 #5
0
static void load_hunpos_data(const SMap *data, SHunposUttProc *hunposProc,
			     const char *voice_base_path, s_erc *error)
{
	const SObject *tmp;
	const char *mf_data = NULL;


	S_CLR_ERR(error);


	/* max guessed tags */
	hunposProc->max_guessed_tags = SMapGetIntDef(data, "max guessed tags",
						     SPCT_DEF_MAX_GUESSED_TAGS, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "load_hunpos_data",
		      "Call to \"SMapGetIntDef\" failed"))
		return;

	/* theta */
	hunposProc->theta = SMapGetIntDef(data, "theta",
					  SPCT_DEF_THETA, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "load_hunpos_data",
		      "Call to \"SMapGetIntDef\" failed"))
		return;

	/* max tokens */
	hunposProc->max_tokens_number = SMapGetIntDef(data, "max_tokens_number",
						      SPCT_DEF_MAX_TOKENS_NUMBER, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "load_hunpos_data",
		      "Call to \"SMapGetIntDef\" failed"))
		return;

	/* model file */
	tmp = SMapGetObjectDef(data, "model file", NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "load_hunpos_data",
		      "Call to \"SMapGetObjectDef\" failed"))
		return;

	if (tmp == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
			  "load_hunpos_data",
			  "Failed to find 'model file' hunpos data entry");
		return;
	}

	mf_data = SObjectGetString(tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "load_hunpos_data",
		      "Call to \"SObjectGetString\" failed"))
		return;

	hunposProc->model_file = s_path_combine(voice_base_path, mf_data,
						error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "load_hunpos_data",
		      "Call to \"s_path_combine\" failed"))
		return;
}
Example #6
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);
}
Example #7
0
static void ReSynthUtt(const SVoice *self, const char *utt_type,
					   SUtterance *utt, s_erc *error)
{
	const SList *uttType;
	const SUttProcessor *uttProc; /* utterance processor */
	const char *utt_processor_name;
	SIterator *itr;


	S_CLR_ERR(error);

	uttType = SVoiceGetUttType(self, utt_type, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "ReSynthUtt",
				  "Call to \"SVoiceGetUttType\" failed"))
		return;

	SUtteranceSetFeature(utt, "utterance-type",
						 SObjectSetString(utt_type, error),
						 error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "ReSynthUtt",
				  "Failed to set utterance \'utterance-type\' feature"))
		return;

	/* run utterance processors on utterance */
	itr = S_ITERATOR_GET(uttType, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "ReSynthUtt",
				  "Call to \"S_ITERATOR_GET\" failed"))
		return;

	for (/* NOP */; itr != NULL; itr = SIteratorNext(itr))
	{
		/* get utterance processor name */
		utt_processor_name = SObjectGetString(SIteratorObject(itr, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "ReSynthUtt",
					  "Failed to get utterance processor name"))
		{
			S_DELETE(itr, "ReSynthUtt", error);
			return;
		}

		uttProc = S_UTTPROCESSOR(SMapGetObjectDef(self->uttProcessors, utt_processor_name,
												  NULL, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "ReSynthUtt",
					  "Call to \"SMapGetObjectDef\" failed"))
		{
			S_DELETE(itr, "ReSynthUtt", error);
			return;
		}

		if (uttProc == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "ReSynthUtt",
					  "Utterance processor \'%s\' not defined",
					  utt_processor_name);
			S_DELETE(itr, "ReSynthUtt", error);
			return;
		}

		S_DEBUG(S_DBG_INFO,
				"executing \'%s\' utterance processor ...",
				utt_processor_name);

		SUttProcessorRun(uttProc, utt, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "ReSynthUtt",
					  "Execution of utterance processor \'%s\' failed",
					  utt_processor_name))
		{
			S_DELETE(itr, "ReSynthUtt", error);
			return;
		}
	}
}
Example #8
0
static void read_g2p_rewrites_zeros(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error)
{
	uint32 id;
	SList *tmpZeros;
	size_t list_size;
	SIterator *itr;
	s_bool container_exhausted;
	s_gzero *tmp;


	S_CLR_ERR(error);

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

	/* create a temporary SList storage */
	tmpZeros = S_LIST(S_NEW(SListList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_zeros",
				  "Failed to create new 'SList' object"))
		return;

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_zeros",
					  "ebmlRead method \"container_at_end\" failed"))
		{
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			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_zeros",
					  "ebmlRead method \"peek_id\" failed"))
		{
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			return;
		}


		switch(id)
		{
		case S_G2PREWRITES_EBML_ZEROS_SYMBOL:
		{
			char *symbol;


			symbol = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_zeros",
						  "ebmlRead method \"read_utf8\" failed"))
			{
				S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
				return;
			}

			/* put symbol in list */
			SListAppend(tmpZeros, SObjectSetString(symbol, error), error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_zeros",
						  "Call to \"SListAppend\" failed"))
			{
				S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
				S_FREE(symbol);
				return;
			}

			S_FREE(symbol);
			break;
		}
		case S_G2PREWRITES_EBML_ZEROS_REPLACEMENT:
		{
			char *replacement;


			replacement = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_zeros",
						  "ebmlRead method \"read_utf8\" failed"))
			{
				S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
				return;
			}

			/* put replacement in list */
			SListAppend(tmpZeros, SObjectSetString(replacement, error), error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_g2p_rewrites_zeros",
						  "Call to \"SListAppend\" failed"))
			{
				S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
				S_FREE(replacement);
				return;
			}

			S_FREE(replacement);
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_g2p_rewrites_zeros",
					  "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_zeros",
						  "ebmlRead method \"element_skip\" failed"))
				return;
		}
	}

	/* get list size */
	list_size = SListSize(tmpZeros, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_zeros",
				  "Call to \"SListSize\" failed"))
	{
		S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
		return;
	}

	/* make sure it is divisible by 2 */
	if (list_size%2 != 0)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "read_g2p_rewrites_zeros",
				  "Number of read symbol/replacement zero's not divisible by 2");
		S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
		return;
	}

	/* create zeros structure */
	g2p->zeros = S_CALLOC(s_gzero, list_size + 1);
	if (g2p->zeros == NULL)
	{
		S_FTL_ERR(error, S_MEMERROR,
				  "read_g2p_rewrites_zeros",
				  "Failed to allocate memory for 's_gzero' object");
		S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
		return;
	}

	itr = S_ITERATOR_GET(tmpZeros, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_g2p_rewrites_zeros",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
		return;
	}

	tmp = g2p->zeros;

	while (itr != NULL)
	{
		const char *symbol;
		const char *replacement;


		symbol = SObjectGetString(SIteratorObject(itr, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_zeros",
					  "Call to \"SIteratorObject/SObjectGetString\" failed"))
		{
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			S_DELETE(itr, "read_g2p_rewrites_zeros", error);
			return;
		}

		tmp->symbol = s_strdup(symbol, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_zeros",
					  "Call to \"s_strdup\" failed"))
		{
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			S_DELETE(itr, "read_g2p_rewrites_zeros", error);
			return;
		}

		itr = SIteratorNext(itr);
		if (itr == NULL)
		{
			S_CTX_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_zeros",
					  "Expected replacement zero is NULL");
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			return;
		}

		replacement = SObjectGetString(SIteratorObject(itr, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_zeros",
					  "Call to \"SListIterator/SObjectGetString\" failed"))
		{
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			S_DELETE(itr, "read_g2p_rewrites_zeros", error);
			return;
		}

		tmp->replacement = s_strdup(replacement, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_g2p_rewrites_zeros",
					  "Call to \"s_strdup\" failed"))
		{
			S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
			S_DELETE(itr, "read_g2p_rewrites_zeros", error);
			return;
		}

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

	S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error);
	return;
}
Example #9
0
static void print_list(const SList *list, char *buf, s_erc *error)
{
	SIterator *itr;
	size_t list_size;


	S_CLR_ERR(error);

	list_size = SListSize(list, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "print_list",
				  "Call to \"list_size\" failed"))
		return;

	s_strcat(buf, "[", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "print_list",
				  "Call to \"s_strcat\" failed"))
		return;

	itr = S_ITERATOR_GET(list, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "print_list",
				  "Call to \"S_ITERATOR_GET\" failed"))
		return;

	for (/* NOP */; itr != NULL; itr = SIteratorNext(itr), --list_size)
	{
		s_bool type_ok;
		const SObject *tmp;


		tmp = SIteratorObject(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "print_list",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(itr, "print_list", error);
			return;
		}

		type_ok = SObjectIsType(tmp, "SList", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "print_word",
					  "Call to \"SObjectIsType\" failed"))
		{
			S_DELETE(itr, "print_list", error);
			return;
		}

		if (type_ok)
		{
			print_list(S_LIST(tmp), buf, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "print_list",
						  "Call to \"print_list\" failed"))
			{
				S_DELETE(itr, "print_list", error);
				return;
			}
		}
		else
		{
			type_ok = SObjectIsType(tmp, "SString", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "print_list",
						  "Call to \"SObjectIsType\" failed"))
			{
				S_DELETE(itr, "print_list", error);
				return;
			}

			if (type_ok)
			{
				const char *string = SObjectGetString(S_OBJECT(tmp), error);

				if (S_CHK_ERR(error, S_CONTERR,
							  "print_list",
							  "Call to \"SObjectGetString\" failed"))
				{
					S_DELETE(itr, "print_list", error);
					return;
				}
				s_strcat(buf, string, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "print_list",
							  "Call to \"s_strcat\" failed"))
				{
					S_DELETE(itr, "print_list", error);
					return;
				}

				if ((list_size-1) != 0)
				{
					s_strcat(buf, " ", error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "print_list",
								  "Call to \"s_strcat\" failed"))
					{
						S_DELETE(itr, "print_list", error);
						return;
					}
				}
			}
			else
			{
				S_CTX_ERR(error, S_FAILURE,
						  "print_list",
						  "Unknown type in list");
				{
					S_DELETE(itr, "print_list", error);
					return;
				}
			}
		}
	}

	s_strcat(buf, "]", error);
	S_CHK_ERR(error, S_CONTERR,
			  "print_list",
			  "Call to \"s_strcat\" failed");
}
Example #10
0
S_LOCAL void _s_voice_load_data(SVoice *self, const SMap *dataConfig, s_erc *error)
{
	SIterator *itr;
	const char *data_name;
	const SObject *loaded;
	const SMap *dataObjectMap;
	s_data_info *data_info;
	const SObject *vcfgObject;
	char *voice_base_path;


	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "_s_voice_load_data",
				  "Argument \"self\" is NULL");
		return;
	}

	/* get voice base path */
	vcfgObject = SVoiceGetFeature(self, "config_file", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "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,
				  "_s_voice_load_data",
				  "Call to \"s_get_base_path/SObjectGetString\" failed"))
		return;

	/*
	 * now iterate through data config and load everything
	 */
	itr = S_ITERATOR_GET(dataConfig, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(itr, "_s_voice_load_data", error);
		S_FREE(voice_base_path);
		return;
	}

	while (itr)
	{
		char *combined_path;


		data_name = SIteratorKey(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SIteratorKey\" failed"))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		/*
		 * We have already checked this cast in
		 * _s_voice_load_dataConfig (_s_load_voice_data_config)
		 */
		dataObjectMap = (const SMap*)SMapGetObjectDef(dataConfig, data_name, NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SMapGetObjectDef\" for data '%s' failed",
					  data_name))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		if (dataObjectMap == NULL)
		{
			S_CTX_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Data object map for data '%s' in data config in NULL",
					  data_name);
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		data_info = get_data_info(dataObjectMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"get_data_info\" for data '%s' in data config failed",
					  data_name))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		/* 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, data_info->path,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"s_path_combine\" failed"))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		loaded = _s_vm_load_data(data_info->plugin, combined_path,
								 data_info->format, error);
		S_FREE(combined_path);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"_s_vm_load_data\" for data '%s' in data config failed",
					  data_name))
		{
			S_FREE(data_info);
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		S_FREE(data_info);

		SMapSetObject(self->data->dataObjects, data_name, loaded, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SMapSetObject\" for data '%s' in data config failed",
					  data_name))
		{
			s_erc local_err = S_SUCCESS;


			S_FREE(voice_base_path);
			S_DELETE(itr, "_s_voice_load_data", error);
			_s_vm_unload_data((SObject*)loaded, &local_err); /* error is already set */
			return;
		}

		itr = SIteratorNext(itr);
	}

	S_FREE(voice_base_path);
}
Example #11
0
/* /B:b1-b2-b3@b4-b5&b6-b7#b8-b9$b10-b11!b12-b13;b14-b15|b16
 *
 * b1 whether the current syllable stressed or not (0: not stressed, 1: stressed)
 * b2 whether the current syllable accented or not (0: not accented, 1: accented)
 * b3 the number of phonemes in the current syllable
 * b4 position of the current syllable in the current word (forward)
 * b5 position of the current syllable in the current word (backward)
 * b6 position of the current syllable in the current phrase (forward)
 * b7 position of the current syllable in the current phrase (backward)
 * b8 the number of stressed syllables before the current syllable in the current phrase
 * b9 the number of stressed syllables after the current syllable in the current phrase
 * b10 the number of accented syllables before the current syllable in the current phrase
 * b11 the number of accented syllables after the current syllable in the current phrase
 * b12 the number of syllables from the previous stressed syllable to the current syllable
 * b13 the number of syllables from the current syllable to the next stressed syllable
 * b14 the number of syllables from the previous accented syllable to the current syllable
 * b15 the number of syllables from the current syllable to the next accented syllable
 * b16 name of the vowel of the current syllable
 */
static char *create_B_context(const SItem *item, s_erc *error)
{
	SObject *dFeat;
	char *b_context;
	sint32 b3;
	sint32 b4;
	sint32 b5;
	sint32 b6;
	sint32 b7;
	const char *b16;


	S_CLR_ERR(error);

	/* no stress/accented methods */

	/* b3 */
	dFeat = SItemPathToFeatProc(item, "R:SylStructure.parent.R:Syllable.syllable_num_phones",
							   error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"SItemPathToFeatProc\" failed"))
		return NULL;

	if (dFeat != NULL)
	{
		b3 = SObjectGetInt(dFeat, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_B_context",
					  "Call to \"SObjectGetInt\" failed"))
			return NULL;

		S_DELETE(dFeat, "create_B_context", error);
	}
	else
	{
		b3 = 0;
	}

	/* b4 */
	dFeat = SItemPathToFeatProc(item, "R:SylStructure.parent.R:Syllable.syllable_pos_word",
							   error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"SItemPathToFeatProc\" failed"))
		return NULL;

	if (dFeat != NULL)
	{
		b4 = SObjectGetInt(dFeat, error) + 1; /* it seems as if HTS likes indexing from 1 */
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_B_context",
					  "Call to \"SObjectGetInt\" failed"))
			return NULL;

		S_DELETE(dFeat, "create_B_context", error);
	}
	else
	{
		b4 = 0;
	}


	/* b5 */
	dFeat = SItemPathToFeatProc(item, "R:SylStructure.parent.R:Syllable.syllable_pos_word_rev",
							   error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"SItemPathToFeatProc\" failed"))
		return NULL;

	if (dFeat != NULL)
	{
		b5 = SObjectGetInt(dFeat, error) + 1; /* it seems as if HTS likes indexing from 1 */
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_B_context",
					  "Call to \"SObjectGetInt\" failed"))
			return NULL;

		S_DELETE(dFeat, "create_B_context", error);
	}
	else
	{
		b5 = 0;
	}


	/* b6 */
	dFeat = SItemPathToFeatProc(item, "R:SylStructure.parent.R:Syllable.syllable_pos_phrase",
							   error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"SItemPathToFeatProc\" failed"))
		return NULL;

	if (dFeat != NULL)
	{
		b6 = SObjectGetInt(dFeat, error) + 1; /* it seems as if HTS likes indexing from 1 */
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_B_context",
					  "Call to \"SObjectGetInt\" failed"))
			return NULL;

		S_DELETE(dFeat, "create_B_context", error);
	}
	else
	{
		b6 = 0;
	}


	/* b7 */
	dFeat = SItemPathToFeatProc(item, "R:SylStructure.parent.R:Syllable.syllable_pos_phrase_rev",
							   error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"SItemPathToFeatProc\" failed"))
		return NULL;

	if (dFeat != NULL)
	{
		b7 = SObjectGetInt(dFeat, error) + 1; /* it seems as if HTS likes indexing from 1 */
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_B_context",
					  "Call to \"SObjectGetInt\" failed"))
			return NULL;

		S_DELETE(dFeat, "create_B_context", error);
	}
	else
	{
		b7 = 0;
	}

	/* no stress/accented methods */

	/* b16 */
	dFeat = SItemPathToFeatProc(item, "R:SylStructure.parent.R:Syllable.syllable_vowel",
							   error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"SItemPathToFeatProc\" failed"))
		return NULL;

	if (dFeat != NULL)
	{
		b16 = SObjectGetString(dFeat, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_B_context",
					  "Call to \"SObjectGetString\" failed"))
			return NULL;

	}
	else
	{
		b16 = "novowel";
	}

	/* we currently cannot compute b1, b2, b8, b9, b10, b11, b12, b13, b14 and b15 */
	s_asprintf(&b_context, error, "/B:0-0-%d@%d-%d&%d-%d#x-x$x-x!x-x;x-x|%s",
			   b3, b4, b5, b6, b7, b16);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_B_context",
				  "Call to \"s_asprintf\" failed"))
	{
		S_DELETE(dFeat, "create_B_context", error);
		return NULL;
	}

	S_DELETE(dFeat, "create_B_context", error);
	return b_context;
}
Example #12
0
/* p1^p2-p3+p4=p5@
 *
 * p1 the phoneme identity before the previous phoneme
 * p2 the previous phoneme identity
 * p3 the current phoneme identity
 * p4 the next phoneme identity
 * p5 the phoneme after the next phoneme identity
 */
static char *create_phone_context(const SItem *item, s_erc *error)
{
	char *p_context;
	char p1[MAX_PHONE_NAME_LENGTH] = "";
	char p2[MAX_PHONE_NAME_LENGTH] = "";
	char p3[MAX_PHONE_NAME_LENGTH] = "";
	char p4[MAX_PHONE_NAME_LENGTH] = "";
	char p5[MAX_PHONE_NAME_LENGTH] = "";
	const SObject *featPath;
	const char *tmp;


	S_CLR_ERR(error);

	/* p1 = p.p.name */
	featPath = SItemPathToFeature(item, "p.p.name", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_phone_context",
				  "Call to \"SItemPathToFeature\" failed"))
		return NULL;

	if (featPath != NULL)
	{
		s_strcpy(p1, SObjectGetString(featPath, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy/SObjectGetString\" failed"))
			return NULL;
	}
	else
	{
		s_strcpy(p1, none_string, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy\" failed"))
			return NULL;
	}

	/* p2 = p.name */
	featPath = SItemPathToFeature(item, "p.name", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_phone_context",
				  "Call to \"SItemPathToFeature\" failed"))
		return NULL;

	if (featPath != NULL)
	{
		s_strcpy(p2, SObjectGetString(featPath, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy/SObjectGetString\" failed"))
			return NULL;
	}
	else
	{
		s_strcpy(p2, none_string, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy\" failed"))
			return NULL;
	}

	/* p3 = name */
	tmp = SItemGetName(item, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_phone_context",
				  "Call to \"SItemGetName\" failed"))
		return NULL;

	if (tmp != NULL)
	{
		s_strcpy(p3, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy\" failed"))
			return NULL;
	}
	else
	{
		s_strcpy(p3, none_string, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy\" failed"))
			return NULL;
	}

	/* p4 = n.name */
	featPath = SItemPathToFeature(item, "n.name", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_phone_context",
				  "Call to \"SItemPathToFeature\" failed"))
		return NULL;

	if (featPath != NULL)
	{
		s_strcpy(p4, SObjectGetString(featPath, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy/SObjectGetString\" failed"))
			return NULL;
	}
	else
	{
		s_strcpy(p4, none_string, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy\" failed"))
			return NULL;
	}

	/* p5 = n.n.name */
	featPath = SItemPathToFeature(item, "n.n.name", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_phone_context",
				  "Call to \"SItemPathToFeature\" failed"))
		return NULL;

	if (featPath != NULL)
	{
		s_strcpy(p5, SObjectGetString(featPath, error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy/SObjectGetString\" failed"))
			return NULL;
	}
	else
	{
		s_strcpy(p5, none_string, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "create_phone_context",
					  "Call to \"s_strcpy\" failed"))
			return NULL;
	}

	s_asprintf(&p_context, error, "%s^%s-%s+%s=%s@", p1, p2, p3, p4, p5);
	if (S_CHK_ERR(error, S_CONTERR,
				  "create_phone_context",
				  "Call to \"s_asprintf\" failed"))
		return NULL;

	return p_context;
}
Example #13
0
static int write_relation(SDatasource *ds, const SRelation *rel,
						  int num_tiers, float end_time, s_erc *error)
{
	const char *relname;
	const SItem *head = NULL;
	const char *tier_header = "\titem [%d]:\n\t\tclass = \"IntervalTier\"\n\t\tname = \"%s\"\n";
	const char *tier_start_end = "\t\txmin = 0\n\t\txmax = %f\n";
	const char *tier_intervals = "\t\tintervals: size = %d\n";
	const char *tier_item = " \t\tintervals [%d]:\n\t\t\txmin = %f\n\t\t\txmax = %f\n\t\t\ttext = \"%s\"\n";
	char *buff;
	size_t str_size;
	float prev_end = 0.0;
	const SItem *itr;
	float item_start = 0.0;
	float item_end = 0.0;
	const char *item_name = NULL;
	SList *info;
	size_t l_size;
	int counter;
	SIterator *litr;


	S_CLR_ERR(error);
	if (rel == NULL)
		return num_tiers;

	num_tiers += 1;
	relname = SRelationName(rel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"SRelationName\" failed"))
		return 0;

	head = SRelationHead(rel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"SRelationHead\" failed"))
		return 0;

	/* tier header */
	s_asprintf(&buff, error, tier_header, num_tiers, relname);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"s_asprintf\" failed"))
		return 0;

	str_size = s_strsize(buff, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"s_strsize\" failed"))
	{
		S_FREE(buff);
		return 0;
	}

	SDatasourceWrite(ds, buff, sizeof(char), str_size, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"SDatasourceWrite\" failed"))
	{
		S_FREE(buff);
		return 0;
	}

	S_FREE(buff);

	/* start time and end time (always 0 and utt end) */
	s_asprintf(&buff, error, tier_start_end, end_time);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"s_asprintf\" failed"))
		return 0;

	str_size = s_strsize(buff, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"s_strsize\" failed"))
	{
		S_FREE(buff);
		return 0;
	}

	SDatasourceWrite(ds, buff, sizeof(char), str_size, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"SDatasourceWrite\" failed"))
	{
		S_FREE(buff);
		return 0;
	}

	S_FREE(buff);

	info = S_LIST(S_NEW(SListList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Failed to create new list for info cache"))
		return 0;

	prev_end = 0.0;
	itr = head;
	while (itr != NULL)
	{
		item_start = get_start(itr, relname, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"get_start\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			return 0;
		}

		item_end = get_end(itr, relname, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"get_end\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			return 0;
		}

		if (!s_float_equal(item_start, prev_end))
		{
			/* prepend extra "SIL" */
			add_info(info, prev_end, item_start, "SIL", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "write_relation",
						  "Call to \"add_info\" failed"))
			{
				S_DELETE(info, "write_relation", error);
				return 0;
			}
		}

		item_name = SItemGetName(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SItemGetName\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			return 0;
		}

		add_info(info, item_start, item_end, item_name, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"add_info\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			return 0;
		}

		prev_end = item_end;
		itr = SItemNext(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SItemNext\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			return 0;
		}
	}

	if (!s_float_equal(item_end, end_time))
	{
		add_info(info, item_end, end_time, "SIL", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"add_info\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			return 0;
		}
	}

	l_size = SListSize(info, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"SListSize\" failed"))
	{
		S_DELETE(info, "write_relation", error);
		return 0;
	}

	/* tier intervals */
	s_asprintf(&buff, error, tier_intervals, l_size);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"s_asprintf\" failed"))
	{
		S_DELETE(info, "write_relation", error);
		return 0;
	}

	str_size = s_strsize(buff, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"s_strsize\" failed"))
	{
		S_FREE(buff);
		S_DELETE(info, "write_relation", error);
		return 0;
	}

	SDatasourceWrite(ds, buff, sizeof(char), str_size, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"SDatasourceWrite\" failed"))
	{
		S_FREE(buff);
		S_DELETE(info, "write_relation", error);
		return 0;
	}

	S_FREE(buff);

	litr = S_ITERATOR_GET(info, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "write_relation",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(info, "write_relation", error);
		return 0;
	}

	for (counter = 1; litr != NULL; litr = SIteratorNext(litr), counter++)
	{
		SList *itemList;
		SObject *tmp;
		char *name;


		itemList = S_LIST(SIteratorObject(litr, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			return 0;
		}

		tmp = SListPop(itemList, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			return 0;
		}

		item_name = SObjectGetString(tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SObjectGetString\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_DELETE(tmp, "write_relation", error);
			return 0;
		}

		name = s_strdup(item_name, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"s_strdup\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_DELETE(tmp, "write_relation", error);
			return 0;
		}

		S_DELETE(tmp, "write_relation", error);

		tmp = SListPop(itemList, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		item_end = SObjectGetFloat(tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SObjectGetFloat\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_DELETE(tmp, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		S_DELETE(tmp, "write_relation", error);

		tmp = SListPop(itemList, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		item_start = SObjectGetFloat(tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SObjectGetFloat\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_DELETE(tmp, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		S_DELETE(tmp, "write_relation", error);

		/* tier item */
		s_asprintf(&buff, error, tier_item, counter, item_start, item_end, name);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"s_asprintf\" failed"))
		{
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		str_size = s_strsize(buff, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"s_strsize\" failed"))
		{
			S_FREE(buff);
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		SDatasourceWrite(ds, buff, sizeof(char), str_size, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "write_relation",
					  "Call to \"SDatasourceWrite\" failed"))
		{
			S_FREE(buff);
			S_DELETE(info, "write_relation", error);
			S_DELETE(litr, "write_relation", error);
			S_FREE(name);
			return 0;
		}

		S_FREE(buff);
		S_FREE(name);
	}

	S_DELETE(info, "write_relation", error);
	return num_tiers;
}
Example #14
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;
	SItem *wordItemcopy;
	char *downcase_word;
	SList *phones;
	s_bool syllabified;
	SList *syllablesPhones;
	SItem *sylStructureWordItem;
	SItem *syllableItem;
	SItem *sylStructSylItem;
	SItem *segmentItem;
	SIterator *sylItr = NULL;
	SIterator *phoneItr = NULL;
	const SObject *phone;
	s_bool is_present;


	S_CLR_ERR(error);
	s_get_lexical_objects(self, utt, &g2p, &lexicon, &addendum, &syllab, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"s_get_lexical_objects\" failed"))
		goto quit_error;

	/* we require the word relation */
	is_present = SUtteranceRelationIsPresent(utt, "Word", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceRelationIsPresent\" failed"))
		goto quit_error;

	if (!is_present)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "Run",
				  "Failed to find 'Word' relation in utterance");
		goto quit_error;
	}

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

	/* create relations */
	syllableRel = SUtteranceNewRelation(utt, "Syllable", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceNewRelation\" failed"))
		goto quit_error;

	sylStructRel = SUtteranceNewRelation(utt, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceNewRelation\" failed"))
		goto quit_error;

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

	/* start at the first item in the word relation, cast away
	 * const, we want to add daughter items.
	 * iterate over the word relation and fill in the
	 * phones and the associated structure.
	 */
	wordItem = (SItem*)SRelationHead(wordRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SRelationHead\" failed"))
		goto quit_error;

	wordItemcopy = (SItem*)SRelationHead(wordRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SRelationHead\" failed"))
		goto quit_error;

	while (wordItem != NULL)
	{
		/* get word and downcase it */
		downcase_word = s_strlwr(s_strdup(SItemGetName(wordItem, error), error), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Failed to down-case word item"))
			goto quit_error;

		if  (downcase_word == NULL || s_strcmp(downcase_word, "", error) == 0)
			goto continue_cycle;

		phones = NULL;
		syllabified = FALSE;

		/* get phone sequence for word */
		if (addendum != NULL)
		{
			phones = S_ADDENDUM_CALL(addendum, get_word)(addendum,
														 downcase_word,
														 NULL,
														 &syllabified,
														 error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to method \"get_word\" (SAddendum) failed"))
				goto quit_error;
		}

		if ((phones == NULL) && (lexicon != NULL))
		{
			phones = S_LEXICON_CALL(lexicon, get_word)(lexicon,
													   downcase_word,
													   NULL,
													   &syllabified,
													   error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to method \"get_word\" (SLexicon) failed"))
				goto quit_error;
		}

		if ((phones == NULL) && (g2p != NULL))
		{
			phones = S_G2P_CALL(g2p, apply)(g2p, downcase_word, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to method \"apply\" (SG2P) failed"))
				goto quit_error;
		}

		if (phones == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "Run",
					  "Failed to get phone sequence for word '%s'", downcase_word);
			S_FREE(downcase_word);
			continue;
		}

		S_FREE(downcase_word);

		/* syllabify phone sequence */
		if (syllabified == FALSE)
		{
			if (syllab != NULL)
			{
				syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab,
																			wordItem,
																			phones,
																			error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to method \"syllabify\" failed"))
					goto quit_error;

				S_DELETE(phones, "Run", error);
			}
			else
			{
				syllablesPhones = S_LIST(S_NEW(SListList, error));
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Failed to create new 'SList' object"))
					goto quit_error;

				SListAppend(syllablesPhones, S_OBJECT(phones), error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SListAppend\" failed"))
					goto quit_error;
			}
		}
		else
			syllablesPhones = (SList*)phones;

		/* create new syllable structure word item, shares content
		 * with word item.
		 */
		sylStructureWordItem = SRelationAppend(sylStructRel, wordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SRelationAppend\" failed"))
			goto quit_error;

		/* iterate over syllables */
		sylItr = S_ITERATOR_GET(syllablesPhones, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"S_ITERATOR_GET\" failed"))
			goto quit_error;

		while (sylItr != NULL)
		{
			/* new item in syllable relation */
			syllableItem = SRelationAppend(syllableRel, NULL, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SRelationAppend\" failed"))
				goto quit_error;

			SItemSetName(syllableItem, "syl", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemSetName\" failed"))
				goto quit_error;

			/* daughter of above item, but in SylStructure */
			sylStructSylItem = SItemAddDaughter(sylStructureWordItem, syllableItem, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"SItemAddDaughter\" failed"))
				goto quit_error;

			/* iterate over phones and add segments */
			phoneItr = S_ITERATOR_GET((SList*)SIteratorObject(sylItr, error), error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "Run",
						  "Call to \"S_ITERATOR_GET/SIteratorObject\" failed"))
				goto quit_error;

			while (phoneItr != NULL)
			{
				phone = SIteratorObject(phoneItr, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SIteratorObject\" failed"))
					goto quit_error;

				segmentItem = SRelationAppend(segmentRel, NULL, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SRelationAppend\" failed"))
					goto quit_error;

				SItemSetName(segmentItem, SObjectGetString(phone, error), error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SItemSetName/SObjectGetString\" failed"))
					goto quit_error;

				SItemAddDaughter(sylStructSylItem, segmentItem, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SItemAddDaughter\" failed"))
					goto quit_error;

				phoneItr = SIteratorNext(phoneItr);
			}


			sylItr = SIteratorNext(sylItr);
		}

		S_DELETE(syllablesPhones, "Run", error);
continue_cycle:
		wordItem = SItemNext(wordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			goto quit_error;
	}

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

	while (wordItem != NULL)
	{
		const SFeatProcessor* featproc = SUttProcessorGetFeature(self, "_stress_func", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SUttProcessorGetFeature\" failed"))
			goto quit_error;


		s_compute_stresses(featproc, wordItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_compute_stresses\" failed"))
			goto quit_error;

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

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

	/* here all is OK */
	return;


	/* error clean-up code */
quit_error:
	if (syllableRel != NULL)
	{
		SUtteranceDelRelation(utt, "Syllable", error);
		S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceDelRelation\" failed");
	}

	if (sylStructRel != NULL)
	{
		SUtteranceDelRelation(utt, "SylStructure", error);
		S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceDelRelation\" failed");
	}

	if (segmentRel != NULL)
	{
		SUtteranceDelRelation(utt, "Segment", error);
		S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SUtteranceDelRelation\" failed");
	}

	if (sylItr != NULL)
		S_DELETE(sylItr, "Run", error);

	if (phoneItr != NULL)
		S_DELETE(phoneItr, "Run", error);

	self = NULL;
}
Example #15
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;
}