Announcement

Collapse
No announcement yet.

UWP App sprechen / vorlesen lassen Cortana?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • UWP App sprechen / vorlesen lassen Cortana?

    hallo, ich habe eine kleine Beispiel App (um)geschrieben mit der ich über Cortana Sprachbefehle eine Aktion in meiner App ausführe. Also an Stelle eines Buttonclicks. Das klappt wunderbar.

    Es kann aber manchmal sein dass es zu einer Exception kommt weil mein Befehl einen Webrequest macht und mein Ziel ggf. offline ist. Da ich mit Sprache steuere, habe ich nicht unbedingt das Device in der Hand und ich sehe die Messagebox nicht die sagt "es ist ein Fehler aufgetreten".

    Ich suche nach einer Möglichkeit dass mir Cortana oder etwas anders einen String vorliest so dass ich höre dass es einen Fehler gab.

  • #2
    Code:
            // Sprachausgabe
            private MediaElement media = new MediaElement();
    
    
            public async Task Speak(string Text2Speech)
            {
                // The media object for controlling and playing audio.
                Windows.UI.Xaml.Controls.MediaElement mediaElement = this.media;
    
                // The object for controlling the speech synthesis engine (voice).
                var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
    
                IEnumerable<VoiceInformation> germanVoices = from singlevoice in SpeechSynthesizer.AllVoices  
                          where singlevoice.Language == "de-DE"
                          select singlevoice;
                synth.Voice = germanVoices.ElementAt(0);
    
                // Generate the audio stream from plain text.
                SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(Text2Speech);
    
                // Send the stream to the media object.
                mediaElement.SetSource(stream, stream.ContentType);
                mediaElement.Play();
            }
    
    
    
    // Aufruf mit 
    await Speak("Anwendung betriebsbereit");

    Comment

    Working...
    X