예제 #1
0
        /// <summary>
        /// Load phone set from file.
        /// </summary>
        /// <param name="language">The language of phone set.</param>
        /// <param name="path">Path to load phone set.</param>
        /// <returns>Loaded phone set.</returns>
        public static TtsPhoneSet LoadFromFile(Language language, string path)
        {
            TtsPhoneSet phoneSet = new TtsPhoneSet(language);

            phoneSet.Load(path);

            return phoneSet;
        }
        /// <summary>
        /// Parse XML document for Phone Set File path.
        /// </summary>
        /// <param name="dom">XML configuration document.</param>
        /// <param name="nsmgr">Namespace.</param>
        private void ParsePhoneSet(XmlDocument dom, XmlNamespaceManager nsmgr)
        {
            PhoneSetFile = ParseFilePath(dom, nsmgr, PhoneSetFileItem);

            if (!Helper.FileValidExists(PhoneSetFile))
            {
                throw new FileNotFoundException(
                    string.Format(CultureInfo.InvariantCulture,
                    "Phone set file \"{0}\" not found.", PhoneSetFile));
            }

            PhoneSet = new TtsPhoneSet();
            PhoneSet.Load(PhoneSetFile);
        }
예제 #3
0
        /// <summary>
        /// Initialize the validator.
        /// </summary>
        public void EnsureInitialized()
        {
            Debug.Assert(LexiconFilePath != null || Lexicon != null);
            Debug.Assert(PhoneSetFilePath != null || PhoneSet != null);

            if (_lexicon == null)
            {
                _lexicon = new Lexicon();
                _lexicon.Load(LexiconFilePath);
            }

            if (_phoneset == null)
            {
                _phoneset = new TtsPhoneSet();
                _phoneset.Load(PhoneSetFilePath);
            }

            if (_phoneset.Language != _lexicon.Language)
            {
                string message = Utility.Helper.NeutralFormat(
                    "phoneset and lexicon language should match");
                throw new InvalidDataException(message);
            }

            _language = _lexicon.Language;
        }
예제 #4
0
        /// <summary>
        /// Load Phone set Data object.
        /// </summary>
        /// <param name="errorSet">ErrorSet.</param>
        /// <returns>Phone set Data object.</returns>
        internal override object LoadDataObject(ErrorSet errorSet)
        {
            if (errorSet == null)
            {
                throw new ArgumentNullException("errorSet");
            }

            TtsPhoneSet phoneSet = new TtsPhoneSet();
            phoneSet.Load(this.Path);
            phoneSet.Validate();
            errorSet.Merge(phoneSet.ErrorSet);
            if (phoneSet.ErrorSet.Contains(ErrorSeverity.MustFix))
            {
                phoneSet = null;
            }

            return phoneSet;
        }
        /// <summary>
        /// Validate language data files.
        /// </summary>
        /// <param name="language">Language of the data files.</param>
        /// <returns>Error set.</returns>
        public ErrorSet ValidateLanguageData(Language language)
        {
            ErrorSet errorSet = new ErrorSet();
            if (!IsEmpty())
            {
                if (!string.IsNullOrEmpty(_phoneSet))
                {
                    TtsPhoneSet ttsPhoneSet = new TtsPhoneSet();
                    ttsPhoneSet.Load(PhoneSet);
                    if (ttsPhoneSet.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(ttsPhoneSet.Language),
                            Localor.PhoneSetFileName, PhoneSet));
                    }
                }

                if (!string.IsNullOrEmpty(_unitTable))
                {
                    SliceData sliceData = new SliceData();
                    sliceData.Language = language;
                    sliceData.Load(UnitTable);
                    if (sliceData.IsEmpty())
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.EmptyLanguageDataFile,
                            Localor.LanguageToString(language),
                            Localor.UnitTableFileName, UnitTable));
                    }
                }

                if (!string.IsNullOrEmpty(_lexicalAttributeSchema))
                {
                    LexicalAttributeSchema lexicalAttributeSchema = new LexicalAttributeSchema();
                    lexicalAttributeSchema.Load(LexicalAttributeSchema);
                    if (lexicalAttributeSchema.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(lexicalAttributeSchema.Language),
                            Localor.PhoneSetFileName, LexicalAttributeSchema));
                    }
                }

                if (!string.IsNullOrEmpty(_truncateRule))
                {
                    TruncateRuleData truncateRuleData = new TruncateRuleData();
                    truncateRuleData.Load(TruncateRule);
                    if (truncateRuleData.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(truncateRuleData.Language),
                            Localor.TruncateRulesFileName, TruncateRule));
                    }
                }

                if (!string.IsNullOrEmpty(_ttsToSapiVisemeId))
                {
                    PhoneMap phoneMap = PhoneMap.CreatePhoneMap(TtsToSapiVisemeId);
                    if (phoneMap.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(phoneMap.Language),
                            Localor.TtsToSapiVisemeIdFileName, TtsToSapiVisemeId));
                    }
                }

                if (!string.IsNullOrEmpty(_ttsToSrPhone))
                {
                    PhoneMap phoneMap = PhoneMap.CreatePhoneMap(TtsToSrPhone);
                    if (phoneMap.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(phoneMap.Language),
                            Localor.TtsToSrPhoneFileName, TtsToSrPhone));
                    }
                }

                if (!string.IsNullOrEmpty(_ttsToIpaPhone))
                {
                    PhoneMap phoneMap = PhoneMap.CreatePhoneMap(TtsToIpaPhone);
                    if (phoneMap.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(phoneMap.Language),
                            Localor.TtsToIpaPhoneFileName, TtsToIpaPhone));
                    }
                }

                if (!string.IsNullOrEmpty(_fontMeta))
                {
                    PhoneMap phoneMap = PhoneMap.CreatePhoneMap(FontMeta);
                    if (phoneMap.Language != language)
                    {
                        errorSet.Add(new Error(VoiceCreationLanguageDataError.MismatchLanguage,
                            Localor.LanguageToString(language),
                            Localor.LanguageToString(phoneMap.Language),
                            Localor.FontMetaFileName, FontMeta));
                    }
                }
            }
            else
            {
                Trace.WriteLine("Using stocked language data with tools...");
            }

            return errorSet;
        }
예제 #6
0
        public static TtsPhoneSet GetPhoneSet(Language language)
        {
            TtsPhoneSet phoneSet = null;
            if (_ttsPhoneSetMap.ContainsKey(language))
            {
                phoneSet = _ttsPhoneSetMap[language];
            }
            else
            {
                using (StreamReader reader = Localor.LoadResource(language, Localor.PhoneSetFileName))
                {
                    if (reader != null)
                    {
                        phoneSet = new TtsPhoneSet(language);
                        phoneSet.Load(reader);
                        _ttsPhoneSetMap[language] = phoneSet;
                    }
                }
            }

            return phoneSet;
        }