/// <summary>
        /// Initializes a new instance of the ScriptSynthesizer class.
        /// </summary>
        /// <param name="serviceProvider">Service provider.</param>
        /// <param name="commonConfig">Common config of script synthesizer.</param>
        /// <param name="scriptFeatureImportConfig">Config of script feature import.</param>
        /// <param name="customizedFeaturePluginManager">Plugin manager of customized feature extraction.</param>
        public ScriptSynthesizer(ServiceProvider serviceProvider,
            ScriptSynthesizerCommonConfig commonConfig,
            ScriptFeatureImportConfig scriptFeatureImportConfig,
            CustomizedFeaturePluginManager customizedFeaturePluginManager)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            // commonConfig can be null.
            // scriptFeatureImportConfig can be null.
            // customizedFeaturePluginManager can be null.
            _serviceProvider = serviceProvider;

            _scriptFeatureImportConfig = scriptFeatureImportConfig;

            if (commonConfig != null)
            {
                _logger = new TextLogger(commonConfig.TraceLogFile);
                _logger.Reset();
            }

            if (_scriptFeatureImportConfig != null)
            {
                _scriptFeatureImport = new ScriptFeatureImport(commonConfig,
                    _scriptFeatureImportConfig, _serviceProvider, _logger);
            }

            if (customizedFeaturePluginManager != null)
            {
                _customizedFeatureExtraction = new CustomizedFeatureExtraction(_serviceProvider,
                    customizedFeaturePluginManager);
            }
        }
        /// <summary>
        /// Initializes a new instance of the ScriptFeatureImport class.
        /// </summary>
        /// <param name="commonConfig">Common config of script synthesizer.</param>
        /// <param name="config">Config of script feature import.</param>
        /// <param name="serviceProvider">Service provider.</param>
        /// <param name="logger">Log writer.</param>
        public ScriptFeatureImport(ScriptSynthesizerCommonConfig commonConfig,
            ScriptFeatureImportConfig config, ServiceProvider serviceProvider,
            TextLogger logger)
        {
            //// commonConfig can be null.

            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            _commonConfig = commonConfig;
            _config = config;

            if (_config.UpdateSilenceWord && _config.UpdateFixedSilenceDuration)
            {
                throw new InvalidDataException("Cannot implement updating script silence word and fixed silence duration together.");
            }

            if (!_config.UpdateSilenceWord && _config.UpdateScriptSilenceDuration)
            {
                throw new InvalidDataException("Cannot update script silence duration without update silence word.");
            }

            _serviceProvider = serviceProvider;
            if (_config.UpdateSilenceWord || _config.UpdateFixedSilenceDuration)
            {
                UpdateSilenceDurationsConfig();
            }

            _logger = logger;

            _serviceProvider.Engine.LinguisticProsodyTagger.Processing += new EventHandler<TtsModuleEventArgs>(OnLinguisticProcessing);
            _serviceProvider.Engine.LinguisticProsodyTagger.Processed += new EventHandler<TtsModuleEventArgs>(OnLinguisticProcessed);

            _serviceProvider.Engine.Processed += new EventHandler<TtsModuleEventArgs>(OnProcessed);
            _serviceProvider.Engine.AcousticProsodyTagger.Processed += new EventHandler<TtsModuleEventArgs>(OnAcousticProcessed);

            if (_commonConfig != null)
            {
                Helper.EnsureFolderExist(_commonConfig.OutputWaveDir);
            }
        }
        /// <summary>
        /// Parse config snippet and create the config object.
        /// </summary>
        /// <param name="nsmgr">Namespace manager.</param>
        /// <param name="configNode">Xml node containing the config.</param>
        /// <returns>The config object.</returns>
        public static ScriptSynthesizerCommonConfig ParseConfig(XmlNamespaceManager nsmgr, XmlNode configNode)
        {
            ScriptSynthesizerCommonConfig commonConfig = null;
            if (nsmgr != null && configNode != null)
            {
                commonConfig = new ScriptSynthesizerCommonConfig();
                commonConfig.Load(nsmgr, configNode);
            }

            return commonConfig;
        }