.Net Framework 3.0 Text to Speech
The dot net framework 3.0 now has a managed provider for text to speech. I tested this app on a machine with windows xp service pack 2 and the Dot Net FrameWork 3.0 RC1. The link is to set up instructions for the .net framework 3.0
For this sample add a reference to system.speech, place a textbox named txtSay, a button named btnSay, and listbox named lstVoice. The application fills a list box with the installed voices on the system at startup. When you click on the button it says the text in the textbox with the selected voice.
VB Sample
Imports System.Speech.Synthesis
Public Class Form1
Private Sub btnSay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSay.Click
Dim spk As New SpeechSynthesizer
spk.SelectVoice(lstVoice.SelectedItem.ToString)
spk.Speak(txtSay.Text)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim spk As New SpeechSynthesizer
For Each voice As InstalledVoice In spk.GetInstalledVoices
lstVoice.Items.Add(voice.VoiceInfo.Name)
Next
lstVoice.SelectedIndex = 0
txtSay.Text = "Hello World!"
End Sub
End Class
C# Sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
namespace CS3._Speech
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SpeechSynthesizer spk = new SpeechSynthesizer();
foreach(InstalledVoice voice in spk.GetInstalledVoices())
{
lstVoice.Items.Add(voice.VoiceInfo.Name);
}
lstVoice.SelectedIndex = 0;
txtSay.Text = "Hello World";
}
private void btnSay_Click(object sender, EventArgs e)
{
SpeechSynthesizer spk = new SpeechSynthesizer();
spk.SelectVoice(lstVoice.SelectedItem.ToString());
spk.Speak(txtSay.Text);
}
}
}