Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

ContextManager:updateStatesLoopFailed:reason=stateProviderTimedOut #47

Closed
charleschen84 opened this issue Jul 5, 2017 · 0 comments
Closed

Comments

@charleschen84
Copy link

charleschen84 commented Jul 5, 2017

Hi, all

I have made an alexa client demo based alexa-client-sdk-0.5.
And, i can make conversation with alexa-client over my microphone.
Then, i added some code about led and button to handle variable status of aleax-client.
Most time, the program works well.
some time some error appeared.

log is below:

[  354.196902] multi_ctrl_breath_work_fn, new breath work is queued
2017-07-05 01:36:30.895 [  3] I ?:?::x-amzn-requestid: 0e35e3fffec495ae-00004589-0005dfae-7c1117f238211679-dbef60ff-31
2017-07-05 01:36:32.984 [  9] I ?:?::The parsed JSON document does not contain a direct child node with the key:'dialogRequestId'.
2017-07-05 01:36:32.999 [  9] I DirectiveSequencer:onDirective:directive={"namespace\:"SpeechRecognizer"\,name\:"StopCapture"\,messageId\:"6554fbde-31c4-4f2e-8592-d23b608961a7"\,dialogRequestId\:""}
2017-07-05 01:36:33.014 [  a] I DirectiveRouter:handleDirectiveImmediately:messageId=6554fbde-31c4-4f2e-8592-d23b608961a7,action=calling
================>>Alertsstat changed
===>now channel is FOREGROUND
2017-07-05 01:36:33.026 [  6] 0 AudioInputProcessor:executeOnFocusChanged:reason=Lost focus
2017-07-05 01:36:33.029 [  3] I InProcessAttachmentReader:readFailed:reason=SDS is closed
-----mode OFF-------
-----mode OFF-------
2017-07-05 01:36:33.662 [  3] I ?:?::x-amzn-requestid: 0e35e3fffec495ae-00004589-0005dfae-7c1117f238211679-dbef60ff-33
2017-07-05 01:36:41.728 [  8] 0 ContextManager:buildContextSuccessful:context={"context"\:[{"header"\:{"namespace"\:"SpeechSynthesizer"\,"name"\:"SpeechState"}\,"payload"\:{"token"\:"amzn1.as-ct.v1.DOMAIN\:WIKIPEDIA#ACRI#WikiPrompt.766c53bb-9fe9-4c2a-9a66-96db35775367"\,"offsetInMilliseconds"\:0\,"playerActivity"\:"FINISHED"}}\,{"header"\:{"namespace"\:"SpeechRecognizer"\,"name"\:"RecognizerState"}\,"payload"\:{"wakeword"\:"ALEXA"}}]}
================>>Alertsstat changed
===>now channel is BACKGROUND
2017-07-05 01:36:41.763 [  6] I DirectiveProcessor:setDialogRequestId:dialogRequestId=cb1e3062-beb5-49c3-9ae8-4de244327276
2017-07-05 01:36:41.780 [  6] 0 CapabilityAgent:bu[  365.615806] multi_ctrl_breath_work_fn, new breath work is queued
ildJsonEventString:messageId=4e4ab92a-8356-4158-bd83-2bf0aecebbb0,namespace=SpeechRecognizer,name=Recognize
-----mode OFF-------
2017-07-05 01:36:44.419 [  9] I ?:?::The parsed JSON document does not contain a direct child node with the key:'dialogRequestId'.
2017-07-05 01:36:44.427 [  9] I DirectiveSequencer:onDirective:directive={"namespace\:"SpeechRecognizer"\,name\:"StopCapture"\,messageId\:"02f90b1d-fefd-40a3-80b3-dc746b0c8f6f"\,dialogRequestId\:""}
2017-07-05 01:36:44.445 [  a] I DirectiveRouter:handleDirectiveImmediately:messageId=02f90b1d-fefd-40a3-80b3-dc746b0c8f6f,action=calling
================>>Alertsstat changed
===>now channel is FOREGROUND
2017-07-05 01:36:44.457 [  6] 0 AudioInputProcessor:executeOnFocusChanged:reason=Lost focus
2017-07-05 01:36:44.460 [  3] I InProcessAttachmentReader:readFailed:reason=SDS is closed
-----mode OFF-------
-----mode OFF-------
2017-07-05 01:36:45.037 [  3] I ?:?::x-amzn-requestid: 0e35e3fffec495ae-00004589-0005dfae-7c1117f238211679-dbef60ff-35
2017-07-05 01:36:45.954 [  9] I DirectiveSequencer:onDirective:directive={"namespace\:"SpeechSynthesizer"\,name\:"Speak"\,messageId\:"b53d48a0-3745-41ce-9f05-2dd0c6e3cb36"\,dialogRequestId\:"cb1e3062-beb5-49c3-9ae8-4de244327276"}
2017-07-05 01:36:45.972 [  a] I DirectiveRouter:preHandleDirective:messageId=b53d48a0-3745-41ce-9f05-2dd0c6e3cb36,action=calling
2017-07-05 01:36:45.983 [  a] 0 CapabilityAgent:addingMessageIdToMap:messageId=b53d48a0-3745-41ce-9f05-2dd0c6e3cb36
2017-07-05 01:36:45.975 [  9] I DirectiveSequencer:onDirective:directive={"namespace\:"SpeechSynthesizer"\,name\:"Speak"\,messageId\:"debb17e1-9973-48cc-bffa-a9dcf690ad5e"\,dialogRequestId\:"cb1e3062-beb5-49c3-9ae8-4de244327276"}
2017-07-05 01:36:45.993 [  b] I DirectiveRouter:handleDirective:messageId=b53d48a0-3745-41ce-9f05-2dd0c6e3cb36,action=calling
2017-07-05 01:36:46.014 [  9] I DirectiveSequencer:onDirective:directive={"namespace\:"SpeechRecognizer"\,name\:"ExpectSpeech"\,messageId\:"3136ec27-92f8-4299-8939-abf10804383f"\,dialogRequestId\:"cb1e3062-beb5-49c3-9ae8-4de244327276"}
================>>Alertsstat changed
===>now channel is BACKGROUND
ectiveRouter:preHandleDirective:messageId=debb17e1-9973-48cc-bffa-a9dcf690ad5e,action=calling
2017-07-05 01:36:46.060 [  5] 0 MediaPlayer:handleSetSourceCalled
2017-07-05 01:36:46.065 [  a] 0 CapabilityAgent:addingMessageIdToMap:messageId=debb17e1-9973-48cc-bffa-a9dcf690ad5e
2017-07-05 01:36:46.090 [  a] I DirectiveRouter:preHandleDirective:messageId=3136ec27-92f8-4299-8939-abf10804383f,action=calling
2017-07-05 01:36:46.105 [  a] 0 CapabilityAgent:addingMessageIdToMap:messageId=3136ec27-92f8-4299-8939-abf10804383f
-----mode OFF-------
2017-07-05 01:36:46.158 [  5] 0 MediaPlayer:handlePlayCalled
2017-07-05 01:36:46.163 [  5] 0 MediaPlayer:doStopSuccess:reason=alreadyStopped
2017-07-05 01:36:46.879 [  5] 0 MediaPlayer:callingOnPlaybackStarted
2017-07-05 01:36:46.887 [  5] 0 MediaPlayer:handleGetOffsetInMillisecondsCalled
2017-07-05 01:36:46.892 [  7] 0 ContextManager:updateStateLocked:action=updatedState,state={"token"\:"amzn1.as-ct.v1.ThirdPartySdkSpeechlet#ACRI#AlexaSkillsKitActveAudio_ee44f0b8-10a9-4c1b-b91c-8062c2f9b5c1"\,"offsetInMilliseconds"\:610\,"playerActivity"\:"PLAYING"},namespace=SpeechSynthesizer,name=SpeechState
2017-07-05 01:36:46.919 [  7] 0 CapabilityAgent:buildJsonEventString:messageId=4446fe63-39e0-4d4c-abce-d9bb8b6e6498,namespace=SpeechSynthesizer,name=SpeechStarted
2017-07-05 01:36:52.612 [  3] I ?:?::x-amzn-requestid: 0e35e3fffec495ae-00004589-0005dfae-7c1117f238211679-dbef60ff-37
input: type=2,code=0,value 1
-------------- SYN_REPORT ------------
signal(volume change) is send to comsumer!
numid=1,iface=MIXER,name='Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=26,step=0
  : values=7,7
  | dBminmax-min=-0.39dB,max=0.00dB
current alexa volume is: 64,codec vol is 8, step value is : 4
-----mode ADJUST_VOLUME:4-------
save volume m_currentVolume:4,line(392)
tmpbuf:2
tmpbuf:4
[  393.096541] multi_ctrl_breath_work_fn, new breath work is queued
2017-07-05 01:37:11.706 [  8] E ContextManager:updateStatesLoopFailed:reason=stateProviderTimedOut
2017-07-05 01:37:11.712 [  6] E **AudioInputProcessor:executeOnContextFailure:error=STATE_PROVIDER_TIMEDOUT**

my code:

void AlexaClient::InitService(std::string configPath, std::string inputPath)
{
    m_configPath = configPath;
    m_inputPath = inputPath;

    bool isEnabled = false;
    std::ifstream infile(m_configPath);
    assert(infile.good());
    assert(AlexaClientSDKInit::initialize({&infile}));

    m_infoled = std::make_shared<InfoLed>();
    m_infoled->init();

    m_authObserver = std::make_shared<AuthObserver>();
    m_authDelegate = AuthDelegate::create();
    m_authDelegate->setAuthObserver(m_authObserver);

    m_attachmentManager = std::make_shared<avsCommon::avs::attachment::AttachmentManager>(
            AttachmentManager::AttachmentType::IN_PROCESS);
    m_connectionStatusObserver = std::make_shared<ConnectionStatusObserver>();
    m_clientMessageHandler = std::make_shared<ClientMessageHandler>(m_attachmentManager);
    m_messageRouter = std::make_shared<HTTP2MessageRouter>(m_authDelegate, m_attachmentManager);
    m_exceptionEncounteredSender = std::make_shared<TestExceptionEncounteredSender>();

    DirectiveHandlerConfiguration handlerConfig;
    handlerConfig[SET_MUTE_PAIR] = BlockingPolicy::NON_BLOCKING;
    handlerConfig[SPEAK_PAIR] = BlockingPolicy::BLOCKING;
    m_directiveHandler = std::make_shared<TestDirectiveHandler>(handlerConfig);

    m_directiveSequencer = DirectiveSequencer::create(m_exceptionEncounteredSender);
    m_messageInterpreter = std::make_shared<MessageInterpreter>(
            m_exceptionEncounteredSender,
            m_directiveSequencer,
            m_attachmentManager);

    m_StateObserver = std::make_shared<AipStateObserver>();
    assert(nullptr != m_StateObserver);

    m_AlexaClientObserver = std::make_shared<AlexaClientObserver>(std::string("Content"));
    m_AlexaClientObserver_alerts = std::make_shared<AlexaClientObserver>(std::string("Alerts"));
    m_AlexaClientObserver_dialog = std::make_shared<AlexaClientObserver>(std::string("Dialog"));
    m_AlexaClientObserver_alarm = std::make_shared<AlexaClientObserver>(std::string("Alarm"));

    m_AlexaStatIndicator = std::make_shared<AlexaStatIndicator>(
            m_AlexaClientObserver_alarm,
            m_AlexaClientObserver_alerts,
            m_AlexaClientObserver_dialog,
            m_AlexaClientObserver,
            m_StateObserver,
            m_infoled
            );

    m_compatibleAudioFormat.sampleRateHz = COMPATIBLE_SAMPLE_RATE;
    m_compatibleAudioFormat.sampleSizeInBits = COMPATIBLE_SAMPLE_SIZE_IN_BITS;
    m_compatibleAudioFormat.numChannels = COMPATIBLE_NUM_CHANNELS;
    m_compatibleAudioFormat.endianness = COMPATIBLE_ENDIANNESS;
    m_compatibleAudioFormat.encoding = COMPATIBLE_ENCODING;

    size_t nWords = 1024*1024;
    size_t wordSize = 2;
    size_t maxReaders = 4;
    size_t bufferSize = AudioInputStream::calculateBufferSize(nWords, wordSize, maxReaders);

    auto m_Buffer = std::make_shared<AudioInputStream::Buffer>(bufferSize);
    auto m_Sds = AudioInputStream::create(m_Buffer, wordSize, maxReaders);
    assert(nullptr != m_Sds);
    m_AudioBuffer = std::move(m_Sds);
    m_AudioBufferWriter = m_AudioBuffer->createWriter(AudioInputStream::Writer::Policy::NONBLOCKABLE);
    assert(nullptr != m_AudioBufferWriter);

    m_focusManager = std::make_shared<FocusManager>();
    m_contextManager = ContextManager::create();
    assert(nullptr != m_contextManager);
    m_stateProvider = std::make_shared<testStateProvider>(m_contextManager);
    m_contextManager->setStateProvider(VOLUME_STATE_PAIR, m_stateProvider);
    m_focusManager = std::make_shared<FocusManager>();

    // m_focusManager->acquireChannel(CONTENT_CHANNEL_NAME, m_AlexaClientObserver, CONTENT_ACTIVITY_ID);
    // m_focusManager->acquireChannel(DIALOG_CHANNEL_NAME, m_AlexaClientObserver_dialog, DIALOG_ACTIVITY_ID);
    m_focusManager->acquireChannel(ALERTS_CHANNEL_NAME, m_AlexaClientObserver_alerts, ALERTS_ACTIVITY_ID);

    m_contextManager = ContextManager::create();
    assert(nullptr != m_contextManager);

    // Set up connection and connect
    m_avsConnectionManager = std::make_shared<TestMessageSender>(
            m_messageRouter,
            isEnabled,
            m_connectionStatusObserver,
            m_messageInterpreter);
    assert(nullptr != m_avsConnectionManager);
    connect();

    // Set up audio input processor
    m_AudioInputProcessor = AudioInputProcessor::create(
            m_directiveSequencer,
            m_avsConnectionManager,
            m_contextManager,
            m_focusManager,
            m_exceptionEncounteredSender
            );
    assert(nullptr != m_AudioInputProcessor);
    m_AudioInputProcessor->addObserver(m_StateObserver);

    assert(m_directiveSequencer->addDirectiveHandler(m_AudioInputProcessor));

    m_WakeWordTrigger = std::make_shared<WakeWordTrigger>(m_compatibleAudioFormat, m_AudioInputProcessor);
    kwd::KittAiKeyWordDetector::KittAiConfiguration config;
    config = {m_inputPath+MODEL_FILE, MODEL_KEYWORD, KITTAI_SENSITIVITY};
    m_detector = kwd::KittAiKeyWordDetector::create(
            m_AudioBuffer,
            m_compatibleAudioFormat,
            {m_WakeWordTrigger},
            std::unordered_set<std::shared_ptr<KeyWordDetectorStateObserverInterface>>(),
            inputPath + RESOURCE_FILE,
            {config},
            2.0,
            false);
    assert(nullptr != m_detector);

    m_AlexaKeyHandler = std::make_shared<AlexaKeyHandler>(m_compatibleAudioFormat,
            m_AudioBuffer,
            m_AudioInputProcessor,
            m_infoled);

    m_mediaPlayer = MediaPlayer::create();
    assert(nullptr != m_mediaPlayer);

    // Create and register the SpeechSynthesizer.
    m_speechSynthesizer = SpeechSynthesizer::create(m_mediaPlayer,
                                                    m_avsConnectionManager,
                                                    m_focusManager,
                                                    m_contextManager,
                                                    m_attachmentManager,
                                                    m_exceptionEncounteredSender);

    m_speechSynthesizerObserver = std::make_shared<TestSpeechSynthesizerObserver>();
    m_speechSynthesizer->addObserver(m_speechSynthesizerObserver);
    assert(m_directiveSequencer->addDirectiveHandler(m_speechSynthesizer));
}
void AlexaStatIndicator::mainLoop()
{
    FocusState last_stat = FocusState::NONE;

    system("aplay /data/mode_sound/hello.wav");

    while(m_isRuning) {
        FocusState curr_stat = FocusState::NONE;
        AudioInputProcessorObserverInterface::State aip_stat = AudioInputProcessorObserverInterface::State::IDLE;

        aip_stat = m_aipObserver->waitForNext(STAT_CHANGE_TIME_OUT_S);
        if(aip_stat == AudioInputProcessorObserverInterface::State::BUSY) {
            m_infoled->led_open(MODE_VP, 0);
        } else if (aip_stat == AudioInputProcessorObserverInterface::State::RECOGNIZING) {
            m_infoled->led_open(MODE_VP_WAKEUP, 0);
        } else if(aip_stat == AudioInputProcessorObserverInterface::State::EXPECTING_SPEECH) {
            m_infoled->led_open(MODE_VP_WAKEUP, 0);
        } else {

        }

        curr_stat = m_alertObserver->waitForFocusChange(STAT_CHANGE_TIME_OUT);
        if(curr_stat == FocusState::NONE && last_stat != FocusState::NONE) {
            m_infoled->led_open(MODE_OFF, 0);
        } else if(curr_stat == FocusState::BACKGROUND) {
            m_infoled->led_open(MODE_VP_WAKEUP, 0);
        } else if(curr_stat == FocusState::FOREGROUND) {
            m_infoled->led_open(MODE_OFF, 0);
        }

        last_stat = curr_stat;

        curr_stat = m_alarmObserver->waitForFocusChange(STAT_CHANGE_TIME_OUT);
        if(curr_stat == FocusState::FOREGROUND) {
            // m_infoled->led_open(MODE_OFF, 0);
        } else if (curr_stat == FocusState::BACKGROUND) {
            // m_infoled->led_open(MODE_VP_WAKEUP, 0);
        } else {

        }

        curr_stat = m_dialogObserver->waitForFocusChange(STAT_CHANGE_TIME_OUT);
        if(curr_stat != FocusState::NONE) {
            // m_infoled->led_open(MODE_WIFI_ERR, 0);
        }

        curr_stat =  m_contentObserver->waitForFocusChange(STAT_CHANGE_TIME_OUT);
        if(curr_stat != FocusState::NONE) {
            // m_infoled->led_open(MODE_OFF, 0);
        }
    }

    printf("AlexaStatIndicator stat thread dead!\n");
}

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants