Add reference System.Speech
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Speech.Synthesis; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApp127 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Loaded += MainWindow_Loaded; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { SpeechDemo(); } int idx = 0; private void SpeechDemo() { SpeechSynthesizer synth = new SpeechSynthesizer(); synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child); var voices = synth.GetInstalledVoices(); foreach (var voice in voices) { Console.WriteLine(voice.VoiceInfo.Name); } synth.SelectVoice("Microsoft Zira Desktop"); while (true) { string msg = $"{++idx},{Guid.NewGuid().ToString("N").Substring(0, 5)}"; //synth.SetOutputToWaveFile("SpeechSynchesizer2.wav"); synth.Speak(msg); } } } }
标签:Windows,System,MainWindow,Speech,synth,using,WPF,SpeechSynthesizer From: https://www.cnblogs.com/Fred1987/p/18642529