16 #ifndef ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SPEECHSYNTHESIZER_INCLUDE_SPEECHSYNTHESIZER_SPEECHSYNTHESIZER_H_ 17 #define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SPEECHSYNTHESIZER_INCLUDE_SPEECHSYNTHESIZER_SPEECHSYNTHESIZER_H_ 22 #include <unordered_set> 51 namespace capabilityAgents {
52 namespace speechSynthesizer {
67 ,
public std::enable_shared_from_this<SpeechSynthesizer> {
90 std::shared_ptr<acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface>
92 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
93 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
94 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
95 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
96 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>
metricRecorder,
97 std::shared_ptr<avsCommon::avs::DialogUXStateAggregator> dialogUXStateAggregator,
98 std::shared_ptr<captions::CaptionManagerInterface> captionManager =
nullptr,
99 std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> powerResourceManager =
nullptr);
117 static std::shared_ptr<SpeechSynthesizer>
create(
118 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> mediaPlayer,
119 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
120 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
121 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
122 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
123 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>
metricRecorder,
124 std::shared_ptr<avsCommon::avs::DialogUXStateAggregator> dialogUXStateAggregator,
125 std::shared_ptr<captions::CaptionManagerInterface> captionManager =
nullptr,
126 std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> powerResourceManager =
nullptr);
137 void addObserver(std::shared_ptr<SpeechSynthesizerObserverInterface> observer);
147 void removeObserver(std::shared_ptr<SpeechSynthesizerObserverInterface> observer);
194 struct SpeakDirectiveInfo {
200 SpeakDirectiveInfo(std::shared_ptr<DirectiveInfo> directiveInfo);
206 std::shared_ptr<avsCommon::avs::AVSDirective> directive;
209 std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result;
215 std::unique_ptr<avsCommon::avs::attachment::AttachmentReader> attachmentReader;
218 bool sendPlaybackStartedMessage;
221 bool sendPlaybackFinishedMessage;
224 bool sendCompletedMessage;
227 bool isSetFailedCalled;
230 bool isPlaybackInitiated;
236 bool isCancelInitiated;
245 std::vector<avsCommon::utils::audioAnalyzer::AudioAnalyzerState> analyzersData;
263 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> mediaPlayer,
264 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
265 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
266 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
267 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>
metricRecorder,
268 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
269 std::shared_ptr<captions::CaptionManagerInterface> captionManager =
nullptr,
270 std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> powerResourceManager =
nullptr);
272 void doShutdown()
override;
287 void executeHandleImmediately(std::shared_ptr<DirectiveInfo> info);
297 void executePreHandleAfterValidation(std::shared_ptr<SpeakDirectiveInfo> speakInfo);
307 void executeHandleAfterValidation(std::shared_ptr<SpeakDirectiveInfo> speakInfo);
315 void executePreHandle(std::shared_ptr<DirectiveInfo> info);
323 void executeHandle(std::shared_ptr<DirectiveInfo> info);
330 void executeCancel(std::shared_ptr<DirectiveInfo> info);
337 void executeCancel(std::shared_ptr<SpeakDirectiveInfo> speakInfo,
bool internalCancel);
354 void executeProvideStateLocked(
const unsigned int& stateRequestToken);
359 void executePlaybackStarted();
364 void executePlaybackFinished();
371 void executePlaybackStopped(
SourceId id);
392 void submitInstanceEntryMetric(
395 const std::map<std::string, std::string>& metadata = {});
403 void executeOnDialogUXStateChanged(
472 void resetCurrentInfo();
477 void setHandlingCompleted();
484 void setHandlingFailed(
const std::string& description);
493 void sendExceptionEncounteredAndReportFailed(
494 std::shared_ptr<SpeakDirectiveInfo> info,
504 void sendExceptionEncounteredAndReportMissingProperty(
505 std::shared_ptr<SpeakDirectiveInfo> info,
514 void sendExceptionEncounteredAndReportUnexpectedPropertyType(
515 std::shared_ptr<SpeakDirectiveInfo> info,
521 void releaseForegroundFocus();
531 std::shared_ptr<SpeakDirectiveInfo> validateInfo(
533 std::shared_ptr<DirectiveInfo> info,
534 bool checkResult =
true);
542 std::shared_ptr<SpeakDirectiveInfo> getSpeakDirectiveInfo(
const std::string& messageId);
551 bool setSpeakDirectiveInfo(
553 std::shared_ptr<SpeechSynthesizer::SpeakDirectiveInfo> speakDirectiveInfo);
560 void addToDirectiveQueue(std::shared_ptr<SpeakDirectiveInfo> speakInfo);
567 void removeSpeakDirectiveInfo(
const std::string& messageId);
573 void resetMediaSourceId();
580 void clearPendingDirectivesLocked();
596 int64_t m_offsetInMilliseconds;
599 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> m_speechPlayer;
602 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
605 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
608 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> m_focusManager;
611 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
614 std::shared_ptr<captions::CaptionManagerInterface> m_captionManager;
617 std::unordered_set<std::shared_ptr<SpeechSynthesizerObserverInterface>> m_observers;
636 std::shared_ptr<SpeakDirectiveInfo> m_currentInfo;
642 std::condition_variable m_waitOnStateChange;
645 std::unordered_map<std::string, std::shared_ptr<SpeakDirectiveInfo>> m_speakDirectiveInfoMap;
651 std::mutex m_speakDirectiveInfoMutex;
655 std::deque<std::shared_ptr<SpeakDirectiveInfo>> m_speakInfoQueue;
659 bool m_isShuttingDown;
662 std::mutex m_speakInfoQueueMutex;
665 bool m_initialDialogUXStateReceived;
668 std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
671 std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId> m_powerResourceId;
674 std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> m_powerResourceManager;
689 #endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_SPEECHSYNTHESIZER_INCLUDE_SPEECHSYNTHESIZER_SPEECHSYNTHESIZER_H_ const std::string & name() const
Definition: CapabilityAgent.h:47
void onContextAvailable(const std::string &jsonContext) override
MixingBehavior
Definition: MixingBehavior.h:25
Definition: CapabilityConfigurationInterface.h:32
Definition: NamespaceAndName.h:32
void onContextFailure(const avsCommon::sdkInterfaces::ContextRequestError error) override
PlayBehavior
Used to determine how a client must handle queueing and playback of a stream.
Definition: PlayBehavior.h:29
void onPlaybackError(SourceId id, const avsCommon::utils::mediaPlayer::ErrorType &type, std::string error, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
::std::string string
Definition: gtest-port.h:1097
void addObserver(std::shared_ptr< SpeechSynthesizerObserverInterface > observer)
ContextRequestError
Definition: ContextRequesterInterface.h:40
Single-thread executor implementation.
Definition: Executor.h:45
void onDialogUXStateChanged(DialogUXState newState) override
Definition: RequiresShutdown.h:32
ExceptionErrorType
Definition: ExceptionErrorType.h:28
void onBufferUnderrun(SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
void onFirstByteRead(SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
FocusState
Definition: FocusState.h:29
DialogUXState
The different dialog specific AVS UX states.
Definition: DialogUXStateObserverInterface.h:32
Definition: CaptionData.h:30
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
static std::shared_ptr< SpeechSynthesizer > createSpeechSynthesizer(std::shared_ptr< acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface > audioPipelineFactory, std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface > focusManager, std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionSender, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder, std::shared_ptr< avsCommon::avs::DialogUXStateAggregator > dialogUXStateAggregator, std::shared_ptr< captions::CaptionManagerInterface > captionManager=nullptr, std::shared_ptr< avsCommon::sdkInterfaces::PowerResourceManagerInterface > powerResourceManager=nullptr)
static const constexpr char * SPEAK_MEDIA_PLAYER_NAME
String to identify the speak media player to render audio.
Definition: SpeechSynthesizer.h:55
Definition: MetricEventBuilder.h:31
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
void onFocusChanged(avsCommon::avs::FocusState newFocus, avsCommon::avs::MixingBehavior behavior) override
void provideState(const avsCommon::avs::NamespaceAndName &stateProviderName, const unsigned int stateRequestToken) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onPlaybackStopped(SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
void cancelDirective(std::shared_ptr< DirectiveInfo > info) override
void onPlaybackFinished(SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
void preHandleDirective(std::shared_ptr< DirectiveInfo > info) override
void removeObserver(std::shared_ptr< SpeechSynthesizerObserverInterface > observer)
void onDeregistered() override
type
Definition: upload.py:443
Definition: SpeechSynthesizerObserverInterface.h:32
SpeechSynthesizerState
Definition: SpeechSynthesizerObserverInterface.h:37
std::unordered_set< std::shared_ptr< avsCommon::avs::CapabilityConfiguration > > getCapabilityConfigurations() override
void onPlaybackStarted(SourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
tuple message
Definition: gtest_output_test.py:331
void handleDirective(std::shared_ptr< DirectiveInfo > info) override
void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override
Definition: SpeechSynthesizer.h:61
static std::shared_ptr< SpeechSynthesizer > create(std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface > mediaPlayer, std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface > focusManager, std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionSender, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder, std::shared_ptr< avsCommon::avs::DialogUXStateAggregator > dialogUXStateAggregator, std::shared_ptr< captions::CaptionManagerInterface > captionManager=nullptr, std::shared_ptr< avsCommon::sdkInterfaces::PowerResourceManagerInterface > powerResourceManager=nullptr)
A dialog specific UX state observer.
Definition: DialogUXStateObserverInterface.h:29