speech
This commit is contained in:
9
PacticeSolution/Speech/App.xaml
Normal file
9
PacticeSolution/Speech/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="Speech.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Speech"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
17
PacticeSolution/Speech/App.xaml.cs
Normal file
17
PacticeSolution/Speech/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Speech
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
10
PacticeSolution/Speech/AssemblyInfo.cs
Normal file
10
PacticeSolution/Speech/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
25
PacticeSolution/Speech/MainWindow.xaml
Normal file
25
PacticeSolution/Speech/MainWindow.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<Window x:Class="Speech.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Speech"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="300" Width="300">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button x:Name="speechButton" Grid.Row="0" Content="Speech!" VerticalAlignment="Center" HorizontalAlignment="Center"
|
||||
Click="speechButton_Click"/>
|
||||
<StackPanel Grid.Row="1">
|
||||
<ToggleButton x:Name="recognizeButton" Content="Recognize!" HorizontalAlignment="Center"
|
||||
Click="recognizeButton_Click"/>
|
||||
<TextBox x:Name="recognizeBox" Height="50"
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
81
PacticeSolution/Speech/MainWindow.xaml.cs
Normal file
81
PacticeSolution/Speech/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
14
PacticeSolution/Speech/Speech.csproj
Normal file
14
PacticeSolution/Speech/Speech.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Speech" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user