- === Let your program start talking (using text reading engine (TTS) technology in VB) === -

zhaozj2021-02-08  244

Use text reading engine (TTS) technology in VB

(Author: Xu Jinxin, 2001 at 13:52 on April 10)

Today, some English learning software popular in the market, often saying that they have used the international top full voice TTS technology, can perform whole English fluorescent reading, and freely adjust the speed and frequency of the reading. So, what is this magical TTS? In fact, TTS is a text-to-speech engine in Microsoft, which calls it to read English. We can also use TTS technology in programming development of English learning software. The author will use Visual Basic 5.0 to uncover the mysterious veil of TTS. First, install the Microsoft Text-To-Speech Engine required to install the TTS engine TTS engine to download Microsoft SPEECH API software, you can also download it on the installation of "Jinshan Word 2000" or "Jinshan Word .NET" Find (file name MSTTS.EXE and SPCHAPI.exe). After installing the TTS engine, you will generate a speech directory in the directory where Windows is located, with a vtxtauto.tlb file, and we need to call it when programming. Second, introduce the vtxtauto.tlb file into the VB 5.0, execute the menu command "File / New Project / Standard EXE" and determine, then "reference" in the menu "Project", click the "Browse" button to the Windows directory The bottom SPEECH subdirectory opens the vtxtauto.tlb file, add "VoiceText 1.0 Type Library" to the reference list, select it and click OK. After introducing the library vtxtauto, we can understand the "Object Browser" in the menu "Object Browser", and the meaning of the properties of the various member functions, using the format. Some main methods and properties, the author will give a comment in the source program below, and will not be listed here, see Figure 1. Third, setting controls and properties Add three Label controls on Form1, a TextBox control, a HScrollBar control, and six CommandButton controls.

The main attributes of the form and each control are set as follows: Form1: caption = "English reading" Label1: caption = "Please enter the English document" Label2: caption = "Langxue speed" label3: caption = "" (Label3 tag is used to display Speed ​​value) text1: text = "please input 中文"; tooltiptext = "Please enter or paste English document"; multiline = true; scrollbars = 3-Both HScroll1: Name = SpeedChange; min = 90; max = 300 (MIN) The maximum value of the maximum speed is used to limit the minimum and maximum value of the adjustable speech.) Command1: name = read; caption = "Read" Command2: Name = pause; caption = "pause" Command3: Name = stop; caption = "stop "Command4: name = prev; caption =" previous sentence "Command5: Name = next; caption =" next "Command6: Name = quit; caption =" Exit "IV, write code below We can write code step by step, The specific code is as follows: 'When the form is loaded, the register method is registered, the two parameters in parentheses are string private suform_load () call vtxtauto.vtxtauto.register (space (8), space (8))' Because The default value is 170, the initial value of the horizontal scroll bar is also set to 170 spetedchange.value = 170 End sub 'set the aloud speed adjustment code, which gives it to the SPEED of the control speed when the value value of the horizontal scroll bar changes properties Private Sub SpeedChange_Change () VTxtAuto.VTxtAuto.Speed ​​= SpeedChange.Value Label3.Caption = SpeedChange.Value End Sub 'settings "read" button code Private Sub read_Click ()' If the reading error, to the error flag processing module ErrorHandler On Error Goto Errorhandler 'Call method speak Read, the first parameter is the text to be read, the second parameter is set a reading style Call vtxtauto.vtxtauto.speak (TRIM (TEXT1.TEXT), VTXTSP_VERYHIGH VTXTST_READING) EXIT SUB ERRORHANDLER: MsgBox "only Can read English documents, can't read Chinese characters! "," Error "end sub 'set" Pause "button code private subpause_click () if vtxtauto.vtxtauto.isspeaking life' If the property isspeaking is true, it means that it is reading aloud.

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

New Post(0)