public IEnumerable <(IEnumerable <SingleResult> IndividualValues, SegmentResult Segment)> SegmentsOrValues() { if (Init() == false) { yield break; } var segmentResult = new SegmentResult(this); InitializeSegment(out var baselineMilliseconds, out _currentSegment); while (true) { _token.ThrowIfCancellationRequested(); var baseline = new DateTime(baselineMilliseconds * 10_000, DateTimeKind.Utc); if (baseline > _to) { yield break; } if (_currentSegment.NumberOfValues != _values.Length) { _values = new double[_currentSegment.NumberOfValues]; _states = new TimestampState[_currentSegment.NumberOfValues]; } if (_offset.HasValue) { baseline = DateTime.SpecifyKind(baseline, DateTimeKind.Unspecified).Add(_offset.Value); } segmentResult.End = _currentSegment.GetLastTimestamp(baseline); segmentResult.Start = baseline; segmentResult.ChangeVector = GetCurrentSegmentChangeVector(); if (_currentSegment.NumberOfLiveEntries > 0) { if (segmentResult.Start >= _from && segmentResult.End <= _to && _currentSegment.InvalidLastValue() == false && // legacy issue RavenDB-15645 _currentSegment.Version.ContainsLastValueDuplicate == false) { // we can yield the whole segment in one go segmentResult.Summary = _currentSegment; yield return(null, segmentResult); } else { yield return(YieldSegment(baseline), segmentResult); } } if (NextSegment(out baselineMilliseconds) == false) { yield break; } } }
public void GetSavedSegmentsForList_Successful() { // Arrange MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey); ListResult lists = mc.GetLists(); // Act SegmentResult result = mc.GetSegmentsForList(lists.Data[1].Id, "saved"); // Assert Assert.IsTrue(result.SavedResult.Any()); }
public static IEnumerable ListsSegments(SqlString apikey, SqlString list_id, SqlString segment_type) { List <SegmentRow> rows = new List <SegmentRow>(); MailChimpManager mc = new MailChimpManager(apikey.ToString()); SegmentResult result = mc.GetSegmentsForList(list_id.ToString(), segment_type.ToString()); if (result.SavedResult != null) { foreach (SavedSegmentResult savedResult in result.SavedResult) { rows.Add(new SegmentRow { Type = segment_type.ToString(), Id = savedResult.Id, Name = savedResult.Name, SegmentOpts = savedResult.SegmentOpts, SegmentText = savedResult.SegmentText }); } } if (result.StaticResult != null) { foreach (StaticSegmentResult staticResult in result.StaticResult) { rows.Add(new SegmentRow { Type = segment_type.ToString(), Id = staticResult.StaticSegmentId, Name = staticResult.SegmentName, CreatedDate = staticResult.createdDate, LastUpdate = staticResult.lastUpdate, LastReset = staticResult.lastReset }); } } return(rows); }
public SpeechRecognition(IConfiguration config, ILogger <SpeechRecognition> logger) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } this.Logger = logger; this.Config = config; var speechKey = config["Azure.Cognitive.Speech.Key"]; var speechRegion = config["Azure.Cognitive.Speech.Region"]; var speechLanguage = config["Azure.Cognitive.Speech.Language"]; var speechEndpointId = config["Azure.Cognitive.Speech.EndpointId"]; listSegment = new List <SegmentResult>(); speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion); if (speechConfig != null) { speechConfig.SpeechRecognitionLanguage = speechLanguage; speechConfig.OutputFormat = OutputFormat.Detailed; if (!string.IsNullOrEmpty(speechEndpointId)) { speechConfig.EndpointId = speechEndpointId; } PushStream = AudioInputStream.CreatePushStream(); audioConfig = AudioConfig.FromStreamInput(PushStream); speechRecognizer = new SpeechRecognizer(speechConfig, audioConfig); } speechRecognizer.Recognizing += (s, e) => { Logger.LogDebug($"Recognizing: Text={e.Result.Text}"); }; speechRecognizer.Recognized += (s, e) => { if (e.Result.Reason == ResultReason.RecognizedSpeech) { // Building transcription. var listBest = new List <NBest>(); foreach (var best in e.Result.Best()) { listBest.Add(new NBest() { Confidence = best.Confidence, Lexical = best.LexicalForm, Itn = best.NormalizedForm, MaskedItn = best.MaskedNormalizedForm, Display = best.Text, Sentiment = null, Words = null }); } var segment = new SegmentResult() { ChannelNumber = null, SpeakerId = (long)SpeakerType, Offset = e.Result.OffsetInTicks, Duration = e.Result.Duration.Ticks, OffsetInSeconds = new TimeSpan(e.Result.OffsetInTicks).TotalSeconds, DurationInSeconds = e.Result.Duration.TotalSeconds, SpeechCompletedTimeStamp = DateTime.Now, NBest = listBest.ToArray() }; listSegment.Add(segment); } else if (e.Result.Reason == ResultReason.NoMatch) { Logger.LogDebug($"NoMatch: Speech could not be recognized."); } }; speechRecognizer.Canceled += (s, e) => { Logger.LogInformation($"Canceled: Reason={e.Reason}"); if (e.Reason == CancellationReason.Error) { Logger.LogDebug($"Canceled: ErrorCode={e.ErrorCode}"); Logger.LogDebug($"Canceled: ErrorDetails={e.ErrorDetails}"); Logger.LogDebug($"Canceled: Did you update the subscription info?"); } }; speechRecognizer.SessionStarted += (s, e) => { Logger.LogInformation($"Session started for {ConversationId}:{SpeakerType.ToString()}"); }; speechRecognizer.SessionStopped += (s, e) => { Logger.LogInformation($"Session stopped for {ConversationId}:{SpeakerType.ToString()}"); Logger.LogInformation("Stop recognition."); }; }