Is Amazon Connect supposed to set the outputDialogMode when invoking Lex? - amazon-web-services

When I call a Lambda function from Lex by calling my number set up in AWS Connect, intent_request['outputDialogMode'] always seems to return "text" when using a simple if/else statement.
Is this expected?

That is not what I would expect, but if that is what you are getting then AWS must be doing it differently than what we would think.
Based on the Input/Response Format (bold added):
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
And the ContentType is set depending on what type of content is being sent.
Based on PostContent API:
contentType
You pass this value as the Content-Type HTTP header.
Indicates the audio format or text. The header value must start with one of the following prefixes:
PCM format, audio data must be in little-endian byte order.
audio/l16; rate=16000; channels=1
audio/x-l16; sample-rate=16000; channel-count=1
audio/lpcm; sample-rate=8000; sample-size-bits=16; channel-count=1; is-big-endian=false
Opus format
audio/x-cbr-opus-with-preamble; preamble-size=0; bit-rate=256000; frame-size-
milliseconds=4
Text format
text/plain; charset=utf-8
Required: Yes
Basically, the outputDialogMode is set to Voice only when the contentType is set to either PCM or Opus audio format.
So this must mean that AWS Connect is not actually sending the audio input to your Lex bot. It therefore must be processing the audio through speech-to-text elsewhere and then passing the text output to your Lex bot instead.
Unfortunately, this means that outputDialogMode is not a reliable indicator of a voice channel unless you are using PostContent API to send an audio input file to your Lex bot yourself.

Related

aws sns publising compressed payload

There is a limit of 256KB as the max size of message which can be published to AWS-SNS. Can we compress a message using GZIP and send publish the compressed message to overcome the size limit ?
You can gzip the message body -- however -- SNS message bodies only support UTF-8 character data. Gzipped data is binary, so that is not directly compatible with SNS because not every possible sequence of bytes is also a valid sequence of UTF-8 characters.
So, after gzipping your payload, you need to encode that binary data using a scheme such as base-64. Base-64 encodes arbitrary binary data (8 bits per byte) using only 64 (which is 2^6, giving effectively 6 bits per byte) symbols and so the byte count inflates by 8/6 (133%) as a result of this encoding. This means 192KB of binary data encodes to 256KB of base-64-encoded data, so the maximum allowable size of your message after gzip becomes 192K (since the SNS limit is 256KB). But all the base-64 symbols are valid single-byte UTF-8 characters, which is a significant reason why this encoding is so commonly used, despite its size increase. That, and the fact that gzip typically has a compression ratio far superior to 1.33:1 (which is the break-even point for gzip + base-64).
But if your messages will gzip to 192K or lower, this definitely does work with SNS (as well as SQS, which has the same character set and size limits).
You already take a look at this? https://docs.aws.amazon.com/sns/latest/dg/sns-large-payload-raw-message-delivery.html
If you think that the file can increase on the time I suggest another approach.
Put the file on S3 bucket and attach the S3 Event Notification to SNSTopic so all consumer will be notified when a new file is ready to be processed.
In other word the message of the SNS will be the location of the file and not the file it self.
Think about it.
‪You can also use the SNS/SQS extended client library for large message payloads.‬
‪https://aws.amazon.com/about-aws/whats-new/2020/08/amazon-sns-launches-client-library-supporting-message-payloads-of-up-to-2-gb

What does "useinbandfec is a unidirectional receive-only parameter" mean in Opus?

I am trying to implement a Opus transcoder in C++, and I have some conceptual questions.
As for the useinbandfec parameter, I don't quite understand the meaning of "unidirectional receive-only parameter", as written in RFC7587, section 7.1:
The "useinbandfec" parameter is a unidirectional receive-only
parameter.
For example, Alice is calling Bob. Alice uses Opus codec with useinbandfec=1, while Bob doesn't use Opus. Therefore, there should be a Opus transcoder between the two. If so, how can I configure the settings of Opus encoder and decoder?
As for Alice->Bob where opus_decode() is needed, what value should be sent as the 5th parameter (fecFlag)? And as for Bob->Alice where a Opus encoder is needed, what value should be sent with OPUS_SET_INBAND_FEC() in opus_encoder_ctl()?
Thank you!
Parameter useinbandfec
This parameter means that encoder puts additional information to the stream to recover lost packets. How it works, when encoder encodes number N+1 packet it add there some information about packet N that is useful for decoder if it supports recovery.
If decoder does not support recovery then this information is useless and wasting bandwidth.
Unidirectional receive only parameter meaning
This means that if you specify it in session descriptor (SDP) then this parameters describes capability of receiver and advise sender to use or not to use inbound FEC
Questions:
1
For example, Alice is calling Bob. Alice uses Opus codec with
useinbandfec=1, while Bob doesn't use Opus. Therefore, there should be
a Opus transcoder between the two. If so, how can I configure the
settings of Opus encoder and decoder?
In this configuration you need transcoder between Alice and Bob. If transcoder supports FEC you may prefer to include useinbandfec=1 to SDP fmtp attribute. If encoder (sender on Alice device) is also under your control you MAY set ask encoder to add FEC to the stream in following condtions:
Losses in network (may be detected by RTCP)
Transcoder capability to decode it (may be known from SDP parameter)
2
As for Alice->Bob where opus_decode() is needed, what value should be
sent as the 5th parameter (fecFlag)?
opus_decode FEC flag is used when you detect packet loss (for example by RTP sequence number). Lets assume that you receive packet N and N-1 packet is lost. Then you may restore packet N-1 by calling opus_decode with fecFlag set to true and then decode packet N:
packets[N-1] = decode_opus(pktN, fecFlag=true)
packets[N] = decode_opus(pktN, fecFlag=false)
3
And as for Bob->Alice where a Opus encoder is needed, what value
should be sent with OPUS_SET_INBAND_FEC() in opus_encoder_ctl()?
OPUS_SET_INBAND_FEC is better to set from useinbandfec parameter retrieved from Alice SDP. Also beware that FEC is not included into encoded stream unless you do not set OPUS_SET_PACKET_LOSS_PERC

