public static string ConvertTextToXml(ItemPlayOptions ipo, string text, bool isComment = false, int volume = 100) { // Apply 'message' volume and playback volume. //var vol = (int)(((decimal)volume / 100m) * (decimal)SettingsManager.Options.Volume); var xml = GetSsmlXml(text, ipo.Voice, volume, ipo.Pitch, ipo.Rate, isComment); return(xml); }
public static List <PlayItem> AddTextToPlaylist(ItemPlayOptions ipo, string game, string text, bool addToPlaylist, string voiceGroup, // Optional properties for NPC character. string name = null, string effect = null, // 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 ) { // 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 isComment = 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 = isComment ? ReplaceNameToVoiceFromVoiceDefaultsTab("Commentator") : name; item.Name = name; item.Gender = ipo.Gender; item.Effect = effect; item.Volume = ipo.Volume; // Set data properties. item.Status = JobStatusType.Parsed; item.IsComment = isComment; item.Group = voiceGroup; item.VoiceSourceKeys = voiceSourceKeys; item.Text = sentence; if (SettingsManager.Options.CacheDataGeneralize) { item.Text = item.GetGeneralizedText(); } item.Xml = ConvertTextToXml(ipo, item.Text, isComment, ipo.Volume); items.Add(item); if (addToPlaylist) { lock (playlistLock) { playlist.Add(item); } } } ; // If comment started. if (block.Key == cs) { isComment = true; } // If comment ended. if (block.Key == ce) { isComment = false; } } return(items); }
public static ItemPlayOptions GetPlayOptions(string name = null, string language = null, string gender = null, string overridePitch = null, string overrideRate = null, string overrideVolume = null, string effect = null ) { var ipo = new ItemPlayOptions(); // Set gender: Male, Female or Neutral. MessageGender amGender; if (!Enum.TryParse(gender, out amGender)) { amGender = SettingsManager.Options.GenderComboBoxText; } ipo.Gender = amGender; if (name == null) { ipo.Voice = SelectedVoice; } else { ipo.Voice = SelectVoice(name, language, amGender); } // Set pitch. int _pitch; var pitchIsValid = int.TryParse(overridePitch, out _pitch); if (!pitchIsValid) { _pitch = MainHelper.GetNumber(SettingsManager.Options.PitchMin, SettingsManager.Options.PitchMax, "pitch", name); } if (_pitch < -10) { _pitch = -10; } if (_pitch > 10) { _pitch = 10; } ipo.Pitch = _pitch; // Set rate. int _rate; var rateIsValid = int.TryParse(overrideRate, out _rate); if (!rateIsValid) { _rate = MainHelper.GetNumber(SettingsManager.Options.RateMin, SettingsManager.Options.RateMax, "rate", name); } if (_rate < -10) { _rate = -10; } if (_rate > 10) { _rate = 10; } ipo.Rate = _rate; // Set volume. int _volume; var volumeIsValid = int.TryParse(overrideVolume, out _volume); if (!volumeIsValid) { _volume = 100; } if (_volume < 0) { _volume = 0; } if (_volume > 100) { _volume = 100; } ipo.Volume = _volume; // Set effect. string _effect; if (string.IsNullOrEmpty(effect)) { _effect = "Default"; } else { _effect = effect; if (SelectedEffect != effect) { OnEvent(EffectsPresetSelected, effect); } } ipo.Effect = _effect; return(ipo); }