在VB中使用文字朗讀引擎(TTS)技術現今市面上流行的一些英語學習軟件,在廣告詞上經常說自己使用了國際頂尖的全程語音TTS技術,能進行整段英文的流利朗讀,并能自由調節(jié)朗讀的速度與頻率等。那么,這個神奇的TTS究竟是什么東西呢? 其實,TTS是微軟出品的一套文字朗讀引擎(Text-To-Speech Engine),這些英語軟件就是調用它來進行英文朗讀的。我們在英語學習軟件的編程開發(fā)中也可使用TTS技術,下面筆者將利用Visual Basic 5.0來揭開TTS神秘的面紗。 一、安裝TTS引擎 TTS引擎所需的Microsoft Text-to-Speech Engine與Microsoft Speech API軟件都可到微軟的站點去下載,也可以在“金山詞霸2000”或“金山詞霸.net”的安裝光盤上找到(文件名為MSTTS.EXE與SPCHAPI.EXE)。安裝了TTS引擎后,在Windows所在目錄下會生成一個SPEECH目錄,其中有一個Vtxtauto.tlb文件,在編程時我們需要調用它。 二、在VB中引入Vtxtauto.tlb文件 進入VB 5.0,執(zhí)行選單命令“文件/新建工程/標準EXE”并確定,然后執(zhí)行選單“工程”中的“引用”,單擊“瀏覽”按鈕到Windows目錄下的SPEECH子目錄,打開Vtxtauto.tlb文件,將“VoiceText 1.0 Type Library”添加到引用列表中,選中它并單擊確定。將庫Vtxtauto引入VB后,我們可以通過選單“視圖”中的“對象瀏覽器”來了解它所封裝的類,以及各類成員函數的屬性的意義、使用格式等信息。一些主要的方法與屬性意義,筆者在下面的源程序中將給出注釋,在這里就不詳細列出。
創(chuàng)新互聯長期為1000+客戶提供的網站建設服務,團隊從業(yè)經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態(tài)環(huán)境。為臨川企業(yè)提供專業(yè)的網站設計制作、成都網站建設,臨川網站改版等技術服務。擁有10多年豐富建站經驗和眾多成功案例,為您定制開發(fā)。
安裝了sdk后應該可以在控件箱單擊鼠標右鍵,然后選擇部件,在彈出的列表中應該可以找到microsoft tts engine或之類的東西,選擇后就可以吧tts engine作為控件放到窗體上。 調用貌似是用.speak(String)實現的。 由于我是很久以前用的,所以也記得不是很清楚了,你可以找找看。
用 CType(TTS_View1.Rows.Item(i).Cells(j).Controls(1), CheckBox).Checked 判斷
If CType(TTS_View1.Rows.Item(i).Cells(j).Controls(1), CheckBox).Checked = True Then
else
end if
Public Class ks
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 窗體設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之后添加任何初始化
End Sub
'窗體重寫 dispose 以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗體設計器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下過程是 Windows 窗體設計器所必需的
'可以使用 Windows 窗體設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents tx As System.Windows.Forms.TextBox
Friend WithEvents ty As System.Windows.Forms.TextBox
Friend WithEvents tz As System.Windows.Forms.TextBox
Friend WithEvents ok As System.Windows.Forms.Button
Friend WithEvents l1 As System.Windows.Forms.Label
Friend WithEvents l2 As System.Windows.Forms.Label
Friend WithEvents l3 As System.Windows.Forms.Label
System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
Me.l1 = New System.Windows.Forms.Label
Me.l2 = New System.Windows.Forms.Label
Me.l3 = New System.Windows.Forms.Label
Me.tx = New System.Windows.Forms.TextBox
Me.ty = New System.Windows.Forms.TextBox
Me.tz = New System.Windows.Forms.TextBox
Me.ok = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'l1
'
Me.l1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.l1.Location = New System.Drawing.Point(8, 8)
Me.l1.Name = "l1"
Me.l1.Size = New System.Drawing.Size(200, 16)
Me.l1.TabIndex = 0
'
'l2
'
Me.l2.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.l2.Location = New System.Drawing.Point(8, 32)
Me.l2.Name = "l2"
Me.l2.Size = New System.Drawing.Size(200, 16)
Me.l2.TabIndex = 1
'
'l3
'
Me.l3.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.l3.Location = New System.Drawing.Point(8, 56)
Me.l3.Name = "l3"
Me.l3.Size = New System.Drawing.Size(200, 16)
Me.l3.TabIndex = 2
'
'tx
'
Me.tx.Location = New System.Drawing.Point(8, 80)
Me.tx.Name = "tx"
Me.tx.Size = New System.Drawing.Size(200, 25)
Me.tx.TabIndex = 3
Me.tx.Text = "請輸入x"
'
'ty
'
Me.ty.Location = New System.Drawing.Point(8, 104)
Me.ty.Name = "ty"
Me.ty.Size = New System.Drawing.Size(200, 25)
Me.ty.TabIndex = 4
Me.ty.Text = "請輸入y"
'
'tz
'
Me.tz.Location = New System.Drawing.Point(8, 128)
Me.tz.Name = "tz"
Me.tz.Size = New System.Drawing.Size(200, 25)
Me.tz.TabIndex = 5
Me.tz.Text = "請輸入z"
'
'ok
'
Me.ok.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.ok.Location = New System.Drawing.Point(8, 160)
Me.ok.Name = "ok"
Me.ok.Size = New System.Drawing.Size(200, 64)
Me.ok.TabIndex = 6
Me.ok.Text = "ok"
'
'ks
'
Me.AutoScaleBaseSize = New System.Drawing.Size(8, 18)
Me.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte))
Me.ClientSize = New System.Drawing.Size(216, 232)
Me.Controls.Add(Me.ok)
Me.Controls.Add(Me.tz)
Me.Controls.Add(Me.ty)
Me.Controls.Add(Me.tx)
Me.Controls.Add(Me.l3)
Me.Controls.Add(Me.l2)
Me.Controls.Add(Me.l1)
Me.Name = "ks"
Me.Text = "考試"
Me.ResumeLayout(False)
End Sub
#End Region
Dim x, y, z, a, b, c, d, aa, bb, cc As Single
Dim tts, alls As Single
Private Sub ks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = Int(1 + 30 * Rnd())
y = Int(1 + 20 * Rnd())
z = Int(1 + 25 * Rnd())
a = Int(2 + 4 * Rnd())
b = Int(1 + a * 2 * Rnd())
c = Int(1 + b * 2 * Rnd())
d = Int(1 + c * 3 * Rnd())
aa = x + y + z
bb = a * x + b * y + c * z
cc = b * x + c * y + d * z
l1.Text = "x+y+z=" Str(aa)
l2.Text = Str(a) "x+" Str(b) "y+" Str(c) "z=" Str(bb)
l3.Text = Str(b) "x+" Str(c) "y+" Str(d) "z=" Str(cc)
End Sub
Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
If Val(tx.Text) = x And Val(ty.Text) = y And Val(tz.Text) = z Then
tts = tts + 1
End If
alls = alls + 1
tx.Text = ""
ty.Text = ""
tz.Text = ""
x = Int(1 + (1000 ^ 0.5) * Rnd())
y = Int(1 + (10000 ^ 0.4) * Rnd())
z = Int(1 + (100000 ^ 0.3) * Rnd())
a = Int(2 + 4 * Rnd())
b = Int(1 + a * 2 * Rnd())
c = Int(1 + b * 2 * Rnd())
d = Int(1 + c * 3 * Rnd())
aa = x + y + z
bb = a * x + b * y + c * z
cc = b * x + c * y + d * z
l1.Text = "x+y+z=" Str(aa)
l2.Text = Str(a) "x+" Str(b) "y+" Str(c) "z=" Str(bb)
l3.Text = Str(b) "x+" Str(c) "y+" Str(d) "z=" Str(cc)
End Sub
Private Sub ks_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
Dim lv As Single
If Not (alls = 0) Then
lv = Int(tts * 100000 / alls) / 1000
MsgBox(Str(lv) "%", , "正確率")
tx.Visible = False
ty.Visible = False
tz.Visible = False
ok.Visible = False
l1.Visible = False
l2.Visible = False
l3.Visible = False
Else
MsgBox("答題!", , "答題!")
End If
End Sub
End Class