Error in lexClient->StartConversationAsync

0

I am currently trying to establish a stream connection between my AWSClient and a Lex Bot. I am getting the following error:

aws-sdk-cpp/aws-cpp-sdk-core/source/auth/signer-provider/DefaultAuthSignerProvider.cpp:48: virtual std::shared_ptr<Aws::Client::AWSAuthSigner> Aws::Auth::DefaultAuthSignerProvider::GetSigner(const String&) const: Assertion `false' failed.
Aborted (core dumped)

when the code run through the following line:

lexClient->StartConversationAsync(LexRequest, OnStreamReady, OnResponseCallback, nullptr);
    starting.WaitOne();

the entire .cpp follows:

#include <aws/core/Aws.h>
#include <aws/core/client/AsyncCallerContext.h>
#include <aws/core/utils/Outcome.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/lexv2-runtime/LexRuntimeV2Client.h>
#include <aws/lexv2-runtime/model/AudioInputEvent.h>
#include <aws/lexv2-runtime/model/RecognizeUtteranceRequest.h>
#include <aws/lexv2-runtime/model/RecognizeUtteranceResult.h>
#include <aws/lexv2-runtime/model/StartConversationHandler.h>
#include <aws/lexv2-runtime/model/StartConversationRequest.h>
#include <aws/lexv2-runtime/model/StartConversationRequestEventStream.h>
#include <aws/lex/LexRuntimeServiceClient.h>
#include <aws/lex/LexRuntimeServiceRequest.h>
#include <aws/lex/model/PostContentRequest.h>
#include <aws/lex/model/PostContentResult.h>
#include <iterator>
#include <fstream>
#include <chrono>
#include <unistd.h>

using namespace Aws::LexRuntimeV2;
int SessionCount = 0;

int main(int argc, char* argv[])
{
    std::string lexKey, lexSecret;
    std::string botId, botAliasId, localeId, sessionId, regionId;


    // bot credentials
    botId = "_";
    botAliasId = "_";
    lexKey = "_";
    lexSecret = "_";
    localeId = "en_US";

    // starting api
    Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
    Aws::InitAPI(options);
    Aws::Client::ClientConfiguration config;
    config.region = "us-east-1";

    // creating a lex client
    auto lexClient = Aws::MakeUnique<LexRuntimeV2Client>("MyClient", Aws::Auth::AWSCredentials(lexKey.c_str(), lexSecret.c_str()), config);
    Model::StartConversationRequest LexRequest;
    Model::StartConversationHandler requestHandler;

    requestHandler.SetTranscriptEventCallback([](const Model::TranscriptEvent& ev)
    {
        std::cout << ev.GetTranscript() << std::endl;
    });
    requestHandler.SetOnErrorCallback([](const Aws::Client::AWSError<LexRuntimeV2Errors>& error)
    {
        std::cout << "Request handler: " << error.GetMessage() << std::endl;
    });

    LexRequest.WithLocaleId(localeId).WithBotId(botId.c_str()).WithBotAliasId(botAliasId.c_str()).WithSessionId("Blah")
        .WithConversationMode(Model::ConversationMode::AUDIO).WithEventStreamHandler(requestHandler);

    Aws::Utils::Threading::Semaphore signaling(0 /*initialCount*/, 1 /*maxCount*/);
    auto OnResponseCallback = [&signaling](const LexRuntimeV2Client*,const Model::StartConversationRequest&,
        const Model::StartConversationOutcome& outcome, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&) 
    { 
        std::cout << "Response handler: " << outcome.GetError().GetMessage();
        signaling.Release(); 
    };

    Model::StartConversationRequestEventStream* pStream = nullptr;
    Aws::Utils::Threading::Semaphore starting(0 /*initialCount*/, 1 /*maxCount*/);
    auto OnStreamReady = [&starting,&pStream](Model::StartConversationRequestEventStream& stream)
    {
        pStream = &stream;
        pStream->SetSignatureSeed("blah");
        starting.Release();
    };

    lexClient->StartConversationAsync(LexRequest, OnStreamReady, OnResponseCallback, nullptr);
    starting.WaitOne();
    std::ifstream audioFile(argv[1], std::ios_base::binary);

    if (!audioFile)
    {
        std::cout << "Cannot open audio file " << argv[2] << std::endl;
        return 0;
    }

    if (audioFile) {
        std:: cout << "Audio file is open: "<< std::endl;
    }

    while (!audioFile.eof())
    {
        unsigned char buf[320 + 1];
        audioFile.read((char*)buf, 320);
        Aws::Utils::ByteBuffer bytes(buf, audioFile.gcount());
        Model::AudioInputEvent input;
        auto millisec_since_epoch = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock().now().time_since_epoch()).count();
        input.SetClientTimestampMillis(millisec_since_epoch);
        input.SetAudioChunk(bytes);
        input.SetContentType("audio/lpcm; sample-rate=8000; sample-size-bits=16; channel-count=1; is-big-endian=false");
        pStream->WriteAudioInputEvent(input); // o erro está aqui (quando comento o StartConversation)
        sleep(20);
    }
    signaling.WaitOne(); // prevent the application from exiting until we're done
    

    Aws::ShutdownAPI(options);
}

//g++ -o main main.cpp -laws-cpp-sdk-s3 -laws-cpp-sdk-core -laws-cpp-sdk-lex -laws-cpp-sdk-lex-models -laws-cpp-sdk-lexv2-models -laws-cpp-sdk-lexv2-runtime

I have no idea why this is happening, and without this command i obviously can't publish events to lex, since the connection does not have started

Nessuna risposta

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande