protected override Dictionary <int, BreakEntity> AnalyzeInternal(MetaText plainText) { var dataDict = new Dictionary <int, BreakEntity>(); for (var i = 0; i < plainText.AtomList.Count; i++) { if (!_breakSettings.BreakLvlMapping.TryGetValue(plainText.AtomList[i], out var breakLevel)) { continue; } if (_breakSettings.BreakLvlDetail == null) { dataDict[i] = new BreakEntity { BreakLevel = breakLevel }; } else { var breakTime = _breakSettings.BreakLvlDetail[breakLevel]; var floatRange = new Tuple <float, float>(breakTime * (1 - _breakSettings.BreakLvlFloatRate), breakTime * (1 + _breakSettings.BreakLvlFloatRate)); var breakTimeInMs = new Random().Next((int)floatRange.Item1, (int)floatRange.Item2); dataDict[i] = new BreakEntity { BreakTimeInMs = breakTimeInMs }; } } return(dataDict); }
private void BotClient_OnResponse(string message, MessageType type) { switch (type) { case MessageType.History: this.Dispatcher.BeginInvoke((Action)(() => { if (message.Contains(requestName)) { StartButton_Click(this, new RoutedEventArgs()); } HistoryText.AppendText(message + "\n"); SendText.Focus(); HistoryText.ScrollToEnd(); })); break; case MessageType.Metadata: this.Dispatcher.BeginInvoke((Action)(() => { MetaText.AppendText(message + "\n"); SendText.Focus(); MetaText.ScrollToEnd(); })); break; default: break; } }
public Task <IList <SsmlUnit> > GenerateAsync(string text) { var metaText = MetaText.CreateMetaText(text, _textSpliter.SplitText); var analyzeResults = new List <TextAnalyzeResult>(); //todo: parallel the analyze step foreach (var type in _analyzeResultProcessOrder) { if (!_analyzerDict.TryGetValue(type, out var analyzer)) { continue; } try { analyzeResults.Add(analyzer.AnalyzeText(metaText)); } catch (Exception) { //ignore for now todo: add log here } } return(GenerateAsync(metaText, analyzeResults)); }
public async Task <SsmlDoc> GenerateAsync(MetaText analyzedText, IList <TextAnalyzeResult> analyzeResults, SynthesizeParams synthesisDesc) { var ssmlUnits = await GenerateAsync(analyzedText, analyzeResults); return(new MsSsmlDoc { SsmlUnits = ssmlUnits, SynthesizeDesc = synthesisDesc }); }
public IList <SsmlUnit> CreateSsmlUnit(MetaText metaText) { return(metaText.AtomList.Select(x => { var ssmlText = x;//_breakSettings.BreakLvlMapping.ContainsKey(x) ? string.Empty : x; return new MsSsmlUnit { OriginalText = x, SsmlText = SecurityElement.Escape(ssmlText) } as SsmlUnit; }).ToList()); }
public LanguageNode(BotWrapper botWrapper, MetaText requestMessage = null, MetaText answerMessage = null, byte pageSize = 6, bool needBack = true) : base ( new SelectSingleInputNode <string>( DefaultStrings.Language, DefaultStrings.Language, botWrapper.Languages, requestMessage == null ? null : new MetaDoubleKeyboardedMessage(requestMessage), pageSize, needBack: needBack), new ActionNode( (session) => session.Language = session.Vars.GetVar <string>(DefaultStrings.Language), answerMessage == null ? null : new MetaInlineMessage(answerMessage) ) ) { TailNode.SetParent(HeadNode); }
public Task <IList <SsmlUnit> > GenerateAsync(MetaText analyzedText, IList <TextAnalyzeResult> analyzeResults) { var ssmlUnitList = CreateSsmlUnit(analyzedText); var analyzeResultDict = analyzeResults.ToDictionary(x => x.AnalyzeType, y => y); foreach (var type in _analyzeResultProcessOrder) { if (!analyzeResultDict.TryGetValue(type, out var analyzeInfo)) { continue; } ssmlUnitList = Optimize(ssmlUnitList, analyzeInfo); } return(Task.FromResult(ssmlUnitList)); }
private void BotClient_OnError(object sender, EventArgs e) { MetaText.AppendText((e as UnhandledExceptionEventArgs).ExceptionObject.ToString()); }
protected abstract Dictionary <int, T> AnalyzeInternal(MetaText plainText);
public TextAnalyzeResult AnalyzeText(MetaText plainText) { var dataDict = AnalyzeInternal(plainText); return(TextAnalyzeResult <T> .CreateByDict(dataDict)); }
protected static List <ActionNode> CreateItemNodes(string name, string itemsContainer, List <List <string> > sections, List <int> productsIds, string sessionContainer, string addedPrefix, bool useBtnName = false, string addBtnName = DefaultStrings.Add) { List <MetaText> elements = new List <MetaText>(); string[] protoString = new string[sections.Count - 1]; RecursiveAdder(); void RecursiveAdder(int index = 0) { if (index < sections.Count - 1) { for (int i = 0; i < sections[index].Count; i++) { protoString[index] = sections[index][i]; RecursiveAdder(index + 1); } } else { for (int i = 0; i < sections[index].Count; i++) { MetaText metaText = new MetaText(addedPrefix, " ", name, " "); foreach (var part in protoString) { metaText.Append(part, " "); } metaText.Append(sections[index][i]); elements.Add(metaText); } } } if (elements.Count != productsIds.Count) { throw new ArgumentException("Количество элементов не совпадает с количеством продуктов."); } List <ActionNode> nodes = new List <ActionNode>(); if (useBtnName) { for (int i = 0; i < elements.Count; i++) { nodes.Add(new ItemNode <T>(itemsContainer, productsIds[i], sessionContainer, new MetaInlineMessage(elements[i]), addBtnName)); } } else { var lastSection = sections[sections.Count - 1]; for (int i = 0, j = 0; i < elements.Count; i++, j++) { if (j >= lastSection.Count) { j = 0; } nodes.Add(new ItemNode <T>(itemsContainer, productsIds[i], sessionContainer, new MetaInlineMessage(elements[i]), lastSection[j])); } } return(nodes); }