Exemplo n.º 1
0
        private async Task Translate(string text)
        {
            TranslationResult translatedResult;

            try
            {
                translatedResult = await translator.Translate(text, inLanguageSpecificCode, outLanguageSpecificCode);
            }
            catch (Exception e)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    checkError.Visibility = Visibility.Visible;
                    errorCheck.Visibility = Visibility.Visible;
                    errorCheck.Text       = "Translation: " + e.Message;
                });

                return;
            }

            var ignored2 = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                media.SetSource(translatedResult.voice, @"audio/wav");
                media.Play();
                originalmsg.Text      = text;
                ReceivedText.Text     = translatedResult.text;
                ReceivedText.FontSize = 20;
            });
        }
Exemplo n.º 2
0
        private async Task Translate(string text)
        {
            var translatedS = string.Empty;

            try
            {
                translatedS = await translator.Translate(text, inLanguageSpecificCode, outLanguageSpecificCode);
            }
            catch (Exception e)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    checkError.Visibility = Visibility.Visible;
                    errorCheck.Visibility = Visibility.Visible;
                    errorCheck.Text       = "Translation: " + e.Message;
                });

                return;
            }

            SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(translatedS);

            var ignored2 = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                media.SetSource(stream, stream.ContentType);
                media.Play();
                originalmsg.Text      = text;
                ReceivedText.Text     = translatedS;
                ReceivedText.FontSize = 20;
            });
        }