AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DialogUXStateAggregator.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_DIALOGUXSTATEAGGREGATOR_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_DIALOGUXSTATEAGGREGATOR_H_
18 
19 #include <atomic>
20 #include <chrono>
21 #include <unordered_set>
22 #include <vector>
23 
35 
36 namespace alexaClientSDK {
37 namespace avsCommon {
38 namespace avs {
39 
49 public:
54  static constexpr std::chrono::milliseconds SHORT_TIMEOUT_FOR_THINKING_TO_IDLE = std::chrono::milliseconds{200};
55 
60  static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_THINKING_TO_IDLE = std::chrono::seconds{8};
61 
66  static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_LISTENING_TO_IDLE = std::chrono::seconds{8};
67 
78  static std::shared_ptr<DialogUXStateAggregator> createDialogUXStateAggregator(
79  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder,
80  const std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface>& connectionManager,
81  const std::shared_ptr<acsdkInteractionModelInterfaces::InteractionModelNotifierInterface>&
82  interactionModelNotifier);
83 
97  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr,
98  std::chrono::milliseconds timeoutForThinkingToIdle = LONG_TIMEOUT_FOR_THINKING_TO_IDLE,
99  std::chrono::milliseconds timeoutForListeningToIdle = LONG_TIMEOUT_FOR_LISTENING_TO_IDLE,
100  std::chrono::milliseconds shortTimeoutForThinkingToIdle = SHORT_TIMEOUT_FOR_THINKING_TO_IDLE);
101 
111  void addObserver(std::shared_ptr<sdkInterfaces::DialogUXStateObserverInterface> observer);
112 
123  void removeObserver(std::shared_ptr<sdkInterfaces::DialogUXStateObserverInterface> observer);
124 
129 
132  void onStateChanged(
136  const std::vector<avsCommon::utils::audioAnalyzer::AudioAnalyzerState>& audioAnalyzerState) override;
138 
141  void onRequestProcessingStarted() override;
142  void onRequestProcessingCompleted() override;
144 
145 private:
149  void notifyObserversOfState();
150 
158 
162  void executeTryEnterIdleState();
163 
168  void executeTryExitThinkingState();
169 
173  void transitionFromThinkingTimedOut();
174 
178  void transitionFromListeningTimedOut();
179 
184  void tryEnterIdleStateOnTimer();
185 
186  void onConnectionStatusChanged(
189 
193  void onActivityStarted();
194 
201 
204  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
205 
207  std::unordered_set<std::shared_ptr<sdkInterfaces::DialogUXStateObserverInterface>> m_observers;
208 
211 
213  const std::chrono::milliseconds m_timeoutForThinkingToIdle;
214 
219  const std::chrono::milliseconds m_shortTimeoutForThinkingToIdle;
220 
222  avsCommon::utils::timing::Timer m_thinkingTimeoutTimer;
223 
225  avsCommon::utils::timing::Timer m_multiturnSpeakingToListeningTimer;
226 
229  const std::chrono::milliseconds m_timeoutForListeningToIdle;
230 
233  avsCommon::utils::timing::Timer m_listeningTimeoutTimer;
234 
236 
244 
246  std::atomic<alexaClientSDK::avsCommon::sdkInterfaces::SpeechSynthesizerObserverInterface::SpeechSynthesizerState>
247  m_speechSynthesizerState;
248 
250  std::atomic<alexaClientSDK::avsCommon::sdkInterfaces::AudioInputProcessorObserverInterface::State>
251  m_audioInputProcessorState;
252 };
253 
254 } // namespace avs
255 } // namespace avsCommon
256 } // namespace alexaClientSDK
257 
258 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_DIALOGUXSTATEAGGREGATOR_H_
DialogUXStateAggregator(std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr, std::chrono::milliseconds timeoutForThinkingToIdle=LONG_TIMEOUT_FOR_THINKING_TO_IDLE, std::chrono::milliseconds timeoutForListeningToIdle=LONG_TIMEOUT_FOR_LISTENING_TO_IDLE, std::chrono::milliseconds shortTimeoutForThinkingToIdle=SHORT_TIMEOUT_FOR_THINKING_TO_IDLE)
Definition: DialogUXStateAggregator.cpp:93
static std::shared_ptr< DialogUXStateAggregator > createDialogUXStateAggregator(const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder, const std::shared_ptr< avsCommon::sdkInterfaces::AVSConnectionManagerInterface > &connectionManager, const std::shared_ptr< acsdkInteractionModelInterfaces::InteractionModelNotifierInterface > &interactionModelNotifier)
Definition: DialogUXStateAggregator.cpp:72
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
void addObserver(std::shared_ptr< sdkInterfaces::DialogUXStateObserverInterface > observer)
Definition: DialogUXStateAggregator.cpp:111
uint64_t SourceId
A type that identifies which source is currently being operated on. This must be unique across all in...
Definition: MediaPlayerInterface.h:69
void onStateChanged(sdkInterfaces::AudioInputProcessorObserverInterface::State state) override
Definition: DialogUXStateAggregator.cpp:130
void onRequestProcessingCompleted() override
Definition: DialogUXStateAggregator.cpp:249
Definition: ConnectionStatusObserverInterface.h:31
static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_LISTENING_TO_IDLE
Definition: DialogUXStateAggregator.h:66
DialogUXState
The different dialog specific AVS UX states.
Definition: DialogUXStateObserverInterface.h:32
static constexpr std::chrono::milliseconds SHORT_TIMEOUT_FOR_THINKING_TO_IDLE
Definition: DialogUXStateAggregator.h:54
State
The different states the AudioInputProcessor can be in.
Definition: AudioInputProcessorObserverInterface.h:30
A directive observer for an InteractionModelCapabilityAgent.
Definition: InteractionModelRequestProcessingObserverInterface.h:23
static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_THINKING_TO_IDLE
Definition: DialogUXStateAggregator.h:60
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
A state observer for an AudioInputProcessor.
Definition: AudioInputProcessorObserverInterface.h:27
Definition: SpeechSynthesizerObserverInterface.h:32
SpeechSynthesizerState
Definition: SpeechSynthesizerObserverInterface.h:37
void onRequestProcessingStarted() override
Definition: DialogUXStateAggregator.cpp:219
Definition: DialogUXStateAggregator.h:44
void removeObserver(std::shared_ptr< sdkInterfaces::DialogUXStateObserverInterface > observer)
Definition: DialogUXStateAggregator.cpp:122
Status
Definition: ConnectionStatusObserverInterface.h:36

AlexaClientSDK 1.25.0 - Copyright 2016-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0