decompressing IMAP deflated message

I have an issue trying to decompress an imap message compressed using deflate method. The things I've tryed so far were isolating one of the directions of an IMAP conversation (using wireshark's follow tcp function) and saving the message data in an raw format that I hope it contains only the deflated message part. I then found some programs like tinf (1st and 3rd example) and miniz (tgunzip example) and tryed to inflate back that file, but with no succes.
I am missing something? Thank you in advance.
tinf - http://www.ibsensoftware.com/download.html
Miniz - https://code.google.com/archive/p/miniz/source/default/source
Try piping that raw data to:
perl -MCompress::Zlib -pe 'BEGIN{$i = inflateInit(-WindowBits => -15)}
$_=$i->inflate($_)'
The important part is the -WindowBits => -15 that changes the expected format into a raw one without adler checksum.
(that's derived from the dovecot source, works for me on Thunderbird to gmail network capture).
From RFC4978 that specifies IMAP compression (emphasis mine):
When using the zlib library (see RFC1951), the functions
deflateInit2(), deflate(), inflateInit2(), and inflate() suffice to
implement this extension. The windowBits value must be in the range
-8 to -15, or else deflateInit2() uses the wrong format.
deflateParams() can be used to improve compression rate and resource
use. The Z_FULL_FLUSH argument to deflate() can be used to clear the
dictionary (the receiving peer does not need to do anything).

Serialize and deserialize the message using google protobuf in socket programming in C++

Message format to send to server side as below :
package test;
message Test {
required int32 id = 1;
required string name = 2;
}
Server.cpp to do encoding :
string buffer;
test::Test original;
original.set_id(0);
original.set_name("original");
original.AppendToString(&buffer);
send(acceptfd,buffer.c_str(), buffer.size(),0);
By this send function it will send the data to client,i hope and i am not getting any error also for this particular code.
But my concern is like below:
How to decode using Google Protocol buffer for the above message in
the client side
So that i can see/print the message.
You should send more than just the protobuf message to be able to decode it on the client side.
A simple solution would be to send the value of buffer.size() over the socket as a 4-byte integer using network byte order, and the send the buffer itself.
The client should first read the buffer's size from the socket and convert it from network to host byte order. Let's denote the resulting value s. The client must then preallocate a buffer of size s and read s bytes from the socket into it. After that, just use MessageLite::ParseFromString to reconstruct your protobuf.
See here for more info on protobuf message methods.
Also, this document discourages the usage of required:
You should be very careful about marking fields as required. If at
some point you wish to stop writing or sending a required field, it
will be problematic to change the field to an optional field – old
readers will consider messages without this field to be incomplete and
may reject or drop them unintentionally. You should consider writing
application-specific custom validation routines for your buffers
instead. Some engineers at Google have come to the conclusion that
using required does more harm than good; they prefer to use only
optional and repeated. However, this view is not universal.

Progress indication with HTTP file download using WinHTTP

I want to implement an progress bar in my C++ windows application when downloading a file using WinHTTP. Any idea how to do this? It looks as though the WinHttpSetStatusCallback is what I want to use, but I don't see what notification to look for... or how to get the "percent downloaded"...
Help!
Thanks!
Per the docs:
WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE
Data is available to be retrieved with
WinHttpReadData. The
lpvStatusInformation parameter points
to a DWORD that contains the number of
bytes of data available. The
dwStatusInformationLength parameter
itself is 4 (the size of a DWORD).
and
WINHTTP_CALLBACK_STATUS_READ_COMPLETE
Data was successfully read from the
server. The lpvStatusInformation
parameter contains a pointer to the
buffer specified in the call to
WinHttpReadData. The
dwStatusInformationLength parameter
contains the number of bytes read.
There may be other relevant notifications, but these two seem to be the key ones. Getting "percent" is not necessarily trivial because you may not know how much data you're getting (not all downloads have content-length set...); you can get the headers with:
WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
The response header has been received
and is available with
WinHttpQueryHeaders. The
lpvStatusInformation parameter is
NULL.
and if Content-Length IS available then the percentage can be computed by keeping track of the total number of bytes at each "data available" notification, otherwise your guess is as good as mine;-).