Tutorials to .com

Tutorials to .com » Software » Vb » Mixed programming article in English voice output

Mixed programming article in English voice output

Print View , by: iSee ,Total views: 43 ,Word Count: 1869 ,Date: Wed, 26 Aug 2009 Time: 4:09 PM


Qingdao Branch of the Ministry of Information Industry Institute of Electronics 22nd Lang sharp

At present, some software, especially the translation of multi-class software offers voice output function, comparing well-known as "Kingsoft 2000", "unconsciously back the word" and so on, they provide the English reading function is by direct use of Microsoft's TTS (Text-to-Speech) Whole-speech technology to achieve. In fact, we can also program their own through the MS Speech API calls to increase the voice output capabilities, especially for the translation of class software, if there is no voice can say that this software is not complete.
First, the preparatory work for the realization of TTS technology, a necessary precondition for the system need to have MS TTS engine, you can view the Windows directory under the directory whether there is speech to determine whether the engine installed. If not, you can from the "Kingsoft 2000" CD-ROM on ciba subdirectory under the mstts.exe to install the MS TTS engine and spchapi (MS Speech API), or downloaded directly from the interconnection: can http://bcbsrc .home.chinaren.com / ttsapi.exe download the voice interface program TTSapi.exe; can be downloaded from the http://bcbsrc.home.chinaren.com/ttssetup.exe male voice engine program TTSSetup.exe; available from http:// bcbsrc.home.chinaren.com/ttssetup2.exe download female voice engine program TTSSetup2.exe.

Second, the introduction throughout the design process, mainly around the Vtxtauto.tlb carried out this type library, because the type library in the vc achieve more cumbersome, we have chosen to use TLB type library is quite easy to delphi to interact with the Vtxtauto.tlb, and several key features such as "reading", "pause" and "restored", "stop" and the corresponding performance function with a few to achieve the final adoption of DLL (dynamic link library), including its packaging, external while others offer only a few simple interface, you can easily call for Delphi or any other language. Here we through the use of VC + +6.0 to call it by the TTS technology, Delphi has developed a dynamic link library to achieve the English text of the speech output.

3, Delphi implementation of dynamic-link library
1, select "File", "New ...", in the "New Items" dialog box, select "DLL", the new one dynamic link library project Project1.
2, select "File", "New ...", in the "New Items" select the "Unit", a new unit TTSDLL.
3, select "Project", "Import Type Library ...", click on "Add" button, select the C: \ windows \ speech \ directory Vtxtauto.tlb type library, they quickly added to the project came.
4, edit TTSDll modules are as follows:
unit TTSDLL;
interface
uses VtxtAuto_TLB;
procedure Create; export; (to be exported procedures and functions)
procedure Read (text: PChar); export;
procedure Pause; export;
procedure Resume; export;
procedure Stop; export;
function IsSpeaking: Boolean; export;
procedure Destory; export;

var
TTS: IVTxtauto;

implementation
procedure Create;
begin
TTS: = CoVTxtAuto.Create; (create object)
TTS.Register ( 'Project1', 'Project1'); (Register)
end;

procedure Read (text: PChar);
begin
TTS.Speak (text, vtxtst_READING);
(Read function. The first parameter is the text to be read aloud. The second parameter is used to control the reading of the tone and priority, mainly the following may be based on the need for flexible options, and if a number of options can be carried out or operation:
vtxtst_STATEMENT = 1; usual tone when speaking, the default.
vtxtst_QUESTION = 2; question tone.
vtxtst_COMMAND = 4; command tone.
vtxtst_WARNING = 8; a warning tone.
vtxtst_READING = 16; read the tone of the document.
vtxtst_NUMBERS = 32; read the numbers tone.
vtxtst_SPREADSHEET = 64; read the spreadsheet element tone.
vtxtsp_VERYHIGH = 128; immediately read out, you can read the contents of the currently interrupted.
vtxtsp_HIGH = 256; read out as soon as possible to join the queue began to play.
vtxtsp_NORMAL = 512; default, join the queue at the end of play. )
end;

procedure Pause;
begin
TTS.AudioPause; (read) to suspend
end;

procedure Stop;
begin
TTS.StopSpeaking; (read) end
end;

procedure Resume;
begin
TTS.AudioResume; (read) to restore
end;

function IsSpeaking: Boolean;
var
Check: Boolean;
begin
if TTS.IsSpeaking then (determine the current state)
begin
Check: = TRUE; () is currently being read
end
else
begin
Check: = FALSE; () is not currently reading
end;
Result: = Check; (return status value)
end;

procedure Destory;
begin
TTS: = nil; (release object)
end;
end.
5, in front of Project1.dpr add the following to begin the process to be exported function list:
exports
Create index 1,
Read index 2,
Pause index 3,
Resume index 4,
Stop index 5,
IsSpeaking index 6,
Destory index 7;
Compile package can be obtained after the adoption of a TTS voice interface dynamic link library: Project1.dll.

