Add English reading function in the program

zhaozj2021-02-08  238

Add English reading function in the program

Huazhong teacher Fan Da Xue Lu Xiaohai (Flier@126.com)

---- Jinshan Word 2000 English full-text reading feature believes that it is a very deep impression that users trying, and as a program designer, you must also add a similar function in your own program, because That will make your own program has a lot of color.

---- In fact, this is not a difficult thing, because Jinshan word tyrants actually use MS TTS (Text -to -Speech) technology, through the programming of MS Speech API, we can fully realize It is more powerful. Next, let us try it in the Delphi environment.

---- First first from the Delivery of the Golden Mountain Words / CIBA to run and install MSTTS.exe (MS TTS Engine) and spchapi.exe (MS SPEECH API).

---- Add an application in Delphi.

---- Then then from Delphi's Menu Project / Import Type Library ... Browse Add ..., browse to the Speech subdirectory under the Windows directory, open vtxtauto.tlb, you can see that we will appear in the Class Names below. The name of the package of the needed interface TvtxtAuto, Note that the Generate Component Wrapper at the bottom of the dialog needs to be selected, click Create Unit to open a Unit named vtxtauto_tlb.

---- At this point, we can start the actual programming.

---- First first in Form's oncreate, you need to initialize and apply:

...

Procedure tfrmmain.formcreate (sender: TOBJECT);

Begin

FISPEECH: = COVTXTAUTO_.CREATE

Fispeech.register ('Demo Site', 'Demo APP');

END;

...

---- Delphi has a good package in Delphi, this only needs to be connected to the package, and his back desk is inquiring, the release is equal to Delphi.

---- Note that the register operation in this is not less, because there are multiple procedures that can be used to set the TTS engine.

---- After placing a TMEMO and a TButton on the mainform, add the corresponding code in its OnClick.

Form printed as follows:

Object frmmain: tfrmmain

LEFT = 296

TOP = 187

Borderstyle = BSDIALOG

CAPTION = 'English full-text reading show'

ClientHeight = 185

Clientwidth = 456

Color = CLBTNFACEFONT.CHARSET = GB2312_CHARSET

Font.color = CLWINDOWTEXT

Font.height = -12

Font.name = 'Song body'

Font.style = []

OldcreateOrder = FALSE

Position = podesktopcenter

Oncreate = formcreate

Pixelsperinch = 96

TextHeight = 12

Object Memtext: TMEMO

LEFT = 8

TOP = 8

Width = 361

HEIGHT = 169

Scrollbars = SSVertical

Taborder = 0

end

Object btnread: tbutton

LEFT = 376

TOP = 8

Width = 75

HEIGHT = 25

CAPTION = 'Lang Read (& R)'

Taborder = 1

Onclick = btnreadclick

end

Object bstnpause: TButton

LEFT = 376

TOP = 40

Width = 75

HEIGHT = 25

CAPTION = 'Pause (& P)'

Enabled = false

Taborder = 2

Onclick = btnpauseclick

end

Object btnstop: tbutton

LEFT = 376

TOP = 72

Width = 75

HEIGHT = 25

CAPTION = 'Stop (& S)'

Enabled = false

Taborder = 3

Onclick = btnstopclick

end

Object btnforward: tbutton

LEFT = 376

TOP = 120

Width = 75

HEIGHT = 25

CAPTION = 'Next sentence (& n)'

Enabled = false

Taborder = 4

Onclick = btnforwardclick

end

Object btnrewind: TButton

LEFT = 376

TOP = 152

Width = 75

HEIGHT = 25

CAPTION = 'Previous (& W)'

Enabled = false

Taborder = 5

Onclick = btnrewindclick

end

end

---- The key code segment is as follows:

---- 1. Reading and stopping

...

Procedure tfrmmain.btnreadclick (sender: TOBJECT);

Begin

FISPEECH.SPEAK (Memtext.Lines.Text, vtxtst_

Reading;

Btnpause.enabled: = true;

BtnStop.enabled: = true;

END;

Procedure tfrmmain.btnstopClick (Sender: TOBJECT);

Begin

FISPEECH.STOPSPEAKING;

Btnpause.enabled: = false; btnStop.enabled: = false;

Btnpause.caption: = 'Pause (& P)';

END;

...

---- The first parameter of the SPEAK member function is transferred to the TTS Engine. The second parameter is combined with the two syndrome of the priority of the priority by the desired reading.

---- 2. Suspension and recovery

...

Procedure tfrmmain.btnpauseclick (sender: TOBJECT);

Begin

With fispeech do

If isspeaking then

Begin

AudioPause;

Btnpause.caption: = 'Recovery (& R)';

end

Else

Begin

AudioSume;

Btnpause.caption: = 'Pause (& P)';

END;

END;

...

---- This in this case can be taken as a front state, then paused and restrained by Audiopause and AudioSume.

---- External member Function Audiofastforward and AudioreWind can skip a reading in front of and after reading the SPEED attribute can also be taken or set up, and the single bit is a word / division, the default is 170.

---- Note Speed ​​and Enabled Attribute Default Setup is only written, but in practice IVTXTAUTO provides GET_SPEED and GET_ENABLED functions, and we only have to modify the vocalization in vtxtauto_tlb unit, such as:

...

IvtxtAuto = Interface (IDispatch)

...

Property Speed: Integer Read Get_Speed ​​Write Set_Speed;

Property enabled: Integer Read_enabled Write set_enable;

...

END;

...

---- You can use Speed ​​and Enabled attributes.

---- To this, a simple English full-text reading is complete, and interested friends can add a monopoly plate, hot key activation.

---- This article is called in Win NT / 98 Delphi 4/5 ring.

转载请注明原文地址:https://www.9cbs.com/read-1553.html

New Post(0)