C # speech recognition,
Use the automatic voice recognition function of Microsoft operating system to read information.
1. Add "" reference to the project
2. Introduce the namespace: using SpeechLib;
3. Read code:
SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags. SVSFlagsAsync;
SpVoice voice = new SpVoice ();
Voice. Voice = voice. GetVoices (string. Empty, string. Empty). Item (0 );
Voice. Speak ("You are a pretty girl. I want to give it a try, haha", flag );
----------------------------------------------------------------------------
Where:
1. SpeechVoiceSpeakFlags is an enumeration.
"SpVoice flag
SVSFDefault = 0
SVSFlagsAsync = 1
SVSFPurgeBeforeSpeak = 2
SVSFIsFilename = 4
SVSFIsXML = 8
SVSFIsNotXML = 16
SVSFPersistXML = 32
"Normalization mark
SVSFNLPSpeakPunc = 64
"Mask
SVSFNLPMask = 64
SVSFVoiceMask = 127
SVSFUnusedFlags =-1, 128
End enumerator
SVSFDefault
Specify the default settings that should be used. The default value is:
Fixed text string synchronization (overwrite with SVSFlagsAsync ),
Do not clear pending talk requests (overwrite with SVSFPurgeBeforeSpeak ),
To parse XML text, if the first character is left angle brackets (overwrite with SVSFIsXML or SVSFIsNotXML ),
Do not stick to changes in the global XML status on the phone (overwrite SVSFPersistXML ),
Non-extended punctuation characters (overwrite with SVSFNLPSpeakPunc.
SVSFlagsAsync
The specified call should be asynchronous. That is to say, it will immediately return the queued Lecture Request.
SVSFPurgeBeforeSpeak
Clear all pending speaking requests and calls mentioned earlier.
SVSFIsFilename
Is a file name, not a text. As a result, the path of the file is not the speech string, but the path is verbal.
SVSFIsXML
The entered text will be parsed as an XML tag.
SVSFIsNotXML
The entered text will not be marked by the parsed XML.
SVSFPersistXML
The global status changes marked in XML will continue to the talking call.
SVSFNLPSpeakPunc
, Punctuation should be extended to words (for example, "What is this ." Will become "this is the phase ").
SVSFNLPMask
SAPI (instead of text-to-speech engine) processes the flag in this mask.
SVSFVoiceMask
This mask has each flag position setting.
SVSFUnusedFlags
This mask has an unused bit set.
2. SpVoice
SpVoiceClass is the core class that supports speech synthesis (TTS. PassSpVoiceThe object calls the TTS engine to implement the reading function.
The SpVoice class has the following attributes:
Voice: Specifies the pronunciation type, which is equivalent to the person who reads aloud, including Microsoft Mary, Microsoft Mike, Microsoft Sam, and Microsoft Simplified Chinese. The first three types can only read English, and the last one can read Chinese or English. However, for English words, only English letters can be read one by one. In the following program, we will try to solve this problem.
Rate: Speech reading speed. value range:-10 to + 10. The greater the value, the faster the speed.
Volume: Volume. The value ranges from 0 to 100. The larger the value, the larger the volume.
SpVoice provides the following methods:
Speak: converts Text information to speech and reads it according to specified parameters. This method has two parameters: Text and Flags, specify the text to be read and the reading method (synchronous or asynchronous ).
Pause: Pause all reading processes that use this object. This method has no parameters.
Resume: Resume the suspended reading process corresponding to the object. This method has no parameters.