2017-07-18 22:25:37 +00:00
|
|
|
/*
|
2018-01-12 23:45:42 +00:00
|
|
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2017-07-18 22:25:37 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
* A copy of the License is located at
|
|
|
|
*
|
|
|
|
* http://aws.amazon.com/apache2.0/
|
|
|
|
*
|
|
|
|
* or in the "license" file accompanying this file. This file is distributed
|
|
|
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
|
* express or implied. See the License for the specific language governing
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AVSCommon/AVS/DialogUXStateAggregator.h"
|
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace avsCommon {
|
|
|
|
namespace avs {
|
|
|
|
|
|
|
|
using namespace sdkInterfaces;
|
|
|
|
|
|
|
|
/// String to identify log entries originating from this file.
|
|
|
|
static const std::string TAG("DialogUXStateAggregator");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a LogEntry using this file's TAG and the specified event string.
|
|
|
|
*
|
|
|
|
* @param The event string for this @c LogEntry.
|
|
|
|
*/
|
|
|
|
#define LX(event) alexaClientSDK::avsCommon::utils::logger::LogEntry(TAG, event)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A short timeout that is used to avoid going to the IDLE state immediately while waiting for other state changes.
|
|
|
|
*/
|
|
|
|
static const std::chrono::milliseconds SHORT_TIMEOUT{200};
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
DialogUXStateAggregator::DialogUXStateAggregator(std::chrono::milliseconds timeoutForThinkingToIdle) :
|
|
|
|
m_currentState{DialogUXStateObserverInterface::DialogUXState::IDLE},
|
2017-12-09 00:07:37 +00:00
|
|
|
m_timeoutForThinkingToIdle{timeoutForThinkingToIdle},
|
|
|
|
m_speechSynthesizerState{SpeechSynthesizerObserverInterface::SpeechSynthesizerState::FINISHED},
|
|
|
|
m_audioInputProcessorState{AudioInputProcessorObserverInterface::State::IDLE} {
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::addObserver(std::shared_ptr<DialogUXStateObserverInterface> observer) {
|
|
|
|
if (!observer) {
|
|
|
|
ACSDK_ERROR(LX("addObserverFailed").d("reason", "nullObserver"));
|
|
|
|
return;
|
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
m_executor.submit([this, observer]() {
|
|
|
|
m_observers.insert(observer);
|
|
|
|
observer->onDialogUXStateChanged(m_currentState);
|
|
|
|
});
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::removeObserver(std::shared_ptr<DialogUXStateObserverInterface> observer) {
|
|
|
|
if (!observer) {
|
|
|
|
ACSDK_ERROR(LX("removeObserverFailed").d("reason", "nullObserver"));
|
|
|
|
return;
|
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
m_executor.submit([this, observer]() { m_observers.erase(observer); }).wait();
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::onStateChanged(AudioInputProcessorObserverInterface::State state) {
|
2017-12-09 00:07:37 +00:00
|
|
|
m_audioInputProcessorState = state;
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
m_executor.submit([this, state]() {
|
|
|
|
switch (state) {
|
|
|
|
case AudioInputProcessorObserverInterface::State::IDLE:
|
2017-12-09 00:07:37 +00:00
|
|
|
tryEnterIdleState();
|
2017-10-02 22:59:05 +00:00
|
|
|
return;
|
|
|
|
case AudioInputProcessorObserverInterface::State::RECOGNIZING:
|
2017-12-09 00:07:37 +00:00
|
|
|
onActivityStarted();
|
2017-10-02 22:59:05 +00:00
|
|
|
setState(DialogUXStateObserverInterface::DialogUXState::LISTENING);
|
|
|
|
return;
|
|
|
|
case AudioInputProcessorObserverInterface::State::EXPECTING_SPEECH:
|
2017-12-09 00:07:37 +00:00
|
|
|
onActivityStarted();
|
Version 1.10 alexa-client-sdk
Changes in this update:
**Enhancements**
* New optional configuration for [EqualizerController](https://github.com/alexa/avs-device-sdk/blob/v1.10.0/Integration/AlexaClientSDKConfig.json#L154). The EqualizerController interface allows you to adjust equalizer settings on your product, such as decibel (dB) levels and modes.
* Added reference implementation of the EqualizerController for GStreamer-based (MacOS, Linux, and Raspberry Pi) and OpenSL ES-based (Android) MediaPlayers. Note: In order to use with Android, it must support OpenSL ES.
* New optional configuration for the [TemplateRuntime display card value](https://github.com/alexa/avs-device-sdk/blob/v1.10.0/Integration/AlexaClientSDKConfig.json#L144).
* A configuration file generator script, `genConfig.sh` is now included with the SDK in the **tools/Install** directory. `genConfig.sh` and it's associated arguments populate `AlexaClientSDKConfig.json` with the data required to authorize with LWA.
* Added Bluetooth A2DP source and AVRCP target support for Linux.
* Added Amazon for Business (A4B) support, which includes support for handling the new [RevokeAuthorization](https://developer.amazon.com/docs/alexa-voice-service/system.html#revokeauth) directive in the Settings interface. A new CMake option has been added to enable A4B within the SDK, `-DA4B`.
* Added locale support for IT and ES.
* The Alexa Communication Library (ACL), `CBLAUthDelegate`, and sample app have been enhanced to detect de-authorization using the new `z` command.
* Added `ExternalMediaPlayerObserver`, which receives notification of player state, track, and username changes.
* `HTTP2ConnectionInterface` was factored out of `HTTP2Transport` to enable unit testing of `HTTP2Transport` and re-use of `HTTP2Connection` logic.
**Bug Fixes**
* Fixed a bug in which `ExternalMediaPlayer` adapter playback wasn't being recognized by AVS.
* [Issue 973](https://github.com/alexa/avs-device-sdk/issues/973) - Fixed issues related to `AudioPlayer` where progress reports were being sent out of order or with incorrect offsets.
* An `EXPECTING`, state has been added to `DialogUXState` in order to handle `EXPECT_SPEECH` state for hold-to-talk devices.
* [Issue 948](https://github.com/alexa/avs-device-sdk/issues/948) - Fixed a bug in which the sample app was stuck in a listening state.
* Fixed a bug where there was a delay between receiving a `DeleteAlert` directive, and deleting the alert.
* [Issue 839](https://github.com/alexa/avs-device-sdk/issues/839) - Fixed an issue where speech was being truncated due to the `DialogUXStateAggregator` transitioning between a `THINKING` and `IDLE` state.
* Fixed a bug in which the `AudioPlayer` attempted to play when it wasn't in the `FOREGROUND` focus.
* `CapabilitiesDelegateTest` now works on Android.
* [Issue 950](https://github.com/alexa/avs-device-sdk/issues/950) - Improved Android Media Player audio quality.
* [Issue 908](https://github.com/alexa/avs-device-sdk/issues/908) - Fixed compile error on g++ 7.x in which includes were missing.
2018-10-24 17:01:29 +00:00
|
|
|
setState(DialogUXStateObserverInterface::DialogUXState::EXPECTING);
|
2017-10-02 22:59:05 +00:00
|
|
|
return;
|
|
|
|
case AudioInputProcessorObserverInterface::State::BUSY:
|
|
|
|
setState(DialogUXStateObserverInterface::DialogUXState::THINKING);
|
2017-12-09 00:07:37 +00:00
|
|
|
if (!m_thinkingTimeoutTimer
|
2017-10-02 22:59:05 +00:00
|
|
|
.start(
|
|
|
|
m_timeoutForThinkingToIdle,
|
|
|
|
std::bind(&DialogUXStateAggregator::transitionFromThinkingTimedOut, this))
|
|
|
|
.valid()) {
|
|
|
|
ACSDK_ERROR(LX("failedToStartTimerFromThinkingToIdle"));
|
|
|
|
}
|
|
|
|
return;
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
ACSDK_ERROR(LX("unknownAudioInputProcessorState"));
|
|
|
|
});
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
void DialogUXStateAggregator::onStateChanged(SpeechSynthesizerObserverInterface::SpeechSynthesizerState state) {
|
|
|
|
m_speechSynthesizerState = state;
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
m_executor.submit([this, state]() {
|
|
|
|
switch (state) {
|
2017-12-09 00:07:37 +00:00
|
|
|
case SpeechSynthesizerObserverInterface::SpeechSynthesizerState::PLAYING:
|
|
|
|
onActivityStarted();
|
2017-10-02 22:59:05 +00:00
|
|
|
setState(DialogUXStateObserverInterface::DialogUXState::SPEAKING);
|
|
|
|
return;
|
2017-12-09 00:07:37 +00:00
|
|
|
case SpeechSynthesizerObserverInterface::SpeechSynthesizerState::FINISHED:
|
|
|
|
tryEnterIdleState();
|
|
|
|
return;
|
|
|
|
case SpeechSynthesizerObserverInterface::SpeechSynthesizerState::LOSING_FOCUS:
|
2018-01-12 23:45:42 +00:00
|
|
|
return;
|
2017-12-09 00:07:37 +00:00
|
|
|
case SpeechSynthesizerObserverInterface::SpeechSynthesizerState::GAINING_FOCUS:
|
|
|
|
onActivityStarted();
|
2017-10-02 22:59:05 +00:00
|
|
|
return;
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
ACSDK_ERROR(LX("unknownSpeechSynthesizerState"));
|
|
|
|
});
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
void DialogUXStateAggregator::receive(const std::string& contextId, const std::string& message) {
|
|
|
|
m_executor.submit([this]() {
|
Version 1.10 alexa-client-sdk
Changes in this update:
**Enhancements**
* New optional configuration for [EqualizerController](https://github.com/alexa/avs-device-sdk/blob/v1.10.0/Integration/AlexaClientSDKConfig.json#L154). The EqualizerController interface allows you to adjust equalizer settings on your product, such as decibel (dB) levels and modes.
* Added reference implementation of the EqualizerController for GStreamer-based (MacOS, Linux, and Raspberry Pi) and OpenSL ES-based (Android) MediaPlayers. Note: In order to use with Android, it must support OpenSL ES.
* New optional configuration for the [TemplateRuntime display card value](https://github.com/alexa/avs-device-sdk/blob/v1.10.0/Integration/AlexaClientSDKConfig.json#L144).
* A configuration file generator script, `genConfig.sh` is now included with the SDK in the **tools/Install** directory. `genConfig.sh` and it's associated arguments populate `AlexaClientSDKConfig.json` with the data required to authorize with LWA.
* Added Bluetooth A2DP source and AVRCP target support for Linux.
* Added Amazon for Business (A4B) support, which includes support for handling the new [RevokeAuthorization](https://developer.amazon.com/docs/alexa-voice-service/system.html#revokeauth) directive in the Settings interface. A new CMake option has been added to enable A4B within the SDK, `-DA4B`.
* Added locale support for IT and ES.
* The Alexa Communication Library (ACL), `CBLAUthDelegate`, and sample app have been enhanced to detect de-authorization using the new `z` command.
* Added `ExternalMediaPlayerObserver`, which receives notification of player state, track, and username changes.
* `HTTP2ConnectionInterface` was factored out of `HTTP2Transport` to enable unit testing of `HTTP2Transport` and re-use of `HTTP2Connection` logic.
**Bug Fixes**
* Fixed a bug in which `ExternalMediaPlayer` adapter playback wasn't being recognized by AVS.
* [Issue 973](https://github.com/alexa/avs-device-sdk/issues/973) - Fixed issues related to `AudioPlayer` where progress reports were being sent out of order or with incorrect offsets.
* An `EXPECTING`, state has been added to `DialogUXState` in order to handle `EXPECT_SPEECH` state for hold-to-talk devices.
* [Issue 948](https://github.com/alexa/avs-device-sdk/issues/948) - Fixed a bug in which the sample app was stuck in a listening state.
* Fixed a bug where there was a delay between receiving a `DeleteAlert` directive, and deleting the alert.
* [Issue 839](https://github.com/alexa/avs-device-sdk/issues/839) - Fixed an issue where speech was being truncated due to the `DialogUXStateAggregator` transitioning between a `THINKING` and `IDLE` state.
* Fixed a bug in which the `AudioPlayer` attempted to play when it wasn't in the `FOREGROUND` focus.
* `CapabilitiesDelegateTest` now works on Android.
* [Issue 950](https://github.com/alexa/avs-device-sdk/issues/950) - Improved Android Media Player audio quality.
* [Issue 908](https://github.com/alexa/avs-device-sdk/issues/908) - Fixed compile error on g++ 7.x in which includes were missing.
2018-10-24 17:01:29 +00:00
|
|
|
if (DialogUXStateObserverInterface::DialogUXState::THINKING == m_currentState &&
|
|
|
|
SpeechSynthesizerObserverInterface::SpeechSynthesizerState::GAINING_FOCUS != m_speechSynthesizerState) {
|
2017-10-02 22:59:05 +00:00
|
|
|
/*
|
|
|
|
* Stop the long timer and start a short timer so that either the state will change (i.e. Speech begins)
|
|
|
|
* or we automatically go to idle after the short timeout (i.e. the directive received isn't related to
|
|
|
|
* speech, like a setVolume directive).
|
|
|
|
*/
|
2017-12-09 00:07:37 +00:00
|
|
|
m_thinkingTimeoutTimer.stop();
|
|
|
|
m_thinkingTimeoutTimer.start(
|
2017-10-02 22:59:05 +00:00
|
|
|
SHORT_TIMEOUT, std::bind(&DialogUXStateAggregator::transitionFromThinkingTimedOut, this));
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::onConnectionStatusChanged(
|
|
|
|
const ConnectionStatusObserverInterface::Status status,
|
|
|
|
const ConnectionStatusObserverInterface::ChangedReason reason) {
|
|
|
|
m_executor.submit([this, &status]() {
|
|
|
|
if (status != avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status::CONNECTED) {
|
|
|
|
setState(DialogUXStateObserverInterface::DialogUXState::IDLE);
|
|
|
|
}
|
|
|
|
});
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::notifyObserversOfState() {
|
|
|
|
for (auto observer : m_observers) {
|
|
|
|
if (observer) {
|
|
|
|
observer->onDialogUXStateChanged(m_currentState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::transitionFromThinkingTimedOut() {
|
2017-10-02 22:59:05 +00:00
|
|
|
m_executor.submit([this]() {
|
|
|
|
if (DialogUXStateObserverInterface::DialogUXState::THINKING == m_currentState) {
|
|
|
|
ACSDK_DEBUG(LX("transitionFromThinkingTimedOut"));
|
|
|
|
setState(DialogUXStateObserverInterface::DialogUXState::IDLE);
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
});
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
void DialogUXStateAggregator::tryEnterIdleStateOnTimer() {
|
2017-10-02 22:59:05 +00:00
|
|
|
m_executor.submit([this]() {
|
2017-12-09 00:07:37 +00:00
|
|
|
if (m_currentState != sdkInterfaces::DialogUXStateObserverInterface::DialogUXState::IDLE &&
|
|
|
|
m_audioInputProcessorState == AudioInputProcessorObserverInterface::State::IDLE &&
|
|
|
|
m_speechSynthesizerState == SpeechSynthesizerObserverInterface::SpeechSynthesizerState::FINISHED) {
|
|
|
|
setState(sdkInterfaces::DialogUXStateObserverInterface::DialogUXState::IDLE);
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
2017-10-02 22:59:05 +00:00
|
|
|
});
|
2017-07-18 22:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::setState(sdkInterfaces::DialogUXStateObserverInterface::DialogUXState newState) {
|
|
|
|
if (newState == m_currentState) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-09 00:07:37 +00:00
|
|
|
m_thinkingTimeoutTimer.stop();
|
2017-07-18 22:25:37 +00:00
|
|
|
m_multiturnSpeakingToListeningTimer.stop();
|
|
|
|
ACSDK_DEBUG(LX("setState").d("from", m_currentState).d("to", newState));
|
|
|
|
m_currentState = newState;
|
|
|
|
notifyObserversOfState();
|
|
|
|
}
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
void DialogUXStateAggregator::tryEnterIdleState() {
|
|
|
|
m_multiturnSpeakingToListeningTimer.stop();
|
|
|
|
if (!m_multiturnSpeakingToListeningTimer
|
|
|
|
.start(SHORT_TIMEOUT, std::bind(&DialogUXStateAggregator::tryEnterIdleStateOnTimer, this))
|
|
|
|
.valid()) {
|
|
|
|
ACSDK_ERROR(LX("failedToStartTryEnterIdleStateTimer"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogUXStateAggregator::onActivityStarted() {
|
|
|
|
m_thinkingTimeoutTimer.stop();
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
} // namespace avs
|
|
|
|
} // namespace avsCommon
|
|
|
|
} // namespace alexaClientSDK
|