Exemplo n.º 1
0
// Loads a model from mgr, including the dictionary only if lang is not null.
bool LSTMRecognizer::Load(const char* lang, TessdataManager* mgr) {
  TFile fp;
  if (!mgr->GetComponent(TESSDATA_LSTM, &fp)) return false;
  if (!DeSerialize(mgr, &fp)) return false;
  if (lang == nullptr) return true;
  // Allow it to run without a dictionary.
  LoadDictionary(lang, mgr);
  return true;
}
Exemplo n.º 2
0
int main() {
	LoadDictionary("dictionary.txt");
	
	const char * test1results[] = { "ait", "qat", "dae", "quiz", "zed", "zax", "zit", "zea", "aue", "eau", "eat", "adz", "tuque", "ita", "quat", "qua", "uta", "tui", "tix", "tai", "tae", "taxi", "tau", "tax", "tad", "daut", "daze", "zati", "aitu", "adze", "quai", "quad", "quit", "taed" };
	const int test1count = 34;
	const int test1score = 35;
	Results results1 = FindWords("dzxeaiqut", 3, 3);
	checkEquals(results1, test1results, test1count, test1score, "test1");
	FreeWords(results1);

	const char * test2results[] = { "ply", "flir", "eik", "oye", "yuk", "wye", "reik", "wey", "rei", "plue", "ewt", "euk", "ire", "rew", "rue", "tye", "kir", "top", "toph", "lure", "ruly", "toy", "ure", "puer", "tyer", "lie", "yup", "pot", "yew", "fly", "uey", "puli", "upo", "lye", "ilk", "opt", "plu", "lur", "eyot", "kue", "poh", "phot", "pho", "pye", "flukier", "puy", "pul", "hot", "pur", "jot", "joy", "hop", "hoy", "flu", "weir", "oyer", "weil", "plie", "typo", "yeuk", "iure", "pyot", "puir", "pulk", "puly", "pure", "puri", "lire", "lier", "lieu", "erupt", "kilp", "kier", "kuri", "toyer", "glue", "flue", "twyer", "plier", "plyer", "pulik", "gluer", "gluey", "glyph", "fluyt", "fluey", "flier", "flyer", "yukier", "pulier", "gluier", "fluier" };
	const int test2count = 92;
	const int test2score = 117;
	Results results2 = FindWords("qwertyuioplkjhgf", 4, 4);
	checkEquals(results2, test2results, test2count, test2score, "test2");
	FreeWords(results2);

	const char * test3results[] = { "lou", "mol", "cert", "wex", "holk", "rew", "jupon", "mon", "upon", "rec", "rev", "crew", "poh", "rex", "vex", "hom", "mop", "mou", "til", "noh", "nom", "jol", "only", "kit", "lit", "once", "pol", "noup", "pom", "oup", "lop", "ilk", "upo", "hop", "hon", "holy", "wert", "moly", "reck", "trew", "oncer", "vert", "verb", "brew", "moup", "klik", "polk", "poly", "loup", "treck", "ponce" };
	const int test3count = 51;
	const int test3score = 55;
	Results results3 = FindWords("qwertzxcvbmnjklpolkiujhyt", 5, 5);
	checkEquals(results3, test3results, test3count, test3score, "test3");
	FreeWords(results3);

	const char * test4results[] = { "dad", "add", "dada" };
	const int test4count = 3;
	const int test4score = 3;
	Results results4 = FindWords("dadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadadada", 10, 10);
	checkEquals(results4, test4results, test4count, test4score, "test4");
	FreeWords(results4);

	const char * test5results[] = { "not", "bos", "oon", "bone", "tote", "noo", "non", "nebs", "nos", "bosket", "tete", "nek", "tee", "oot", "nonettos", "keb", "ono", "kons", "tot", "bon", "oos", "sot", "ons", "ten", "snoeks", "tet", "ketones", "oke", "sooks", "ton", "bot", "sen", "books", "too", "tene", "otto", "een", "kon", "note", "ene", "obe", "set", "sneb", "boo", "eek", "bet", "toot", "bee", "ben", "tone", "teen", "toetoe", "obo", "bootee", "sob", "one", "skeet", "ket", "tes", "tokens", "toe", "bes", "skeen", "nene", "eon", "ken", "nob", "net", "knees", "nee", "onos", "neb", "betook", "ens", "bonnet", "bete", "son", "neon", "obs", "oes", "bonks", "ose", "see", "nott", "besee", "noon", "nook", "oons", "ketone", "oont", "toes", "tent", "toon", "tons", "beento", "nenes", "kens", "eons", "took", "ebon", "boose", "eten", "book", "boot", "knot", "boon", "bott", "been", "nonbook", "beet", "bene", "koto", "bent", "bonk", "onto", "keto", "seen", "kete", "ones", "keet", "botone", "toko", "toke", "none", "nett", "nete", "tonk", "sone", "teek", "snot", "snob", "sook", "etens", "soot", "neks", "soon", "nobs", "noes", "okes", "nose", "oose", "tose", "beset", "boos", "tenons", "knee", "keen", "sket", "kebs", "besot", "keno", "kent", "knob", "toetoes", "obos", "tees", "ebook", "tens", "sett", "sekt", "sent", "snee", "seek", "sene", "tenon", "skee", "sken", "skeo", "notebook", "esne", "bosk", "bees", "bens", "obes", "enes", "noons", "nooks", "ottos", "tenet", "tenno", "tenne", "toons", "botte", "bonne", "beton", "benet", "benne", "bento", "boons", "tokes", "token", "nonet", "obento", "neons", "snook", "noose", "nones", "tonne", "tonks", "beknot", "teens", "tones", "snoot", "snoke", "snoek", "soote", "nonette", "notes", "bones", "totes", "onset", "boson", "kotos", "keeno", "kenos", "kente", "netes", "teene", "tense", "tetes", "ebons", "sonne", "seton", "sente", "tenes", "betes", "benes", "obese", "nektons", "neese", "betokens", "nebek", "knobs", "tennos", "tennes", "betons", "entetee", "bennet", "bonnes", "bennes", "ketose", "tonnes", "snooks", "snokes", "sootes", "bookoo", "bottes", "ketene", "keenos", "kennet", "nekton", "tenson", "entete", "settee", "sonnes", "setons", "sennet", "sonnet", "beseen", "nebeks", "botonee", "boneset", "betoken", "nonetto", "tonette", "bookoos", "bootees", "kennett", "ketenes", "nonbooks", "botonnee", "nonettes", "tonettes", "nonobese" };
	const int test5count = 274;
	const int test5score = 559;
	Results results5 = FindWords("notebooknotenotesnotnotebooknotenotesnotnotebooknotenotesnotnotebooknotenotesnotnotebooknotenotesnotnotebooknotenotesnotnotebooknotenotesnotnotebooknotenotesnot", 8, 20);
	checkEquals(results5, test5results, test5count, test5score, "test5");
	FreeWords(results5);

	FreeDictionary();

	std::cout << "Done!" << std::endl;

	return 0;
}
Exemplo n.º 3
0
void MyFrame::OnTools(wxCommandEvent& event)
{//=========================================
	int err;
	FILE *log;
	int debug_flag=0;
	char fname_log[sizeof(path_dsource)+12];
	char err_fname[sizeof(path_home)+15];

	switch(event.GetId())
	{
	case MENU_TEST:
		TestTest(0);
		break;

	case MENU_TEST2:
		TestTest(2);
		break;

	case MENU_TO_UTF8:
		ConvertToUtf8();
		break;

	case MENU_COUNT_WORDS:
		MakeWordFreqList();
		break;

	case MENU_LEXICON_RU:
	case MENU_LEXICON_BG:
	case MENU_LEXICON_DE:
	case MENU_LEXICON_IT:
	case MENU_LEXICON_TEST:
		CompareLexicon(event.GetId());  // Compare a lexicon with _rules translation
		break;

	case MENU_COMPILE_PH:
		CompilePhonemeData();
		SetVoiceTitle(voice_name2);
		break;

	case MENU_COMPILE_PH2:
		CompileSampleRate();
		SetVoiceTitle(voice_name2);
		break;

	case MENU_COMPILE_MBROLA:
		CompileMbrola();
		break;

	case MENU_COMPILE_INTONATION:
		CompileIntonation();
		break;

	case MENU_COMPILE_DICT_DEBUG:
		debug_flag =1;  // and drop through to next case
	case MENU_COMPILE_DICT:
		sprintf(fname_log,"%s%s",path_dsource,"dict_log");
		log = fopen(fname_log,"w");

		LoadDictionary(translator, translator->dictionary_name, 0);
		if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0)
		{
			wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));

			wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
			if(!dir.IsEmpty())
			{
				path_dictsource = dir;
				strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
				strcat(path_dsource,"/");
			}
			break;
		}
		wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);

		if(log != NULL)
		{
			fclose(log);

			if(err > 0)
			{
				// display the error messages
				DisplayErrorFile(fname_log);
			}
		}
		break;

	case MENU_FORMAT_DICTIONARY:
		DictionaryFormat(dictionary_name);
		break;

	case MENU_SORT_DICTIONARY:
		DictionarySort(dictionary_name);
		break;

	case MENU_VOWELCHART1:
		MakeVowelLists();
		break;

	case MENU_VOWELCHART2:
		VowelChart(2,NULL);
		break;

	case MENU_VOWELCHART3:
		VowelChart(3,NULL);
		break;

	case MENU_LOAD_WAV:
