using System; using System.Collections.Generic; using System.Linq; using System.Speech.Recognition; using System.Speech.Synthesis; using System.Text; 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.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace Speech { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { private SpeechRecognitionEngine _speechRecognizer; public MainWindow() { InitializeComponent(); InitInstance(); } private async void InitInstance() { _speechRecognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")); _speechRecognizer.LoadGrammar(new DictationGrammar()); _speechRecognizer.SpeechRecognized += _speechRecognizer_SpeechRecognized; _speechRecognizer.SetInputToDefaultAudioDevice(); } private void speechButton_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("안녕하세요!"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("저는 스피치 신디사이저입니다."); promptBuilder.EndStyle(); promptBuilder.AppendText("오늘은"); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText(DateTime.Now.ToString("yyyy년 MM월 dd일 HH시 mm분 ss초 fff밀리세컨드")); promptBuilder.AppendText("입니다. 이제부터 학습을 시작합시다."); promptBuilder.AppendText("지금 바로", PromptEmphasis.Strong); promptBuilder.AppendText("시작 합니다."); promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut); promptBuilder.AppendText("의 세계로!"); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); } private void recognizeButton_Click(object sender, RoutedEventArgs e) { if (recognizeButton.IsChecked == true) _speechRecognizer.RecognizeAsync(RecognizeMode.Multiple); else _speechRecognizer.RecognizeAsyncStop(); } private void _speechRecognizer_SpeechRecognized(object? sender, SpeechRecognizedEventArgs e) { recognizeBox.AppendText(e.Result.Text); } } }