2013/11/13

C#.Net 透過TTS去發音 Windows7和Windows8適用

引用System.Speech 4.0.0.0的版本


測試系統為Windows7 32位元 企業版



XML:
<Window x:Class="WpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="80" Width="100">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
    </Grid>
</Window>


Code:
using System.Speech.Synthesis;
using System.Windows;

namespace WpfApplication
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            synthesizer.Rate = 1;
            synthesizer.Volume = 100;
            synthesizer.Speak("I love you");
        }
    }
}


參考資料:
http://msdn.microsoft.com/zh-tw/library/gg145021.aspx
http://msdn.microsoft.com/zh-tw/library/system.speech.synthesis.aspx
http://msdn.microsoft.com/zh-tw/library/system.speech.synthesis.speechsynthesizer.aspx