Ejemplo n.º 1
0
        public static List <PlayItem> AddTextToPlaylist(string game, string text, bool addToPlaylist, string voiceGroup,
                                                        // Optional properties for NPC character.
                                                        string name   = null,
                                                        string gender = null,
                                                        string effect = null,
                                                        int volume    = 100,
                                                        // Optional propertied for player character
                                                        string playerName        = null,
                                                        string playerNameChanged = null,
                                                        string playerClass       = null,
                                                        // Keys which will be used to which voice source (Local, Amazon or Google).
                                                        string voiceSourceKeys = null
                                                        )
        {
            MessageGender _gender;

            Enum.TryParse(gender, out _gender);
            // It will take too long to convert large amount of text to WAV data and apply all filters.
            // This function will split text into smaller sentences.
            var cs    = "[comment]";
            var ce    = "[/comment]";
            var items = new List <PlayItem>();
            // Split sentences if option is enabled.
            var splitItems = SettingsManager.Options.SplitMessageIntoSentences
                                ? MainHelper.SplitText(text, new string[] { ". ", "! ", "? ", cs, ce })
                                : MainHelper.SplitText(text, new string[] { cs, ce });
            var  sentences = splitItems.Where(x => (x.Value + x.Key).Trim().Length > 0).ToArray();
            bool comment   = false;

            // Loop trough each sentence.
            for (int i = 0; i < sentences.Length; i++)
            {
                var block = sentences[i];
                // Combine sentence and separator.
                var sentence = block.Value + block.Key.Replace(cs, "").Replace(ce, "") + "";
                if (!string.IsNullOrEmpty(sentence.Trim('\r', '\n', ' ')))
                {
                    var item = new PlayItem();
                    item.Game = game;
                    // Set Player properties
                    item.PlayerName        = playerName;
                    item.PlayerNameChanged = playerNameChanged;
                    item.PlayerClass       = playerClass;
                    // Set NPC properties.
                    item.Name   = name;
                    item.Gender = _gender;
                    item.Effect = effect;
                    item.Volume = volume;
                    // Set data properties.
                    item.Status          = JobStatusType.Parsed;
                    item.IsComment       = comment;
                    item.Group           = voiceGroup;
                    item.VoiceSourceKeys = voiceSourceKeys;
                    item.Text            = sentence;
                    if (SettingsManager.Options.CacheDataGeneralize)
                    {
                        item.Text = item.GetGeneralizedText();
                    }
                    item.Xml = ConvertTextToXml(item.Text, comment, volume);
                    items.Add(item);
                    if (addToPlaylist)
                    {
                        lock (playlistLock) { playlist.Add(item); }
                    }
                }
                ;
                // If comment started.
                if (block.Key == cs)
                {
                    comment = true;
                }
                // If comment ended.
                if (block.Key == ce)
                {
                    comment = false;
                }
            }
            return(items);
        }