C # Speech reading (SMS & amp; Voice Messaging)

Source: Internet
Author: User
Tags sapi

In a project, the customer requests to send text messages, such as New Year's greetings, to employees of the group company. In addition, you can send voice messages to leaders. The implementation method is as follows.

1. There are several methods for sending mass text messages:

1.1 SMS Cat: a common industrial computer, with a SIM card inserted, can send text messages through the interface, point-to-point transmission, fast and accurate arrival rate, but the outgoing number is a common mobile phone number. Disadvantage: the number of SIM cards to be moved is limited to 200 per hour. If too many messages are sent, the SIM card will be locked. Currently, SMS cats have eight ports, that is, up to 1600 messages can be sent in an hour. The price of each text message is 0.1 yuan. Technical Implementation: Generally, the database is shared as an interface only when the SMS cat has an SDK component. Define four tables: The table to be sent, the table to be sent successfully, the table to be sent failed, and the message receiving table (the system can receive and process text messages sent by text users for two-way interaction ).

1.2 SP method: SP vendors dedicated to text messages provide various interfaces, which only need to be called. The fulfillment rate depends on the business you are applying, you can also make sure that you call out a special service number without buying any device. This is suitable for public information services and the target number is uncertain. The specific sending fee needs to be negotiated with the sp manufacturer. It is said that the cheapest is 4 cents.
Here, we condemn SP vendors for their spam.

1.3 mobile communications: An industrial computer provided by mobile. There are special service numbers, and the arrival rate is very high, but there are restrictions on the whitelist of senders, suitable for internal use within the enterprise. Mobile provides SDK Development kits. The specific fee is based on the number of text messages in the corresponding monthly subscription mode. The sending fee is 5 cents. This is the method we are going to adopt.

2. Mass Voice Messaging
Contact the SP manufacturer. You can use the rental agent method for outbound calls and only play the voice. The vendor provides interfaces to upload wav Files and a list of senders to the server.


In the development of voice messaging, how to read the entered text and save it as a wav file, that is, TTS. The steps for using Microsoft's SAPI 5 in the project are as follows:

1. Download The sapi sdk and Language Pack (both Chinese and Japanese are supported ):

SAPI 5 SDK: http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/speechsdk51.exe

Language Pack: http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/speechsdk51LangPack.exe

2. Read through Chen benfeng's article: the development of Chinese speech application http://www.microsoft.com/china/community/program/originalarticles/TechDoc/Cnspeech.mspx under. Net platform

The Com component import can be completed on the import Com Component Interface of Visual Studio.


The Code is as follows: Chen benfeng
// Read aloud
Private void buttonSynthesis_Click (object sender, System. EventArgs e)
{
Try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags. SVSFlagsAsync;
SpVoice Voice = new SpVoice ();
Voice. Speak (this. textBoxText. Text, SpFlags );
}
Catch (Exception er)
{
MessageBox. Show ("An Error Occured! "," SpeechApp ", MessageBoxButtons. OK, MessageBoxIcon. Error );
}
}
// Generate a sound file (Wav)
Private void buttonTTStoWave_Click (object sender, System. EventArgs e)
{
Try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags. SVSFlagsAsync;
SpVoice Voice = new SpVoice ();
SaveFileDialog sfd = new SaveFileDialog ();
Sfd. Filter = "All files (*. *) | *. * | wav files (*. wav) | *. wav ";
Sfd. Title = "Save to a wave file ";
Sfd. FilterIndex = 2;
Sfd. RestoreDirectory = true;
If (sfd. ShowDialog () = DialogResult. OK)
{
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode. SSFMCreateForWrite;
SpFileStream = new SpFileStream ();
SpFileStream. Open (sfd. FileName, SpFileMode, false );
Voice. AudioOutputStream = SpFileStream;
Voice. Speak (txtSpeakText. Text, SpFlags );
Voice. WaitUntilDone (Timeout. Infinite );
SpFileStream. Close ();
}
}
Catch (Exception er)
{
MessageBox. Show ("An Error Occured! "," SpeechApp ", MessageBoxButtons. OK, MessageBoxIcon. Error );
}
}
3. After using the methods in the article, we encountered a problem. The system can only read English, but cannot read Chinese. Solution: Define the Voice attribute of the SpVoice object as the Chinese type. ISpeechObjectTokens tokens = voice. GetVoices (string. Empty, string. Empty );
Int index = GetChineseVoiceIndex (tokens );
Voice. Voice = tokens. Item (index); a simple text message is generated.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.