protected override async Task CustomHandle(Message message)
        {
            var textForDocument = string.Empty;

            if (message.Text != null)
            {
                textForDocument = message.Text;
            }
            else if (message.Photo != null)
            {
                foreach (var photo in message.Photo)
                {
                    MemoryStream photoStream = new MemoryStream();
                    var          file        = await BotClient.GetInfoAndDownloadFileAsync(photo.FileId, photoStream);

                    textForDocument += await _imagesRecognitionService.RecognizeFromFile(photoStream.ToArray());
                }
            }
            else if (message.Voice != null)
            {
                MemoryStream voiceStream = new MemoryStream();
                var          file        = await BotClient.GetInfoAndDownloadFileAsync(message.Voice.FileId, voiceStream);

                textForDocument = await _voiceRecognitionService.RecognizeFromFile(voiceStream.ToArray());
            }

            var documentStream = _documentGenerator.GenerateFromText(textForDocument);

            var bytes    = documentStream.ToArray();
            var document = new InputOnlineFile(new MemoryStream(bytes), "Your document" + _documentGenerator.Extension);

            await BotClient.SendTextMessageAsync(message.Chat.Id, "Your file:");

            await BotClient.SendDocumentAsync(message.Chat.Id, document);
        }
Пример #2
0
        protected override async Task CustomHandle(Message message)
        {
            var recognizedText = string.Empty;

            MemoryStream stream = new MemoryStream();
            var          file   = await BotClient.GetInfoAndDownloadFileAsync(message.Voice.FileId, stream);

            recognizedText += await _voiceRecognitionService.RecognizeFromFile(stream.ToArray());

            if (!string.IsNullOrEmpty(recognizedText))
            {
                await BotClient.SendTextMessageAsync(message.Chat.Id, "Recognized text: \n" + recognizedText);
            }
            else
            {
                await BotClient.SendTextMessageAsync(message.Chat.Id, "Speech on a voice message was not recognized");
            }
        }