Пример #1
0
        /// <summary>
        /// Remove error sentence out of script file.
        /// </summary>
        /// <param name="errorSet">Data error set.</param>
        /// <param name="scriptFilePath">Script file path.</param>
        public static void RemoveErrorSentence(DataErrorSet errorSet, string scriptFilePath)
        {
            if (errorSet == null)
            {
                throw new ArgumentNullException("errorSet");
            }

            if (errorSet.Errors == null)
            {
                throw new ArgumentException("errorSet.Errors is null");
            }

            ScriptFile script = new ScriptFile();
            script.Load(scriptFilePath);

            foreach (DataError error in errorSet.Errors)
            {
                if (string.IsNullOrEmpty(error.SentenceId))
                {
                    continue;
                }

                if (script.Items.ContainsKey(error.SentenceId))
                {
                    script.Items.Remove(error.SentenceId);
                }
            }

            script.Save(scriptFilePath);
        }
Пример #2
0
        /// <summary>
        /// Convert XML script to two-line script.
        /// </summary>
        /// <param name="xmlScript">Input XML script.</param>
        /// <param name="targetFile">Output script.</param>
        /// <param name="phoneSet">
        /// Phone set used to convert pronunciation
        /// It can be null when you can directly get the word's pronunciation in the word's attribute.
        /// </param>
        /// <returns>Errors happened.</returns>
        public static ErrorSet ConvertXmlScriptToTwoLineScript(string xmlScript, 
            string targetFile, TtsPhoneSet phoneSet)
        {
            if (string.IsNullOrEmpty(xmlScript))
            {
                throw new ArgumentNullException("xmlScript");
            }

            if (string.IsNullOrEmpty(targetFile))
            {
                throw new ArgumentNullException("targetFile");
            }

            if (!Directory.Exists(Path.GetDirectoryName(targetFile)))
            {
                throw new DirectoryNotFoundException(targetFile);
            }

            ErrorSet errorSet = new ErrorSet();
            XmlScriptFile script = new XmlScriptFile();
            script.Load(xmlScript);
            ScriptFile oldScript = new ScriptFile(script.Language);
            foreach (ScriptItem item in script.Items)
            {
                ErrorSet itemErrors = new ErrorSet();
                ScriptItem oldItem = ConvertScriptItemToTwoLineFormat(item, phoneSet, itemErrors);
                if (itemErrors.Count != 0)
                {
                    errorSet.Merge(itemErrors);
                }
                else
                {
                    oldScript.Items.Add(oldItem.Id, oldItem);
                }
            }

            oldScript.Save(targetFile, true, true);

            return errorSet;
        }