4, in the VC call TTS dynamic link library
1, select "File", "New ..." a new MFC AppWizard (exe) project TTSCall. The final step selection of the base class for CformView. The remaining default settings desirable.
2, in the Form to add four buttons, namely: IDC_BUTTON1 "read"; IDC_BUTTON2 "pause"; IDC_BUTTON4 "resume"; IDC_BUTTON3 "stop", as well as an edit box IDC_EDIT1. And add four button handler: OnRead, OnPause, OnResume, OnStop and edit boxes EN_CHANGE incident response functions: OnChangeEdit. By ClassWizard to edit box m_Text bind the same variable.
3, in order to CTTSCallView class to add two variables: BOOL m_bCreated; HINSTANCE m_DLL; and in the constructor to initialize the.
CTTSCallView:: CTTSCallView (): CFormView (CTTSCallView:: IDD)
(
/ / ((AFX_DATA_INIT (CTTSCallView)
m_Text = _T ( "Hello! Welcome to use this software developed by LangRui.");
/ /)) AFX_DATA_INIT
m_DLL = NULL;
m_bCreated = FALSE;
)
4, depending on class in the initialization function add the code:
void CTTSCallView:: OnInitialUpdate ()
(
CFormView:: OnInitialUpdate ();
GetParentFrame () -> RecalcLayout ();
ResizeParentToFit ();
GetDlgItem (IDC_BUTTON1) -> EnableWindow (TRUE);
GetDlgItem (IDC_BUTTON2) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON4) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON3) -> EnableWindow (FALSE);
)
5, to achieve reading function:
void CTTSCallView:: OnRead ()
(
m_DLL = LoadLibrary ( "Project1.dll"); / / dynamically load the dynamic link library
void (* Create) (void);
/ / Get DLL in the Create Function
Create = (void (*) (void)):: GetProcAddress (m_DLL, "Create");
Create ();
m_bCreated = TRUE;
void (* Read) (char *);
/ / Get DLL function in the Read
Read = (void (*) (char *)):: GetProcAddress (m_DLL, "Read");
/ / Get the edit box contents
UpdateData (TRUE);
char buf [10000];
:: strcpy (buf, m_Text);
Read (buf); / / read the contents of the edit box.
GetDlgItem (IDC_BUTTON1) -> EnableWindow (FALSE );//" read "button is not available
GetDlgItem (IDC_BUTTON2) -> EnableWindow (TRUE); / / "Pause" button is available
GetDlgItem (IDC_BUTTON4) -> EnableWindow (FALSE );//" restore "button is not available
GetDlgItem (IDC_BUTTON3) -> EnableWindow (TRUE); / / "Stop" button is available
)
6, a suspension of functions:
void CTTSCallView:: OnPause ()
(
m_DLL = LoadLibrary ( "Project1.dll");
void (* Pause) ();
Pause = (void (*)()):: GetProcAddress (m_DLL, "Pause");
BOOL (* IsSpeaking) ();
/ / To determine whether they are read
IsSpeaking = (BOOL (*)()):: GetProcAddress (m_DLL, "IsSpeaking");
if (IsSpeaking ())
(
Pause ();
GetDlgItem (IDC_BUTTON1) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON2) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON4) -> EnableWindow (TRUE);
GetDlgItem (IDC_BUTTON3) -> EnableWindow (TRUE);
)
)
7, have resumed their functions:
void CTTSCallView:: OnResume ()
(
m_DLL = LoadLibrary ( "Project1.dll");
void (* Resume) ();
Resume = (void (*)()):: GetProcAddress (m_DLL, "Resume");
BOOL (* IsSpeaking) ();
IsSpeaking = (BOOL (*)()):: GetProcAddress (m_DLL, "IsSpeaking");
if (! IsSpeaking ())
(
Resume ();
GetDlgItem (IDC_BUTTON1) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON2) -> EnableWindow (TRUE);
GetDlgItem (IDC_BUTTON4) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON3) -> EnableWindow (TRUE);
)
)
8, achieving a cessation of function:
void CTTSCallView:: OnStop ()
(
m_DLL = LoadLibrary ( "Project1.dll");
void (* Stop) ();
Stop = (void (*)()):: GetProcAddress (m_DLL, "Stop");
Stop ();// to stop reading
GetDlgItem (IDC_BUTTON1) -> EnableWindow (TRUE);
GetDlgItem (IDC_BUTTON2) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON4) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON3) -> EnableWindow (FALSE);
)
9, when the edit box contents change, but no reading, it should be at the ready to read state:
void CTTSCallView:: OnChangeEdit ()
(
if (m_bCreated)
(
m_DLL = LoadLibrary ( "Project1.dll");
BOOL (* IsSpeaking) ();
IsSpeaking = (BOOL (*)()):: GetProcAddress (m_DLL, "IsSpeaking");
if (! IsSpeaking ())
(
GetDlgItem (IDC_BUTTON1) -> EnableWindow (TRUE);
GetDlgItem (IDC_BUTTON2) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON4) -> EnableWindow (FALSE);
GetDlgItem (IDC_BUTTON3) -> EnableWindow (FALSE);
)
)
)
10, when the program quit when the release of loaded dynamic-link library, add a virtual function DestoryWindow ()
BOOL CTTSCallView:: DestroyWindow ()
(
AfxFreeLibrary (m_DLL);
return CFormView:: DestroyWindow ();
)
5, run the test will be compiled by Delphi dynamic link library Project1.dll copied to the VC's TTSCall project Debug directory. Compile and run the TTSCall projects and in the edit box to write one end of the English, press the "read" button, you can hear the full use of TTS-based voice technology issued by the self-assured voice.
Summary: TTS is full of voice technology, which enables the exact English words and phrases pronounced, and even independently read the entire article in English fluency. And TTS technology is based on English reading rule-based speech synthesis technology is not the word one by one open the machine to engage in reading, so the tone of the transition and the interface between the word very nature, questions with, and the rise and fall tone Imperatives are also can be well demonstrated.


Visual Basic Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.