To use C # To develop a Speech program, you must first have the Speech API (SPAI) on your computer ).
By reading this section, you can see whether your computer has installed SPAI:
The Speech API has been an integral component of all Microsoft Windows
Versions since Windows 98. Microsoft Windows XP and Windows Server 2003
Include SAPI version 5.1. Windows Vista and Windows Server 2008 include SAPI
Version 5.3, while Windows 7 des SAPI version 5.4. Code written for SAPI
5.3 (Vista)
Will run on SAPI 5.4 (Windows 7) without recompiling.
Both versions 5.1 and later support Chinese, Japanese, and English languages.
Let's take a look at the example and explain it with a small example:
Create a project-windows Forms application, with the name SpeechDemo
Since my computer is win7, you can add reference directly:
Form code:
[Csharp]
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Using SpeechLib;
Namespace SpeechDemo
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void btnSpeech_Click (object sender, EventArgs e)
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags. SVSFlagsAsync;
SpVoice Voice = new SpVoice ();
Voice. Speak (textBox1.Text, SpFlags );
}
}
}
The code is very simple. As long as you enter Chinese or English in the text box, you can read it normally.
For functions under the SpVoice interface, see: http://msdn.microsoft.com/en-us/library/ee413476 (v = vs.85)
Help connection: http://www.microsoft.com/en-us/Tellme/developers/default.aspx? Tab = desktop
We can see that there are many interfaces in the text-to-speech engine interface (api-level), and many things make us confused. At this time, we should analyze them carefully, find what we need, understand the functions and interfaces we want to call, and do not be intimidated by the things we are not familiar with. Learn the learning method and the learning method by the way, I think this is important.
Author: yjjm1990