Esempio n. 1
0
        private async Task fakeAudio()
        {
            // Display the string.
            string text = "Hello, my name is Paul can you hear me?";

            string InLang = "en";
            string outLang = "es-MX";
            Translator Trans = new Translator(text, InLang, outLang);
            string translatedS = Trans.GetTranslatedString();

            SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(translatedS);

            var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                //video.Source = new Uri("ms-resource:///Files/Assets/fireworks.mp4");
                media.SetSource(stream, stream.ContentType);
                media.Play();
                //originalmsg.Text = text;
                //ReceivedText.Text = translatedS;
                //ReceivedText.FontSize = 20;
            });
        }
Esempio n. 2
0
        private async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {

            DataReader reader = new DataReader(args.Socket.InputStream);
            try
            {
                while (true)
                {
                    // Read first 4 bytes (length of the subsequent string).
                    uint sizeFieldCount = await reader.LoadAsync(sizeof(uint));
                    if (sizeFieldCount != sizeof(uint))
                    {
                        // The underlying socket was closed before we were able to read the whole data.
                        return;
                    }

                    // Read the string.
                    uint stringLength = reader.ReadUInt32();
                    uint actualStringLength = await reader.LoadAsync(stringLength);
                    if (stringLength != actualStringLength)
                    {
                        // The underlying socket was closed before we were able to read the whole data.
                        return;
                    }

                    // Display the string.
                    string text = reader.ReadString(actualStringLength);

                    string InLang = "en";
                    string outLang = "es-MX";
                    Translator Trans = new Translator(text, InLang, outLang);
                    string translatedS = Trans.GetTranslatedString();

                    SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(translatedS);
                    var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        media.SetSource(stream, stream.ContentType);
                        media.Play();
                        originalmsg.Text = text;
                        ReceivedText.Text = translatedS;
                        ReceivedText.FontSize = 20;
                    });
                }
            }
            catch (Exception exception)
            {
                // If this is an unknown status it means that the error is fatal and retry will likely fail.
                if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                {
                    throw;
                }
                var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    StatusText.Text = "Error in Socket reading data from Remote host: " + exception.Message;
                    connected = false;
                    CoreApplication.Properties.Remove("clientSocket");
                    CoreApplication.Properties.Remove("clientDataWriter");
                });
            }
        }