//		LoadWavFile();
		break;
	}
}
Exemplo n.º 4
0
voice_t *LoadVoice(const char *vname, int control)
{//===============================================
// control, bit 0  1= no_default
//          bit 1  1 = change tone only, not language
//          bit 2  1 = don't report error on LoadDictionary
//          bit 4  1 = vname = full path

	FILE *f_voice = NULL;
	char *p;
	int  key;
	int  ix;
	int  n;
	int  value;
	int  value2;
	int  langix = 0;
	int  tone_only = control & 2;
	int  language_set = 0;
	int  phonemes_set = 0;
	int  stress_amps_set = 0;
	int  stress_lengths_set = 0;
	int  stress_add_set = 0;
	int  conditional_rules = 0;
	LANGUAGE_OPTIONS *langopts = NULL;

	Translator *new_translator = NULL;

	char voicename[40];
	char language_name[40];
	char translator_name[40];
	char new_dictionary[40];
	char phonemes_name[40];
	char option_name[40];
	const char *language_type;
	char buf[sizeof(path_home)+30];
	char path_voices[sizeof(path_home)+12];

	int dict_min = 0;
	int stress_amps[8];
	int stress_lengths[8];
	int stress_add[8];
	char names[8][40];
	char name1[40];
	char name2[80];
	const char *voice_dir;

	int pitch1;
	int pitch2;

	static char voice_identifier[40];  // file name for  current_voice_selected
	static char voice_name[40];        // voice name for current_voice_selected
	static char voice_languages[100];  // list of languages and priorities for current_voice_selected

	// which directory to look for a named voice. List of voice names, must end in a space.
	static const char *voices_asia =
		"az bn fa fa-pin gu hi hy hy-west id ka kn ku ml ms ne pa ta te tr vi vi-hue vi-sgn zh zh-yue ";
	static const char *voices_europe =
		"an bg bs ca cs cy da de el en en-us es et eu fi fr fr-be ga hr hu is it lt lv mk nl no pl pt-pt ro ru sk sq sr sv ";


	strncpy0(voicename, vname, sizeof(voicename));
	if(control & 0x10)
	{
		strcpy(buf,vname);
		if(GetFileLength(buf) <= 0)
			return(NULL);
	}
	else
	{
		if(voicename[0]==0)
			strcpy(voicename,"default");

		sprintf(path_voices,"%s%cvoices%c",path_home,PATHSEP,PATHSEP);
		sprintf(buf,"%s%s",path_voices,voicename);  // first, look in the main voices directory

		if(GetFileLength(buf) <= 0)
		{
			// then look in the appropriate subdirectory
			if((voicename[0]=='m') && (voicename[1]=='b'))
			{
				voice_dir = "mb";   // mbrola voices
			}
			else
			{
				sprintf(name2, "%s ", voicename);
				if(strstr(voices_europe, voicename) != NULL)
					voice_dir = "europe";
				else if(strstr(voices_asia, voicename) != NULL)
					voice_dir = "asia";
				else
					voice_dir = "other";

				sprintf(buf,"%s%s%c%s", path_voices,voice_dir,PATHSEP,voicename);

				if(GetFileLength(buf) <= 0)
				{
					// if not found, look in "test" sub-directory
					sprintf(buf,"%stest%c%s",path_voices,PATHSEP,voicename);
				}
			}
		}
	}

	f_voice = fopen(buf,"r");

	language_type = "en";    // default
	if(f_voice == NULL)
	{
		if(control & 3)
			return(NULL);  // can't open file

		if(SelectPhonemeTableName(voicename) >= 0)
			language_type = voicename;
	}

	if(!tone_only && (translator != NULL))
	{
		DeleteTranslator(translator);
		translator = NULL;
	}

	strcpy(translator_name,language_type);
	strcpy(new_dictionary,language_type);
	strcpy(phonemes_name,language_type);


	if(!tone_only)
	{
		voice = &voicedata;
		strncpy0(voice_identifier,vname,sizeof(voice_identifier));
		voice_name[0] = 0;
		voice_languages[0] = 0;

		current_voice_selected.identifier = voice_identifier;
		current_voice_selected.name = voice_name;
		current_voice_selected.languages = voice_languages;
	}
	else
	{
		// append the variant file name to the voice identifier
		if((p = strchr(voice_identifier,'+')) != NULL)
			*p = 0;    // remove previous variant name
		sprintf(buf,"+%s",&vname[3]);    // omit  !v/  from the variant filename
		strcat(voice_identifier,buf);
		langopts = &translator->langopts;
	}
	VoiceReset(tone_only);

	if(!tone_only)
		SelectPhonemeTableName(phonemes_name);  // set up phoneme_tab


	while((f_voice != NULL) && (fgets_strip(buf,sizeof(buf),f_voice) != NULL))
	{
		// isolate the attribute name
		for(p=buf; (*p != 0) && !isspace(*p); p++);
		*p++ = 0;

		if(buf[0] == 0) continue;

		key = LookupMnem(keyword_tab, buf);

		switch(key)
		{
		case V_LANGUAGE:
		{
			unsigned int len;
			int priority;

			if(tone_only)
				break;

			priority = DEFAULT_LANGUAGE_PRIORITY;
			language_name[0] = 0;

			sscanf(p,"%s %d",language_name,&priority);
			if(strcmp(language_name,"variant") == 0)
				break;

			len = strlen(language_name) + 2;
			// check for space in languages[]
			if(len < (sizeof(voice_languages)-langix-1))
			{
				voice_languages[langix] = priority;

				strcpy(&voice_languages[langix+1],language_name);
				langix += len;
			}

			// only act on the first language line
			if(language_set == 0)
			{
				language_type = strtok(language_name,"-");
				language_set = 1;
				strcpy(translator_name,language_type);
				strcpy(new_dictionary,language_type);
				strcpy(phonemes_name,language_type);
				SelectPhonemeTableName(phonemes_name);

				if(new_translator != NULL)
					DeleteTranslator(new_translator);

				new_translator = SelectTranslator(translator_name);
				langopts = &new_translator->langopts;
				strncpy0(voice->language_name, language_name, sizeof(voice->language_name));
			}
		}
		break;

		case V_NAME:
			if(tone_only == 0)
			{
				while(isspace(*p)) p++;
				strncpy0(voice_name,p,sizeof(voice_name));
			}
			break;

		case V_GENDER:
		{
			int age = 0;
			char vgender[80];
			sscanf(p,"%s %d",vgender,&age);
			current_voice_selected.gender = LookupMnem(genders,vgender);
			current_voice_selected.age = age;
		}
		break;

		case V_TRANSLATOR:
			if(tone_only) break;

			sscanf(p,"%s",translator_name);

			if(new_translator != NULL)
				DeleteTranslator(new_translator);

			new_translator = SelectTranslator(translator_name);
			langopts = &new_translator->langopts;
			break;

		case V_DICTIONARY:        // dictionary
			sscanf(p,"%s",new_dictionary);
			break;

		case V_PHONEMES:        // phoneme table
			sscanf(p,"%s",phonemes_name);
			break;

		case V_FORMANT:
			VoiceFormant(p);
			break;

		case V_PITCH:
		{
			double factor;
			// default is  pitch 82 118
			n = sscanf(p,"%d %d",&pitch1,&pitch2);
			voice->pitch_base = (pitch1 - 9) << 12;
			voice->pitch_range = (pitch2 - pitch1) * 108;
			factor = (double)(pitch1 - 82)/82;
			voice->formant_factor = (int)((1+factor/4) * 256);  // nominal formant shift for a different voice pitch
		}
		break;

		case V_STRESSLENGTH:   // stressLength
			stress_lengths_set = Read8Numbers(p,stress_lengths);
			break;

		case V_STRESSAMP:   // stressAmp
			stress_amps_set = Read8Numbers(p,stress_amps);
			break;

		case V_STRESSADD:   // stressAdd
			stress_add_set = Read8Numbers(p,stress_add);
			break;

		case V_INTONATION:   // intonation
			sscanf(p,"%d %d",&option_tone_flags,&option_tone2);
			if((option_tone_flags & 0xff) != 0)
				langopts->intonation_group = option_tone_flags & 0xff;
			break;

		case V_TUNES:
			n = sscanf(p,"%s %s %s %s %s %s",names[0],names[1],names[2],names[3],names[4],names[5]);
			langopts->intonation_group = 0;
			for(ix=0; ix<n; ix++)
			{
				if(strcmp(names[ix],"NULL")==0)
					continue;

				if((value = LookupTune(names[ix])) < 0)
					fprintf(stderr,"Unknown tune '%s'\n",names[ix]);
				else
					langopts->tunes[ix] = value;
			}
			break;

		case V_DICTRULES:   // conditional dictionary rules and list entries
		case V_NUMBERS:
		case V_STRESSOPT:
			// expect a list of numbers
			while(*p != 0)
			{
				while(isspace(*p)) p++;
				n = -1;
				if((n = atoi(p)) > 0)
				{
					p++;
					if(n < 32)
					{
						if(key==V_DICTRULES)
							conditional_rules |= (1 << n);
						else if(key==V_NUMBERS)
							langopts->numbers |= (1 << n);
						else if(key==V_STRESSOPT)
							langopts->stress_flags |= (1 << n);
					}
					else
					{
						if((key==V_NUMBERS) && (n < 64))
							langopts->numbers |= (1 << (n-32));
						else
							fprintf(stderr,"Bad option number %d\n", n);
					}
				}
				while(isalnum(*p)) p++;
			}
			ProcessLanguageOptions(langopts);
			break;

		case V_REPLACE:
			if(phonemes_set == 0)
			{
				// must set up a phoneme table before we can lookup phoneme mnemonics
				SelectPhonemeTableName(phonemes_name);
				phonemes_set = 1;
			}
			PhonemeReplacement(key,p);
			break;

		case V_WORDGAP:   // words
			sscanf(p,"%d %d",&langopts->word_gap, &langopts->vowel_pause);
			break;

		case V_STRESSRULE:
			sscanf(p,"%d %d %d %d",&langopts->stress_rule,
				   &langopts->stress_flags,
				   &langopts->unstressed_wd1,
				   &langopts->unstressed_wd2);
			break;

		case V_CHARSET:
			if((sscanf(p,"%d",&value)==1) && (value < N_CHARSETS))
				new_translator->charset_a0 = charsets[value];
			break;

		case V_OPTION:
			value2 = 0;
			if(((sscanf(p,"%s %d %d",option_name,&value,&value2) >= 2) && ((ix = LookupMnem(options_tab, option_name)) >= 0)) ||
				((sscanf(p,"%d %d %d",&ix,&value,&value2) >= 2) && (ix < N_LOPTS)))
			{
				langopts->param[ix] = value;
				langopts->param2[ix] = value2;
			}
			else
			{
				fprintf(stderr,"Bad voice option: %s %s\n",buf,p);
			}
			break;

		case V_ECHO:
			// echo.  suggest: 135mS  11%
			value = 0;
			voice->echo_amp = 0;
			sscanf(p,"%d %d",&voice->echo_delay,&voice->echo_amp);
			break;

		case V_FLUTTER:   // flutter
			if(sscanf(p,"%d",&value)==1)
				voice->flutter = value * 32;
			break;

		case V_ROUGHNESS:   // roughness
			if(sscanf(p,"%d",&value)==1)
				voice->roughness = value;
			break;

		case V_CLARITY:  // formantshape
			if(sscanf(p,"%d",&value)==1)
			{
				if(value > 4)
				{
					voice->peak_shape = 1;  // squarer formant peaks
					value = 4;
				}
				voice->n_harmonic_peaks = 1+value;
			}
			break;

		case V_TONE:
		{
			int tone_data[12];
			ReadTonePoints(p,tone_data);
			SetToneAdjust(voice,tone_data);
		}
		break;

		case V_VOICING:
			if(sscanf(p,"%d",&value)==1)
				voice->voicing = (value * 64)/100;
			break;

		case V_BREATH:
			voice->breath[0] = Read8Numbers(p,&voice->breath[1]);
			for(ix=1; ix<8; ix++)
			{
				if(ix % 2)
					voice->breath[ix] = -voice->breath[ix];
			}
			break;

		case V_BREATHW:
			voice->breathw[0] = Read8Numbers(p,&voice->breathw[1]);
			break;

		case V_CONSONANTS:
			value = sscanf(p,"%d %d",&voice->consonant_amp, &voice->consonant_ampv);
			break;

		case V_SPEED:
			sscanf(p,"%d",&voice->speed_percent);
			break;

		case V_MBROLA:
		{
			int srate = 16000;

			name2[0] = 0;
			sscanf(p,"%s %s %d",name1,name2,&srate);
			if(LoadMbrolaTable(name1,name2,srate) != EE_OK)
			{
				fprintf(stderr,"mbrola voice not found\n");
			}
			voice->samplerate = srate;
		}
		break;

		case V_KLATT:
			voice->klattv[0] = 1;  // default source: IMPULSIVE
			Read8Numbers(p,voice->klattv);
			voice->klattv[KLATT_Kopen] -= 40;
			break;

		case V_FAST:
			Read8Numbers(p,speed.fast_settings);
			SetSpeed(3);
			break;

		case V_DICTMIN:
			sscanf(p,"%d",&dict_min);
			break;

		case V_ALPHABET2:
			{
				ALPHABET *alphabet;
				name1[0] = name2[0] = 0;
				sscanf(p, "%s %s", name1, name2);

				if(strcmp(name1, "latin") == 0)
				{
					strncpy0(langopts->ascii_language,name2,sizeof(langopts->ascii_language));
				}
				else if((alphabet = AlphabetFromName(name1)) != 0)
				{
					langopts->alt_alphabet = alphabet->offset;
					langopts->alt_alphabet_lang = StringToWord2(name2);
				}
				else
				{
					fprintf(stderr,"alphabet name '%s' not found\n", name1);
				}
			}
			break;

		case V_DICTDIALECT:
			// specify a dialect to use for foreign words, eg, en-us for _^_EN
			if(sscanf(p, "%s", name1) == 1)
			{
				if((ix = LookupMnem(dict_dialects, name1)) > 0)
				{
					langopts->dict_dialect |= (1 << ix);
				}
				else
				{
					fprintf(stderr, "dictdialect name '%s' not recognized\n", name1);
				}
			}
			break;

		default:
			if((key & 0xff00) == 0x100)
			{
				sscanf(p,"%d",&langopts->param[key &0xff]);
			}
			else
			{
				fprintf(stderr,"Bad voice attribute: %s\n",buf);
			}
			break;
		}
	}
	if(f_voice != NULL)
		fclose(f_voice);

	if((new_translator == NULL) && (!tone_only))
	{
		// not set by language attribute
		new_translator = SelectTranslator(translator_name);
	}

	SetSpeed(3);   // for speed_percent

	for(ix=0; ix<N_PEAKS; ix++)
	{
		voice->freq2[ix] = voice->freq[ix];
		voice->height2[ix] = voice->height[ix];
		voice->width2[ix] = voice->width[ix];
	}

	if(tone_only)
	{
		new_translator = translator;
	}
	else
	{
		if((ix = SelectPhonemeTableName(phonemes_name)) < 0)
		{
			fprintf(stderr,"Unknown phoneme table: '%s'\n",phonemes_name);
			ix = 0;
		}
		voice->phoneme_tab_ix = ix;
		new_translator->phoneme_tab_ix = ix;
		new_translator->dict_min_size = dict_min;
		LoadDictionary(new_translator, new_dictionary, control & 4);
		if(dictionary_name[0]==0)
			return(NULL);   // no dictionary loaded

		new_translator->dict_condition = conditional_rules;

		voice_languages[langix] = 0;
	}

	langopts = &new_translator->langopts;


	if((value = langopts->param[LOPT_LENGTH_MODS]) != 0)
	{
		SetLengthMods(new_translator,value);
	}

	voice->width[0] = (voice->width[0] * 105)/100;

	if(!tone_only)
	{
		translator = new_translator;
	}


	// relative lengths of different stress syllables
	for(ix=0; ix<stress_lengths_set; ix++)
	{
		translator->stress_lengths[ix] = stress_lengths[ix];
	}
	for(ix=0; ix<stress_add_set; ix++)
	{
		translator->stress_lengths[ix] += stress_add[ix];
	}
	for(ix=0; ix<stress_amps_set; ix++)
	{
		translator->stress_amps[ix] = stress_amps[ix];
		translator->stress_amps_r[ix] = stress_amps[ix] -1;
	}

	return(voice);
}  //  end of LoadVoice
bool	Satori::load(const string& iBaseFolder)
{
	GetSender().next_event();

	setlocale(LC_ALL, "Japanese");
#ifdef _WINDOWS
	_setmbcp(_MB_CP_LOCALE);
#endif

	mBaseFolder = iBaseFolder;
	GetSender().sender() << "■SATORI::Load on " << mBaseFolder << "" << std::endl;

#if POSIX
	// 「/」で終わっていなければ付ける。
	if (mBaseFolder[mBaseFolder.size() - 1] != '/') {
	    mBaseFolder += '/';
	}
#else
	// 「\」で終わっていなければ付ける。
	if (mBaseFolder[mBaseFolder.size() - 1] != '\\') {
	    mBaseFolder += '\\';
	}
#endif


#ifdef	_MSC_VER
	// 本体のあるフォルダをサーチ
	{
		TCHAR	buf[MAX_PATH+1];
		::GetModuleFileName(NULL, buf, MAX_PATH);
		char*	p = FindFinalChar(buf, DIR_CHAR);
		if ( p==NULL )
			mExeFolder = "";
		else {
			*(++p) = '\0';
			mExeFolder = buf;
		}
	}
	GetSender().sender() << "本体の所在: " << mExeFolder << "" << std::endl;
#endif // _MSC_VER

	// メンバ初期化
	InitMembers();

#ifdef	_MSC_VER
	// システムの設定を読んでおく
    OSVERSIONINFO	ovi;
    ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	::GetVersionEx(&ovi);
	string	os;
	if ( ovi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
		if ( ovi.dwMinorVersion == 0 ) { mOSType=SATORI_OS_WIN95; os="Windows 95"; }
		else if ( ovi.dwMinorVersion == 10 ) { mOSType=SATORI_OS_WIN98; os="Windows 98"; }
		else if ( ovi.dwMinorVersion == 90 ) { mOSType=SATORI_OS_WINME; os="Windows Me"; }
		else { mOSType = SATORI_OS_UNDEFINED; os="undefined"; }
	} else {
		if ( ovi.dwMinorVersion == 0 ) {
			if ( ovi.dwMajorVersion == 4 ) { mOSType=SATORI_OS_WINNT; os="Windows NT"; }
			else if ( ovi.dwMajorVersion == 5 ) { mOSType=SATORI_OS_WIN2K; os="Windows 2000"; }
		}
		else { mOSType = SATORI_OS_WINXP; os="Windows XP or later"; }
	}
	GetSender().sender() << "OS種別: " << os << std::endl;
	if ( mOSType==SATORI_OS_WIN95 ) {
		is_single_monitor = true;
	} else {
		BOOL (WINAPI* pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
		(FARPROC&)pEnumDisplayMonitors = ::GetProcAddress(::GetModuleHandle("user32.dll"), "EnumDisplayMonitors");
		if ( pEnumDisplayMonitors==NULL ) {
			is_single_monitor = true;
		}
		else {
			RECT rectData[2];
			memset(rectData,0,sizeof(rectData));
			(*pEnumDisplayMonitors)(NULL,NULL,(MONITORENUMPROC)MonitorEnumFunc,(LPARAM)(rectData));

			max_screen_rect = rectData[0];
			desktop_rect = rectData[1];

			RECT*	rect;
			rect = &desktop_rect;
			GetSender().sender() << "プライマリデスクトップ: (" << 
				rect->left << "," << rect->top << "," << rect->right << "," << rect->bottom << ")" << std::endl;
			rect = &max_screen_rect;
			GetSender().sender() << "仮想デスクトップ: (" << 
				rect->left << "," << rect->top << "," << rect->right << "," << rect->bottom << ")" << std::endl;
			is_single_monitor = ( ::EqualRect(&max_screen_rect, &desktop_rect)!=FALSE );
			GetSender().sender() << (is_single_monitor ? 
				"モニタは一つだけと判断、見切れ判定を呼び出し元に任せます。" : 
				"複数のモニタが接続されていると判断、見切れ判定は里々が行います。") << std::endl;
		}
	}
#endif // _MSC_VER

	// 置換辞書読み取り
	strmap_from_file(replace_before_dic, mBaseFolder+"replace.txt", "\t");
	strmap_from_file(replace_after_dic, mBaseFolder+"replace_after.txt", "\t");

	// キャラデータ読み込み
	mCharacters.load(mBaseFolder + "characters.ini");
	for ( inimap::const_iterator i=mCharacters.begin() ; i!=mCharacters.end() ; ++i ) {
		const strmap& m = i->second;
		strmap::const_iterator j;

		// 置換辞書に追加
		j = m.find("popular-name");
		if ( j != m.end() && j->second.size()>0 ) 
			replace_before_dic[j->second + ":"] = string("\xff\x01") + zen2han(i->first); //0xff0x01はあとで変換
		j = m.find("initial-letter");
		if ( j != m.end() && j->second.size()>0 ) 
			replace_before_dic[j->second + ":"] = string("\xff\x01") + zen2han(i->first); //0xff0x01はあとで変換

		j = m.find("base-surface");
		if ( j != m.end() && j->second.size()>0 )
			system_variable_operation( string("サーフェス加算値") + i->first, j->second);
	}

	//for ( strmap::const_iterator j=replace_before_dic.begin() ; j!=replace_before_dic.end() ; ++j )
	//	cout << j->first << ": " << j->second << endl;

	// ランダマイズ
	randomize();


	//------------------------------------------

	// コンフィグ読み込み
	LoadDictionary(mBaseFolder + "satori_conf.txt", false);

	// 変数初期化実行
	GetSentence("初期化");	

	// SAORI読み込み
	Family<Word>* f = words.get_family("SAORI");

	mShioriPlugins->load(mBaseFolder);
	
	if ( f != NULL )
	{
		std::vector<const Word*> els;
		f->get_elements_pointers(els);

		for (std::vector<const Word*>::const_iterator i=els.begin(); i!=els.end() ; ++i)
		{
			if ( (*i)->size()>0 && !mShioriPlugins->load_a_plugin(**i) )
			{
				GetSender().sender() << "SAORI読み込み中にエラーが発生: " << **i << std::endl;
			}
		}

	}
	mShioriPlugins->load_default_entry();

	talks.clear();
	words.clear();

	//------------------------------------------

	// セーブデータ読み込み
	//bool oldConf = fEncodeSavedata;

	bool loadResult = LoadDictionary(mBaseFolder + "satori_savedata." + (fEncodeSavedata?"sat":"txt"), false);
	GetSentence("セーブデータ");
	bool execResult = talks.get_family("セーブデータ") != NULL;

	if ( ! loadResult || ! execResult ) {
		loadResult = LoadDictionary(mBaseFolder + "satori_savebackup." + (fEncodeSavedata?"sat":"txt"), false);
		GetSentence("セーブデータ");
		execResult = talks.get_family("セーブデータ") != NULL;
	}

	talks.clear();
	
	reload_flag = false;

	if ( variables.find("ゴースト起動時間累計秒") != variables.end() ) {
		sec_count_total = zen2ul(variables["ゴースト起動時間累計秒"]);
	}
	else if ( variables.find("ゴースト起動時間累計ミリ秒") != variables.end() ) {
		sec_count_total = zen2ul(variables["ゴースト起動時間累計ミリ秒"]) / 1000;
	}
	else {
		sec_count_total = zen2ul(variables["ゴースト起動時間累計(ms)"]) / 1000;
	}
	variables["起動回数"] = itos( zen2int(variables["起動回数"])+1 );

	// 「単語の追加」で登録された単語を覚えておく
	const std::map< string, Family<Word> >& m = words.compatible();
	for (std::map< string, Family<Word> >::const_iterator it = m.begin() ; it != m.end() ; ++it )
	{
		std::vector<const Word*> v;
		it->second.get_elements_pointers(v);
		for (std::vector<const Word*>::const_iterator itx = v.begin() ; itx < v.end() ; ++itx ) {
			mAppendedWords[it->first].push_back(**itx);
		}
	}

	//------------------------------------------

	// 指定フォルダの辞書を読み込み
	int loadcount = 0;
	strvec::iterator i = dic_folder.begin();
	if ( i==dic_folder.end() ) {
		loadcount += LoadDicFolder(mBaseFolder);	// ルートフォルダの辞書
	} else {
		for ( ; i!=dic_folder.end() ; ++i )
			loadcount += LoadDicFolder(mBaseFolder + *i + DIR_CHAR);	// サブフォルダの辞書
	}

	is_dic_loaded = loadcount != 0;

	//------------------------------------------

	secure_flag = true;

	system_variable_operation("単語群「*」の重複回避", "有効、トーク中");
	system_variable_operation("文「*」の重複回避", "有効");
	//system_variable_operation("単語群「季節の食べ物」の重複回避", "有効、トーク中");

	GetSentence("OnSatoriLoad");
	on_loaded_script = GetSentence("OnSatoriBoot");
	diet_script(on_loaded_script);

	GetSender().sender() << "loaded." << std::endl;

	GetSender().flush();
	return	true;
}
Exemplo n.º 6
0
void disassemble(classfile* c)
{		
	Dictionary = malloc(sizeof(opCode_info) * 256);
	LoadDictionary();
	method_info* currentMethod;
	code_attribute* currentCode;

	for(int i = 0; i < c->methods_count; i++)
	{
		currentMethod = c->methods[i];		
		
		currentCode = currentMethod->code;
		unsigned char* method_name = c->constant_pool[currentMethod->name_index - 1]->info;
		
		fprintf(stdout,"Method Name: %s\n", method_name);	

		for(int j = 0; j < currentCode->code_length; j++)
		{
			if(Dictionary[(int)currentCode->code[j]].arg == 0)
			{
				fprintf(stdout,"\t%d %s \n", j, Dictionary[(int)currentCode->code[j]].name);
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 1)
			{				
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg = (int)currentCode->code[j];
				fprintf(stdout, " (%d)\n", arg);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 21)
			{				
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg = (int)currentCode->code[j];
				arg = arg << 8;
				j++;
				arg += (int)currentCode->code[j];
				fprintf(stdout, " (%d)\n", arg);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 22)
			{		
				int index = j;
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				short arg = (unsigned short)currentCode->code[j];
				arg = arg << 8;
				j++;
				arg += (unsigned short)currentCode->code[j];
				arg += index;
				fprintf(stdout, " (%d)\n", arg);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 23)
			{					
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg1 = (int)currentCode->code[j];				
				j++;
				int arg2 = (int)currentCode->code[j];
				fprintf(stdout, " (%d, %d)\n", arg1, arg2);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 3)
			{		
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg1 = (int)currentCode->code[j];
				arg1 = arg1 << 8;
				j++;
				arg1 += (int)currentCode->code[j];
				j++;
				int arg2 = (int)currentCode->code[j];	
				fprintf(stdout, " (%d, %d)\n", arg1, arg2);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 41)
			{		
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg1 = (int)currentCode->code[j];
				arg1 = arg1 << 8;
				j++;
				arg1 += (int)currentCode->code[j];
				j++;
				int arg2 = (int)currentCode->code[j];
				j++;
				int arg3 = (int)currentCode->code[j];
				fprintf(stdout, " (%d, %d, %d)\n", arg1, arg2, arg3);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 42)
			{		
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg1 = (int)currentCode->code[j];
				arg1 = arg1 << 8;
				j++;
				arg1 += (int)currentCode->code[j];
				j++;
				int arg2 = (int)currentCode->code[j];
				j++;
				int arg3 = (int)currentCode->code[j];
				fprintf(stdout, " (%d, %d, %d)\n", arg1, arg2, arg3);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 43)
			{		
				fprintf(stdout,"\t%d %s", j, Dictionary[(int)currentCode->code[j]].name);
				j++;
				int arg1 = (int)currentCode->code[j];
				arg1 = arg1 << 24;
				j++;
				arg1 += (int)currentCode->code[j] << 16;
				j++;
				arg1 += (int)currentCode->code[j] << 8;
				j++;
				arg1 += (int)currentCode->code[j];
				fprintf(stdout, " (%d)\n", arg1);				
			}
			else if(Dictionary[(int)currentCode->code[j]].arg == 44)
			{		
				fprintf(stdout,"\t%d %s:\n", j, Dictionary[(int)currentCode->code[j]].name);				
				int index = j;
				j++;
				while((j % 4) != 0)
					j++;
								
				int defaultValue = (int)currentCode->code[j];
				defaultValue = defaultValue << 24;
				j++;
				defaultValue += (int)currentCode->code[j] << 16;
				j++;
				defaultValue += (int)currentCode->code[j] << 8;
				j++;
				defaultValue += (int)currentCode->code[j];
				defaultValue += index;
				fprintf(stdout, "Default: %d\n", defaultValue);	
				
				j++;
				int lowValue = (int)currentCode->code[j];
				lowValue = lowValue << 24;
				j++;
				lowValue += (int)currentCode->code[j] << 16;
				j++;
				lowValue += (int)currentCode->code[j] << 8;
				j++;
				lowValue += (int)currentCode->code[j];
				fprintf(stdout, "Low: %d\n", lowValue);
				
				j++;
				int highValue = (int)currentCode->code[j];
				highValue = highValue << 24;
				j++;
				highValue += (int)currentCode->code[j] << 16;
				j++;
				highValue += (int)currentCode->code[j] << 8;
				j++;
				highValue += (int)currentCode->code[j];
				fprintf(stdout, "High: %d\n", highValue);
				
				for(int i = lowValue; i < highValue; i++)
				{
					j++;
					int currentVal = (int)currentCode->code[j];
					currentVal = currentVal << 24;
					j++;
					currentVal += (int)currentCode->code[j] << 16;
					j++;
					currentVal += (int)currentCode->code[j] << 8;
					j++;
					currentVal += (int)currentCode->code[j];
					fprintf(stdout, "%d: %d\n", i, currentVal);
				}
			}
		}
		fprintf(stdout, "\n");
	}

}
Exemplo n.º 7
0
voice_t *LoadVoice(const char *vname, int control)
{//===============================================
// control, bit 0  1= no_default
//          bit 1  1 = change tone only, not language
//          bit 2  1 = don't report error on LoadDictionary
//          bit 4  1 = vname = full path

	FILE *f_voice = NULL;
	keywtab_t *k;
	char *p;
	int  key;
	int  ix;
	int  n;
	int  value;
	int  error = 0;
	int  langix = 0;
	int  tone_only = control & 2;
	int  language_set = 0;
	int  phonemes_set = 0;
	int  stress_amps_set = 0;
	int  stress_lengths_set = 0;
	int  stress_add_set = 0;
	int  conditional_rules = 0;
	LANGUAGE_OPTIONS *langopts = NULL;

	Translator *new_translator = NULL;

	char voicename[40];
	char language_name[40];
	char translator_name[40];
	char new_dictionary[40];
	char phonemes_name[40];
	const char *language_type;
	char buf[200];
	char path_voices[sizeof(path_home)+12];
	char langname[4];

	int stress_amps[8];
	int stress_lengths[8];
	int stress_add[8];

	int pitch1;
	int pitch2;

	static char voice_identifier[40];  // file name for  voice_selected
	static char voice_name[40];        // voice name for voice_selected
	static char voice_languages[100];  // list of languages and priorities for voice_selected

	strcpy(voicename,vname);
	if(voicename[0]==0)
		strcpy(voicename,"default");

	if(control & 0x10)
	{
		strcpy(buf,vname);
		if(GetFileLength(buf) <= 0)
			return(NULL);
	}
	else
	{
		sprintf(path_voices,"%s%cvoices%c",path_home,PATHSEP,PATHSEP);
		sprintf(buf,"%s%s",path_voices,voicename);

		if(GetFileLength(buf) <= 0)
		{
			// look for the voice in a sub-directory of the language name
			langname[0] = voicename[0];
			langname[1] = voicename[1];
			langname[2] = 0;
			sprintf(buf,"%s%s%c%s",path_voices,langname,PATHSEP,voicename);

			if(GetFileLength(buf) <= 0)
			{
				// look in "test" sub-directory
				sprintf(buf,"%stest%c%s",path_voices,PATHSEP,voicename);
			}
		}
	}

	f_voice = fopen(buf,"r");

	language_type = "en";    // default
	if(f_voice == NULL)
	{
		if(control & 3)
			return(NULL);  // can't open file

		if(SelectPhonemeTableName(voicename) >= 0)
			language_type = voicename;
	}

	if(!tone_only && (translator != NULL))
	{
		DeleteTranslator(translator);
		translator = NULL;
	}

	strcpy(translator_name,language_type);
	strcpy(new_dictionary,language_type);
	strcpy(phonemes_name,language_type);


	if(!tone_only)
	{
		voice = &voicedata;
		strncpy0(voice_identifier,vname,sizeof(voice_identifier));
		voice_name[0] = 0;
		voice_languages[0] = 0;

		voice_selected.identifier = voice_identifier;
		voice_selected.name = voice_name;
		voice_selected.languages = voice_languages;
	}
	else
	{
		// append the variant file name to the voice identifier
		if((p = strchr(voice_identifier,'+')) != NULL)
			*p = 0;    // remove previous variant name
		sprintf(buf,"+%s",&vname[3]);    // omit  !v/  from the variant filename
		strcat(voice_identifier,buf);
		langopts = &translator->langopts;
	}
	VoiceReset(tone_only);

	if(!tone_only)
		SelectPhonemeTableName(phonemes_name);  // set up phoneme_tab


	while((f_voice != NULL) && (fgets_strip(buf,sizeof(buf),f_voice) != NULL))
	{
		// isolate the attribute name
		for(p=buf; (*p != 0) && !isspace(*p); p++);
		*p++ = 0;

		if(buf[0] == 0) continue;

		key = 0;
		for(k=keyword_tab; k->mnem != NULL; k++)
		{
			if(strcmp(buf,k->mnem)==0)
			{
				key = k->data;
				break;
			}
		}

		switch(key)
		{
		case V_LANGUAGE:
			{
				unsigned int len;
				int priority;

				if(tone_only)
					break;
	
				priority = DEFAULT_LANGUAGE_PRIORITY;
				language_name[0] = 0;
	
				sscanf(p,"%s %d",language_name,&priority);
				if(strcmp(language_name,"variant") == 0)
					break;
	
				len = strlen(language_name) + 2;
				// check for space in languages[]
				if(len < (sizeof(voice_languages)-langix-1))
				{
					voice_languages[langix] = priority;
	
					strcpy(&voice_languages[langix+1],language_name);
					langix += len;
				}
	
				// only act on the first language line
				if(language_set == 0)
				{
					language_type = strtok(language_name,"-");
					language_set = 1;
					strcpy(translator_name,language_type);
					strcpy(new_dictionary,language_type);
					strcpy(phonemes_name,language_type);
					SelectPhonemeTableName(phonemes_name);
		
					if(new_translator != NULL)
							DeleteTranslator(new_translator);
		
					new_translator = SelectTranslator(translator_name);
					langopts = &new_translator->langopts;
				}
			}
			break;

		case V_NAME:
			if(tone_only == 0)
			{
				while(isspace(*p)) p++;
				strncpy0(voice_name,p,sizeof(voice_name));
			}
			break;

		case V_GENDER:
			{
				int age;
				char vgender[80];
				sscanf(p,"%s %d",vgender,&age);
				voice_selected.gender = LookupMnem(genders,vgender);
				voice_selected.age = age;
			}
			break;

		case V_TRANSLATOR:
			if(tone_only) break;

			sscanf(p,"%s",translator_name);

			if(new_translator != NULL)
					DeleteTranslator(new_translator);

			new_translator = SelectTranslator(translator_name);
			langopts = &new_translator->langopts;
			break;

		case V_DICTIONARY:        // dictionary
			sscanf(p,"%s",new_dictionary);
			break;

		case V_PHONEMES:        // phoneme table
			sscanf(p,"%s",phonemes_name);
			break;

		case V_FORMANT:
			VoiceFormant(p);
			break;

		case V_PITCH:
			{
				double factor;
				// default is  pitch 82 118
				n = sscanf(p,"%d %d",&pitch1,&pitch2);
				voice->pitch_base = (pitch1 - 9) << 12;
				voice->pitch_range = (pitch2 - pitch1) * 108;
				factor = double(pitch1 - 82)/82;
				voice->formant_factor = (int)((1+factor/4) * 256);  // nominal formant shift for a different voice pitch
			}
			break;

		case V_STRESSLENGTH:   // stressLength
			stress_lengths_set = Read8Numbers(p,stress_lengths);
			break;

		case V_STRESSAMP:   // stressAmp
			stress_amps_set = Read8Numbers(p,stress_amps);
			break;

		case V_STRESSADD:   // stressAdd
			stress_add_set = Read8Numbers(p,stress_add);
			break;

		case V_INTONATION:   // intonation
			sscanf(p,"%d %d",&option_tone_flags,&option_tone2);
			if((option_tone_flags & 0xff) != 0)
				langopts->intonation_group = option_tone_flags & 0xff;
			break;

		case V_DICTRULES:   // conditional dictionary rules and list entries
			while(*p != 0)
			{
				while(isspace(*p)) p++;
				n = -1;
				if(((n = atoi(p)) > 0) && (n < 32))
				{
					p++;
					conditional_rules |= (1 << n);
				}
				while(isalnum(*p)) p++;
			}
			break;

		case V_REPLACE:
			if(phonemes_set == 0)
			{
				// must set up a phoneme table before we can lookup phoneme mnemonics
				SelectPhonemeTableName(phonemes_name);
				phonemes_set = 1;
			}
			PhonemeReplacement(key,p);
			break;

		case V_WORDGAP:   // words
			sscanf(p,"%d %d",&langopts->word_gap, &langopts->vowel_pause);
			break;

		case V_STRESSRULE:
			sscanf(p,"%d %d %d %d",&langopts->stress_rule,
				&langopts->stress_flags,
				&langopts->unstressed_wd1,
				&langopts->unstressed_wd2);
			break;

		case V_CHARSET:
			if((sscanf(p,"%d",&value)==1) && (value < N_CHARSETS))
				new_translator->charset_a0 = charsets[value];
			break;

		case V_NUMBERS:
			sscanf(p,"%d %d",&langopts->numbers,&langopts->numbers2);
			break;

		case V_OPTION:
			if(sscanf(p,"%d %d",&ix,&value) == 2)
			{
				if((ix >= 0) && (ix < N_LOPTS))
					langopts->param[ix] = value;
			}
			break;

		case V_ECHO:
			// echo.  suggest: 135mS  11%
			value = 0;
			voice->echo_amp = 0;
			sscanf(p,"%d %d",&voice->echo_delay,&voice->echo_amp);
			break;

		case V_FLUTTER:   // flutter
			if(sscanf(p,"%d",&value)==1)
				voice->flutter = value * 32;
			break;

		case V_ROUGHNESS:   // roughness
			if(sscanf(p,"%d",&value)==1)
				voice->roughness = value;
			break;

		case V_CLARITY:  // formantshape
			if(sscanf(p,"%d",&value)==1)
			{
				if(value > 4)
				{
					voice->peak_shape = 1;  // squarer formant peaks
					value = 4;
				}
				voice->n_harmonic_peaks = 1+value;
			}
			break;

		case V_TONE:
			{
				int tone_data[12];
				ReadTonePoints(p,tone_data);
				SetToneAdjust(voice,tone_data);
			}
			break;

		case V_VOICING:
			if(sscanf(p,"%d",&value)==1)
				voice->voicing = (value * 64)/100;
			break;

		case V_BREATH:
				voice->breath[0] = Read8Numbers(p,&voice->breath[1]);
				for(ix=1; ix<8; ix++)
				{
					if(ix % 2)
						voice->breath[ix] = -voice->breath[ix];
				}
			break;

		case V_BREATHW:
				voice->breathw[0] = Read8Numbers(p,&voice->breathw[1]);
			break;

		case V_CONSONANTS:
			value = sscanf(p,"%d %d",&voice->consonant_amp, &voice->consonant_ampv);
			break;

		case V_MBROLA:
			{
				int srate = 16000;
				char name[40];
				char phtrans[40];

				phtrans[0] = 0;
				sscanf(p,"%s %s %d",name,phtrans,&srate);
				LoadMbrolaTable(name,phtrans,srate);
			}
			break;

		case V_KLATT:
			voice->klattv[0] = 1;  // default source: IMPULSIVE
			Read8Numbers(p,voice->klattv);
			voice->klattv[KLATT_Kopen] -= 40;
			break;

		case V_FAST:
			Read8Numbers(p,speed.fast_settings);
			SetSpeed(2);
			break;

		default:
			if((key & 0xff00) == 0x100)
			{
				sscanf(p,"%d",&langopts->param[key &0xff]);
			}
			else
			{
				fprintf(stderr,"Bad voice attribute: %s\n",buf);
			}
			break;
		}
	}
	if(f_voice != NULL)
		fclose(f_voice);

	if((new_translator == NULL) && (!tone_only))
	{
		// not set by language attribute
		new_translator = SelectTranslator(translator_name);
	}

	for(ix=0; ix<N_PEAKS; ix++)
	{
		voice->freq2[ix] = voice->freq[ix];
		voice->height2[ix] = voice->height[ix];
		voice->width2[ix] = voice->width[ix];
	}

	if(tone_only)
	{
		new_translator = translator;
	}
	else
	{
		if((ix = SelectPhonemeTableName(phonemes_name)) < 0)
		{
			fprintf(stderr,"Unknown phoneme table: '%s'\n",phonemes_name);
		}
		voice->phoneme_tab_ix = ix;
		error = LoadDictionary(new_translator, new_dictionary, control & 4);
		if(dictionary_name[0]==0)
			return(NULL);   // no dictionary loaded

		new_translator->dict_condition = conditional_rules;

		voice_languages[langix] = 0;
	}

	langopts = &new_translator->langopts;


	if((value = langopts->param[LOPT_LENGTH_MODS]) != 0)
	{
		SetLengthMods(new_translator,value);
	}

	voice->width[0] = (voice->width[0] * 105)/100;

	if(!tone_only)
	{
		translator = new_translator;
	}

	// relative lengths of different stress syllables
	for(ix=0; ix<stress_lengths_set; ix++)
	{
		translator->stress_lengths[ix] = stress_lengths[ix];
	}
	for(ix=0; ix<stress_add_set; ix++)
	{
		translator->stress_lengths[ix] += stress_add[ix];
	}
	for(ix=0; ix<stress_amps_set; ix++)
	{
		translator->stress_amps[ix] = stress_amps[ix];
		translator->stress_amps_r[ix] = stress_amps[ix] -1;
	}

	return(voice);
}  //  end of LoadVoice
Exemplo n.º 8
0
void JStringServer::Init()
{
    LoadDictionary( "strings" );
}
Exemplo n.º 9
0
MeowPinyin::MeowPinyin()
{
	LoadDictionary();
}
Exemplo n.º 10
0
    void SolverFactory::Solve()
    {
        Wordgrid::Grid grid;
        grid.Init(m_options.GetGridSize());

        Wordgrid::SolverImpl solver;

        Wordgrid::PositionScannerImpl scanner(grid);
        Wordgrid::PositionScannerLog scannerLog(scanner);

        if (m_options.LogPositionScanner())
        {
            solver.SetPositionScanner(scannerLog);
        }
        else
        {
            solver.SetPositionScanner(scanner);
        }

        Wordgrid::Dictionary * dictionary;

        if (m_options.TreeDictionary())
        {
            dictionary = new Wordgrid::DictionaryTreeImpl;
        }
        else
        {
            dictionary = new Wordgrid::DictionarySimpleImpl;
        }

        Wordgrid::DictionaryLog dictionaryLog(*dictionary);
        if (m_options.LogDictionary())
        {
            solver.SetDictionary(dictionaryLog);
        }
        else
        {
            solver.SetDictionary(*dictionary);
        }

        Wordgrid::WordWriterImpl writer(grid);
        Wordgrid::WordWriterLog writerLog(grid, writer);
        if (m_options.LogWordWriter())
        {
            solver.SetWordWriter(writerLog);
        }
        else
        {
            solver.SetWordWriter(writer);
        }

        Wordgrid::FullGridWordRequestGenerator requestGenerator(grid);
        solver.SetWordRequestGenerator(requestGenerator);

        Wordgrid::SolverLog solverLog(solver);
        if (m_options.LogSolver())
        {
            solver.SetSolverHook(solverLog);
        }
        else
        {
            solver.SetSolverHook(solver);
        }

        int minWordSize = m_options.GetMinWordSize();
        int maxWordSize = m_options.GetMaxWordSize();

        LoadDictionary(*dictionary, minWordSize, maxWordSize);

        std::cout << "Solving...\n";
        {
            Wordgrid::ScopedTimer timer("Solved time : ");
            solver.Solve(grid);
        }

        std::cout << "Grid :\n";
        std::cout << grid << std::endl;

        delete dictionary;
    }
Exemplo n.º 11
0
void ConvertDictionary(const string inputFileName, const string outputFileName,
                       const string formatFrom, const string formatTo) {
  DictPtr dictFrom = LoadDictionary(formatFrom, inputFileName);
  SerializableDictPtr dictTo = ConvertDict(formatTo, dictFrom);
  dictTo->SerializeToFile(outputFileName);
}