public async static Task <string> PollyDemo(IAmazonPolly pollyClient, IAmazonS3 S3Client, string text) { string result = null; SynthesizeSpeechRequest synthesizeRequest = new SynthesizeSpeechRequest() { LanguageCode = LanguageCode.EnUS, OutputFormat = "mp3", SampleRate = "8000", Text = text, TextType = "text", VoiceId = "Joanna" }; try { Task <SynthesizeSpeechResponse> synthesizeTask = pollyClient.SynthesizeSpeechAsync(synthesizeRequest); SynthesizeSpeechResponse syntheizeResponse = await synthesizeTask; Console.WriteLine(syntheizeResponse.ContentType); Console.WriteLine(syntheizeResponse.RequestCharacters); using (MemoryStream ms = new MemoryStream()) { syntheizeResponse.AudioStream.CopyTo(ms); Console.WriteLine(ms.Length); // Upload image to S3 bucket string bucketName = "reinvent-indiamazones"; //string key = dto.text; string key = "pollytest"; await Task.Run(() => S3Util.UploadToS3(S3Client, bucketName, key, ms)); // TODO : need to check the file exists in S3 result = S3Util.GetPresignedURL(S3Client, bucketName, key); } //syntheizeResponse.AudioStream.CopyTo(result); //result.Flush(); } catch (AmazonPollyException pollyException) { Console.WriteLine(pollyException.Message, pollyException.InnerException); } return(result); }
//public async Task<IActionResult> TranscribeTest([FromBody] TranscribeTestDTO dto) public async Task <IActionResult> TranscribeTest([FromForm] TranscribeTestDTO dto) { string transcriptionUri = null; Guid g = Guid.NewGuid(); string guidString = Convert.ToBase64String(g.ToByteArray()); guidString = guidString.Replace("=", ""); guidString = guidString.Replace("+", ""); guidString = guidString.Replace("/", ""); // Validation check if (string.IsNullOrWhiteSpace(dto.language_code) == true) { return(BadRequest("language_code is empty.")); } if (dto.WAVblob == null || dto.WAVblob.Length <= 0) { return(BadRequest("WAVblob is empty.")); } using (MemoryStream ms = new MemoryStream()) { dto.WAVblob.CopyTo(ms); // Upload image to S3 bucket await Task.Run(() => S3Util.UploadToS3(this.S3Client, "reinvent-indiamazones", "transcribe_test/mytest.wav", ms)); } string mediaUri = "https://reinvent-indiamazones.s3-us-west-2.amazonaws.com/transcribe_test/mytest.wav"; // call Transcribe API transcriptionUri = await TranscribeUtil.TranscribeDemo(this.TranscribeClient, dto.language_code, mediaUri); return(Ok(transcriptionUri)); }
public async Task <IActionResult> Post([FromBody] GameStagePostImageDTO dto) { Console.WriteLine("PostImage entered."); string bucketName = "reinvent-gottalent"; // Retrieving image data // ex: game/10/Happiness.jpg string keyName = string.Format("game/{0}/{1}.jpg", dto.gameId, dto.actionType); string croppedKeyName = string.Format("game/{0}/{1}_cropped.jpg", dto.gameId, dto.actionType); byte[] imageByteArray = Convert.FromBase64String(dto.base64Image); if (imageByteArray.Length == 0) { return(BadRequest("Image length is 0.")); } StageLog newStageLog = null; using (MemoryStream ms = new MemoryStream(imageByteArray)) { // call Rekonition API FaceDetail faceDetail = await RekognitionUtil.GetFaceDetailFromStream(this.RekognitionClient, ms); // Crop image to get face only System.Drawing.Image originalImage = System.Drawing.Image.FromStream(ms); System.Drawing.Image croppedImage = GetCroppedFaceImage(originalImage, faceDetail.BoundingBox); MemoryStream croppedms = new MemoryStream(); croppedImage.Save(croppedms, ImageFormat.Jpeg); // Upload image to S3 bucket //await Task.Run(() => S3Util.UploadToS3(this.S3Client, bucketName, keyName, ms)); await Task.Run(() => S3Util.UploadToS3(this.S3Client, bucketName, keyName, croppedms)); // Get a specific emotion score double emotionScore = 0.0f; if (dto.actionType != "Profile") { emotionScore = RekognitionUtil.GetEmotionScore(faceDetail.Emotions, dto.actionType); } int evaluatedAge = (faceDetail.AgeRange.High + faceDetail.AgeRange.Low) / 2; string evaluatedGender = faceDetail.Gender.Value; // Database update newStageLog = new StageLog { game_id = dto.gameId, action_type = dto.actionType, score = emotionScore, file_loc = keyName, age = evaluatedAge, gender = evaluatedGender, log_date = DateTime.Now }; var value = _context.StageLog.Add(newStageLog); await _context.SaveChangesAsync(); } // Send response string signedURL = S3Util.GetPresignedURL(this.S3Client, bucketName, keyName); newStageLog.file_loc = signedURL; return(Ok(newStageLog)); }