Esempio n. 1
0
 public static async Task TrySpeechAsync(string message)
 {
     if (settings.IsTextToSpeechEnabled)
     {
         var speechMessage = Regex.Replace(message, @" ?\(.*?\)", string.Empty);
         await speechService.SpeechAsync(speechMessage);
     }
 }
Esempio n. 2
0
        public async Task DescribeImageAsync()
        {
            IsBusy = true;
            string message = null;

            if (IsOnline)
            {
                try
                {
                    MessengerInstance.Send(new NotificationMessage(Constants.PhotoTaken));

                    using (var stream = await streamingService.GetCurrentFrameAsync())
                    {
                        if (stream != null)
                        {
                            StatusMessage = AppResources.QueryingVisionService;

                            var result = await visionServiceClient.DescribeAsync(stream);

                            StatusMessage = AppResources.VisionServiceQueried;

                            if (result.Description.Captions.Length > 0)
                            {
                                message       = result.Description.Captions.First().Text;
                                StatusMessage = message;

                                if (Settings.AutomaticTranslation && Language != Constants.DefaultLanguge)
                                {
                                    // The description needs to be translated.
                                    StatusMessage = AppResources.Translating;
                                    message       = await translatorService.TranslateAsync(message);
                                }
                            }
                            else
                            {
                                message = AppResources.RecognitionFailed;
                            }
                        }
                        else
                        {
                            message = AppResources.UnableToGetImage;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                    Debug.WriteLine(msg);

                    message = AppResources.RecognitionError;
                }
            }
            else
            {
                // Internet isn't available, to service cannot be reached.
                message = AppResources.NoConnection;
            }

            // Speaks the result.
            StatusMessage = message;
            await speechService.SpeechAsync(message, Language);

            IsBusy = false;
        }