I'm having problem with the encode of speech input for Amazon Lex.
If i assign InputStream as null, it works, i receive the default voice answer from Lex : "How can i help you"
var amazonLexClient = new AmazonLexClient("APPID", "APPSECRET", Amazon.RegionEndpoint.USEast1);
var amazonPostRequest = new Amazon.Lex.Model.PostContentRequest();
var amazonPostResponse = new Amazon.Lex.Model.PostContentResponse();
amazonPostRequest.BotAlias = "BookTrip";
amazonPostRequest.BotName = "BookTrip";
amazonPostRequest.ContentType = "audio/l16; rate=16000; channels=1";
amazonPostRequest.UserId = "user";
amazonPostRequest.InputStream = null;
amazonPostResponse = await amazonLexClient.PostContentAsync(amazonPostRequest);
If i try to send a recorded voice "How are you" using the encode (required by Lex : 16KHz, 8bits, 1 channel) below
var amazonLexClient = new AmazonLexClient("APPID", "APPSECRET", Amazon.RegionEndpoint.USEast1);
var amazonPostRequest = new Amazon.Lex.Model.PostContentRequest();
var amazonPostResponse = new Amazon.Lex.Model.PostContentResponse();
amazonPostRequest.BotAlias = "BookTrip";
amazonPostRequest.BotName = "BookTrip";
amazonPostRequest.ContentType = "audio/l16; rate=16000; channels=1";
amazonPostRequest.UserId = "user";
amazonPostRequest.InputStream = new MemoryStream();
WaveFormat target = new WaveFormat(16000, 8, 1);
WaveStream streamIn = new WaveFileReader("F:\\Whatever.wav");
WaveFormatConversionStream str = new WaveFormatConversionStream(target, streamIn);
WaveFileWriter.WriteWavFileToStream(amazonPostRequest.InputStream, str);
amazonPostResponse = await amazonLexClient.PostContentAsync(amazonPostRequest);
Then it doesn't work, after about 20~25s Lex server will return null.
Amazon.Runtime.AmazonUnmarshallingException: 'Error unmarshalling response back from AWS.'
NullReferenceException: Object reference not set to an instance of an object.
Can anyone tell me how to encode a wav file to make it work with Amazon Lex? Btw im using Visual Studio 2017, C# with NAudio library.