Use of dotnetspeech. dll

Source: Internet
Author: User

Voice is the most natural way for humans to interact with each other and the highest goal of software user interface development at present. Microsoft has been actively promoting the development of speech technology, and released the speech development platform speech SDK to help developers implement speech applications.

Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using dotnetspeech;

Namespace speechapp
{
/// <Summary>
/// Summary of form1.
/// </Summary>
Public class form1: system. Windows. Forms. Form
{
Private system. Windows. Forms. groupbox groupbox1;
Private system. Windows. Forms. textbox textbox1;
Private system. Windows. Forms. Button buttonsynthesis;
Private system. Windows. Forms. Button buttonttstowave;
/// <Summary>
/// Required designer variables.
/// </Summary>
Private system. componentmodel. Container components = NULL;

Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();

//
// Todo: add Any constructor after initializecomponent callsCode
//
}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}

# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. groupbox1 = new system. Windows. Forms. groupbox ();
This. textbox1 = new system. Windows. Forms. Textbox ();
This. buttonsynthesis = new system. Windows. Forms. Button ();
This. buttonttstowave = new system. Windows. Forms. Button ();
This. groupbox1.suspendlayout ();
This. suspendlayout ();
//
// Groupbox1
//
This. groupbox1.controls. Add (this. textbox1 );
This. groupbox1.location = new system. Drawing. Point (8, 8 );
This. groupbox1.name = "groupbox1 ";
This. groupbox1.size = new system. Drawing. Size (272,144 );
This. groupbox1.tabindex = 0;
This. groupbox1.tabstop = false;
This. groupbox1.text = "Enter the text to be merged ";
//
// Textbox1
//
This. textbox1.location = new system. Drawing. Point (8, 24 );
This. textbox1.multiline = true;
This. textbox1.name = "textbox1 ";
This. textbox1.size = new system. Drawing. Size (256,112 );
This. textbox1.tabindex = 0;
This. textbox1.text = "Welcome to Lion interactive network ";
//
// Buttonsynthesis
//
This. buttonsynthesis. causesvalidation = false;
This. buttonsynthesis. flatstyle = system. Windows. Forms. flatstyle. Popup;
This. buttonsynthesis. Location = new system. Drawing. Point (24,160 );
This. buttonsynthesis. Name = "buttonsynthesis ";
This. buttonsynthesis. tabindex = 1;
This. buttonsynthesis. Text = "longread ";
This. buttonsynthesis. Click + = new system. eventhandler (this. buttonsynthesis_click );
//
// Buttonttstowave
//
This. buttonttstowave. causesvalidation = false;
This. buttonttstowave. flatstyle = system. Windows. Forms. flatstyle. Popup;
This. buttonttstowave. Location = new system. Drawing. Point (128,160 );
This. buttonttstowave. Name = "buttonttstowave ";
This. buttonttstowave. size = new system. Drawing. Size (136, 23 );
This. buttonttstowave. tabindex = 2;
This. buttonttstowave. Text = "generate audio file (WAV )";
This. buttonttstowave. Click + = new system. eventhandler (this. buttonttstowave_click );
//
// Form1
//
This. autoscalebasesize = new system. Drawing. Size (6, 14 );
This. clientsize = new system. Drawing. Size (292,191 );
This. Controls. Add (this. buttonttstowave );
This. Controls. Add (this. buttonsynthesis );
This. Controls. Add (this. groupbox1 );
This. formborderstyle = system. Windows. Forms. formborderstyle. fixedsingle;
This. Name = "form1 ";
This. Text = "Welcome to Lion interactive network ";
This. groupbox1.resumelayout (false );
This. resumelayout (false );

}
# Endregion

///


/// main entry point of the application Program .
//
[stathread]
static void main ()
{< br> application. run (New form1 ();
}

/// <Summary>
/// Read aloud
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void buttonsynthesis_click (Object sender, system. eventargs E)
{
Try
{
Dotnetspeech. speechvoicespeakflags SSF = dotnetspeech. speechvoicespeakflags. svsflagsasync;
Dotnetspeech. spvoice Vo = new spvoiceclass ();
VO. Speak (this. textbox1.text, SSF );
}
Catch (system. Exception EC)
{
MessageBox. Show (EC. tostring (), "speechapp", messageboxbuttons. OK, system. Windows. Forms. messageboxicon. Error );
}
}

/// <Summary>
/// Generate a sound file
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void buttonttstowave_click (Object sender, system. eventargs E)
{
Try
{
Dotnetspeech. speechvoicespeakflags SSF = dotnetspeech. speechvoicespeakflags. svsflagsasync;
Dotnetspeech. spvoice Vo = new spvoiceclass ();
System. Windows. Forms. savefiledialog SFD = new system. Windows. Forms. savefiledialog ();
SFD. Filter = "all files (*. *) | *. * | WAV Files (*. wav) | *. wav ";
SFD. Title = "Save to a WAV file ";
SFD. filterindex = 2;
SFD. restoredirectory = true;
If (SFD. showdialog () = system. Windows. Forms. dialogresult. OK)
{
Dotnetspeech. speechstreamfilemode ssfm = dotnetspeech. speechstreamfilemode. ssfmcreateforwrite;
Dotnetspeech. spfilestream SFS = new dotnetspeech. spfilestreamclass ();
SFS. Open (SFD. filename, ssfm, false );
VO. audiooutputstream = SFS;
VO. Speak (this. textbox1.text, SSF );
VO. waituntildone (system. Threading. Timeout. Infinite );
SFS. Close ();
}
}
Catch (system. Exception EC)
{
MessageBox. Show (EC. tostring (), "speechapp", messageboxbuttons. OK, system. Windows. Forms. messageboxicon. Error );
}
}
}
}

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.