Ejemplo n.º 1
0
        public void Init(IModuleConfig config)
        {
            giftCacheManager = new GiftCacheManager(5);
            giftCacheManager.CacheExpired += GiftCacheManager_CacheExpired;
            speechProcessor = new SpeechProcessor();
            speechProcessor.QueueChanged += Synthesizer_QueueChanged;

            DanmakuSpeechConfig speechConfig = (DanmakuSpeechConfig)config;

            OptionDict = speechConfig.OptionDict;
            SetVolume(speechConfig.Volume);
            Control = new DanmakuSpeechControl(this, speechConfig.OutputDevice);


            FileInfo fileInfo           = new FileInfo("./config/speech.xml");
            Stream   speechConfigStream = null;

            try
            {
                if (fileInfo.Exists)
                {
                    speechConfigStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                else
                {
                    speechConfigStream = Application.GetResourceStream(new Uri("Config/Speech.xml", UriKind.RelativeOrAbsolute)).Stream;
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(speechConfigStream);
                XmlNode enableAttr = xmlDocument.SelectSingleNode("speech/@enable");
                string  enable     = enableAttr != null ? enableAttr.Value : "true";
                if (enable.ToLower() != "false")
                {
                    XmlNode tokenEndpointNode = xmlDocument.SelectSingleNode("speech/token_endpoint/text()");
                    XmlNode ttsEndpointNode   = xmlDocument.SelectSingleNode("speech/tts_endpoint/text()");
                    XmlNode apiKeyNode        = xmlDocument.SelectSingleNode("speech/api_key/text()");
                    string  tokenEndpoint     = tokenEndpointNode.Value;
                    string  ttsEndpoint       = ttsEndpointNode.Value;
                    string  apiKey            = apiKeyNode.Value;
                    speechProcessor.Init(tokenEndpoint, ttsEndpoint, apiKey);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                if (speechConfigStream != null)
                {
                    speechConfigStream.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public IModuleConfig GetConfig()
        {
            DanmakuSpeechConfig speechConfig = new DanmakuSpeechConfig(OptionDict, Control.GetOutputDeviceName(), Volume);

            return(speechConfig);
        }