How does Delphi7 call the system voice database?

Source: Internet
Author: User
Tags sapi

(1)To use the voice library of the system, you must first install Microsoft Speech SDK 5.1 and Its Language Pack ,:

Speech SDK 5.1: http://www.newhua.com/soft/38264.htm
Speech SDK 5.1 Language Pack (English): http://www.onlinedown.net/soft/38265.htm

 

(2)After the installation is complete, you need to import the class library in D7 to generate the SAPI component on the IDE component panel.

Start D7, project-> Import Type Library-> Find Microsoft Speech Object Library (Version 5.0)

Click Install ..

The SAPI 5.1 control page is displayed on the D7 component panel.

(3)OK. Start a simple project.

Start D7 to create a new project, throw a tmemo and two tbutton in the window, then throw a tspvoice (SAPI 5.1 control page), and write down the following code:

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, oleserver, speechlib_tlb, stdctrls;

Type
Tform1 = Class (tform)
Button1: tbutton;
Memo1: tmemo;
Spvoice1: tspvoice;
Button2: tbutton;
Button3: tbutton;
Procedure button1click (Sender: tobject );
Procedure button3click (Sender: tobject );
Private
{Private Declarations}
Public
Procedure playvoxex;
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

{Tform1}

Procedure tform1.playvoxex;
VaR
I: integer;
S, T: string;
Begin
S: = memo1.text;
For I: = 1 to length (s) do
Begin
If not (s [I] in [#10, #13]) then
Begin
If bytetype (S, I) = mbsinglebyte then
Begin
Spvoice1.voice: = spvoice1.getvoices ('',''). Item (0); // set the language of the report to read. 0 indicates English and 3 indicates Chinese.
T: = s [I];
End
Else if bytetype (S, I) = mbleadbyte then
Begin
Spvoice1.voice: = spvoice1.getvoices ('',''). Item (3 );
T: = s [I];
T: = s [I] + s [I + 1];
End
Else
Continue;
Spvoice1.speak (T, svsflagsasync); // read text
End;
End;
End;

Procedure tform1.button1click (Sender: tobject );
Begin
Spvoice1.voice: = spvoice1.getvoices ('',''). Item (3 );
Spvoice1.speak (memo1.text, svsflagsasync );
End;

Procedure tform1.button3click (Sender: tobject );
Begin
Spvoice1.voice: = spvoice1.getvoices ('',''). Item (0 );
Spvoice1.speak (memo1.text, svsflagsasync );
End;

End.

Button1 directly reads Chinese speech. button2 can read both Chinese and English (the effect is quite poor), while button3 can directly read

I know so much about it. I hope it will be useful to you...

Added by the respondent

An error will be reported when the code is directly copied and compiled. Press Ctrl + H to open the replacement box. Replace the characters in double quotation marks with two spaces (replace all) and compile the code.
Added by the respondent

Procedure tform1.button3click (Sender: tobject );
Begin
Spvoice1.voice: = spvoice1.getvoices ('',''). Item (0 );
Spvoice1.speak (memo1.text, svsflagsasync );
End;

Changed:

Procedure tform1.button3click (Sender: tobject );
Begin
Playvoxex;
End;

FAQ

After the installation is successful, you can find tspvoice again. After I install tspvoice, I will add this page in Delphi7, and I do not know if the installation is correct.

 

Added by the respondent

Dclusr. dpk is the default control package installed by the user. It should be installed in dclusr before. some other controls in the dpk package... after clicking install on the interface for importing ActiveX, you can select into new package, browse a directory, enter a package name, and then return to the installation.
http://wenwen.soso.com/z/q184043644.htm
The following are all the source code of the TTS Speech program.

Unit unit1; interfaceuses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, vtxtauto_tlb, stdctrls, buttons, oleserver, speechlib_tlb,
Comctrls; Type
Tform1 = Class (tform)
Spvoice1: tspvoice;
Bitbtn1: tbitbtn;
Memo1: tmemo;
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Bitbtn2: tbitbtn;
Bitbtn3: tbitbtn;
Bitbtn4: tbitbtn;
Bitbtn5: tbitbtn;
Comboengine: tcombobox;
Button4: tbutton;
Statusbar1: tstatusbar;
Bitbtn6: tbitbtn;
Procedure bitbtn1click (Sender: tobject );
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Procedure bitbtn2click (Sender: tobject );
Procedure bitbtn3click (Sender: tobject );
Procedure bitbtn4click (Sender: tobject );
Procedure bitbtn5click (Sender: tobject );
Procedure button4click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End; var
Form1: tform1;
Tts: ivtxtauto;
Implementation {$ R *. DFM} procedure tform1.bitbtn1click (Sender: tobject );
Begin
Spvoice1.speak (memo1.lines. Text, spfm_create_always); end; Procedure tform1.button1click (Sender: tobject );
Begin
Spvoice1.pause;
End; Procedure tform1.button2click (Sender: tobject );
Begin
Spvoice1.resume;
End; Procedure tform1.button3click (Sender: tobject );
Begin
If spvoice1.rate <10 then

Spvoice1.rate: = spvoice1.rate + 1;
End; Procedure tform1.bitbtn2click (Sender: tobject );
Begin
If spvoice1.rate>-10 then

Spvoice1.rate: = spvoice1.rate-1;
End; Procedure tform1.bitbtn3click (Sender: tobject );
Begin
If spvoice1.volume <100 thenspvoice1.volume: = spvoice1.volume + 1;
End; Procedure tform1.bitbtn4click (Sender: tobject );
Begin
If spvoice1.volume> 0 thenspvoice1.volume: = spvoice1.volume-1;
End; Procedure tform1.bitbtn5click (Sender: tobject );
VaR
Sots1: ispeechobjecttokens;
Sot1: ispeechobjecttoken;
I: integer;
Begin
Spvoice1.eventinterests: = sveallevents;
Sots1: = spvoice1.getvoices ('',''); comboengine. Clear;
For I: = 0 to sots1.count-1 do
Begin
Sot1: = sots1.item (I );
Comboengine. Items. Add (sot1.getdescription (0 ));
End;
Begin
If comboengine. Items. Count> 0 then
Begin
If comboengine. Items. indexof ('Microsoft simplified China') =-1 then
Comboengine. itemindex: = 0
Else
Comboengine. itemindex: = comboengine. Items. indexof ('Microsoft simplified China ');
End;
End;
End;
Procedure tform1.button4click (Sender: tobject );
VaR // set the available engine
Sots1: ispeechobjecttokens;
Sot1: ispeechobjecttoken;
Begin
If comboengine. itemindex =-1 then exit;
Sots1: = spvoice1.getvoices ('','');
Sot1: = sots1.item (comboengine. itemindex );

Spvoice1.voice: = sot1;
Statusbar1.panels [0]. Text: = 'reading engine: '+ comboengine. Items. Strings [comboengine. itemindex];
End;
End.

Hybrid read in Chinese and English

Under normal circumstances, when a Chinese document contains English and a Chinese speech is selected to read aloud, the English Reading effect may be unsatisfactory; or, an English document contains Chinese characters, when you select an English speech to read aloud, Chinese characters cannot be read out. The solution is to add a Chinese and English voice mark (marked as: <Lang Langid= "XXX"> </Lang>), For example:
<Lang Langid="804"> Chinese sentences </Lang>
The above "Chinese sentences" are forced to be read in Chinese speech
<Lang Langid= "409"> English sentenses </Lang>
The above "English sentenses" will be forcibly read in English Speech
Marking804It represents Chinese and 409 represents English.

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.