/// <summary> /// List the best unit and unit candidates number used by ESP when speak the content. /// </summary> /// <param name="content">Content to be spoken.</param> /// <param name="waveUnits">Unit dictionary.</param> /// <param name="candCounter">Candidates number per unit.</param> /// <returns>Unit list used by ESP to speak the content.</returns> public Collection<UnitItem> GenUnitList(string content, Dictionary<long, WaveUnit> waveUnits, out Collection<int> candCounter) { Collection<UnitItem> unitList = new Collection<UnitItem>(); candCounter = new Collection<int>(); foreach (SP.TtsUtterance uttr in EspUtterances(content)) { using (uttr) { int candNum = 0; for (int index = 0; index < uttr.Segments.Count; index++) { if (uttr.Segments[index].Unit.IsSilence) { continue; } WaveUnit waveUnit = waveUnits[uttr.Segments[index].InventoryWaveStartPosition]; UnitItem unitItem = new UnitItem(); unitItem.SentenceId = waveUnit.SentenceId; unitItem.IndexInSentence = waveUnit.IndexInSentence; unitItem.Name = waveUnit.Name; unitList.Add(unitItem); candCounter.Add(uttr.UnitLattice.WucList[candNum++].WucNodeList.Count); } } } return unitList; }
/// <summary> /// Get original unit list used by ESP when speak the content. /// </summary> /// <param name="content">Content to be spoken.</param> /// <param name="waveUnits">Unit dictionary.</param> /// <returns>Unit list used by ESP to speak the content.</returns> public UnitListDictionary GetOriginalUnitList(string content, Dictionary<long, WaveUnit> waveUnits) { UnitListDictionary unitListDictionary = new UnitListDictionary(); foreach (SP.TtsUtterance uttr in EspUtterances(content)) { using (uttr) { for (int index = 0; index < uttr.Segments.Count; index++) { WaveUnit waveUnit = waveUnits[uttr.Segments[index].InventoryWaveStartPosition]; UnitItem unitItem = new UnitItem(); unitItem.SentenceId = waveUnit.SentenceId; unitItem.IndexInSentence = waveUnit.IndexInSentence; unitItem.Name = waveUnit.Name; unitListDictionary.AddUnit(_language, UnitList.UnitListType.Hold, unitItem); } } } return unitListDictionary; }
/// <summary> /// Parse XmlNode to UnitList. /// </summary> /// <param name="node">XmlNode to be parsed.</param> /// <param name="nsmgr">XmlNamespaceManager.</param> public void Parse(XmlNode node, XmlNamespaceManager nsmgr) { if (node == null) { throw new ArgumentNullException("node"); } if (node.Attributes == null) { string message = Helper.NeutralFormat("the Attributes of node should not be null."); throw new ArgumentNullException("node", message); } XmlNode languageNode = node.Attributes["language"]; XmlNode typeNode = node.Attributes["type"]; if (languageNode == null || typeNode == null) { throw new InvalidDataException("unitList XmlNode " + "should have the following two properties: language, type."); } _language = Localor.StringToLanguage(languageNode.InnerText); _type = (UnitListType)Enum.Parse(typeof(UnitListType), typeNode.InnerText); XmlNodeList unitNodes = node.SelectNodes(@"tts:units/tts:unit", nsmgr); _units.Clear(); foreach (XmlNode unitNode in unitNodes) { UnitItem item = new UnitItem(); item.Parse(unitNode); _units.Add(item.Id, item); } }
/// <summary> /// Add unit to unit list map. /// </summary> /// <param name="language">Language of the unit.</param> /// <param name="type">Type of the unit.</param> /// <param name="unit">Unit to be added.</param> public void AddUnit(Language language, UnitList.UnitListType type, UnitItem unit) { string unitListKey = UnitList.GetKey(language, type); if (!_unitListMap.ContainsKey(unitListKey)) { UnitList unitList = new UnitList(); unitList.Language = language; unitList.UnitType = type; _unitListMap.Add(unitListKey, unitList); unitList.AddUnit(unit); } else { UnitList unitList = _unitListMap[unitListKey]; unitList.AddUnit(unit); } }
/// <summary> /// Add Unit to UnitList. /// </summary> /// <param name="unitItem">UnitItem to be added.</param> public void AddUnit(UnitItem unitItem) { if (unitItem == null) { throw new ArgumentNullException("unitItem"); } if (!_units.ContainsKey(unitItem.Id)) { _units.Add(unitItem.Id, unitItem); } else { _units[unitItem.Id] = unitItem; } }