高亮显示代码:
'===============================================================================
'-函数名称: MySpeak
'-功能描述: 朗读文本内容
'-输入参数说明: 参数1: 必选 strSpeak As String 朗读的文本内容
' 参数2: 可选 IntRate As Integer 设置朗读的速度 范围:-10到+10
' 参数3: 可选 intVolume As Integer 设置朗读的音量 范围:0到100
' 参数4: 可选 intVoiceID As Integer 朗读者ID
'-返回参数说明:
'-使用语法示例: Call MySpeak ("中华人民共和国")
'-参考: 网上资料
'-使用注意: 需要引用 Microsoft Speech Object Library
'-兼容性:
'-作者: fan0217@163.com
'-更新日期: 2006-05-25
'===============================================================================
Private Function MySpeak(strSpeak As String, _
Optional intRate As Integer = 0, _
Optional intVolume As Integer = 50, _
Optional intVoiceID As Integer = 0) As Boolean
On Error GoTo Err_MySpeak
Dim oVoise As New SpeechLib.SpVoice
Dim intTotalSpeech As Integer
intTotalSpeech = oVoise.GetVoices.Count '获取朗读者的数量
If intTotalSpeech = 0 Then Exit Function
'设置朗读者
If intVoiceID > intTotalSpeech - 1 Then intVoiceID = 0
Set oVoise.Voice = oVoise.GetVoices.Item(intVoiceID)
'设置朗读速度
If intRate > 10 Then intRate = 10
If intRate < -10 Then intRate = -10
oVoise.Rate = intRate
'设置朗读音量
If intVolume > 100 Then intVolume = 100
If intVolume < 0 Then intVolume = 0
oVoise.Volume = intVolume
oVoise.Speak strSpeak
MySpeak = True
Exit_MySpeak:
Exit Function
Err_MySpeak:
MySpeak = False
MsgBox Err.Description, 64, "fan0217"
Resume Exit_MySpeak
End Function
'===============================================================================
'-函数名称: GetVoiceIDName
'-功能描述: 获取语音库朗读者名称
'-输入参数说明:
'-返回参数说明:
'-使用语法示例: MsgBox GetVoiceIDName
'-参考: 网上资料
'-使用注意: 需要引用 Microsoft Speech Object Library
'-兼容性:
'-作者: fan0217@163.com
'-更新日期: 2006-05-25
'===============================================================================
Private Function GetVoiceIDName() As String
Dim oVoise As New SpeechLib.SpVoice
Dim i As Integer
Dim intTotal As Integer
Dim cVoiceIDName As String
intTotal = oVoise.GetVoices.Count
For i = 0 To intTotal - 1 '遍历语音库
cVoiceIDName = StrReverse(oVoise.GetVoices.Item(i).ID)
cVoiceIDName = StrReverse(Left(cVoiceIDName, InStr(cVoiceIDName, "\") - 1))
GetVoiceIDName = GetVoiceIDName + cVoiceIDName + ";"
Next