看了不少语音朗读的例子,觉得都不够理想,前段时间在网上的偶然所得,把它改编成为通用模块方便大家使用。
可改变朗读者,调节音量和朗读速度。
注意:需要引用 Microsoft Speech Object Library
<'===============================================================================
'-函数名称: 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
'===============================================================================
rivate 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
本贴将持续更新:陆续贴上我收集到的语音朗读的方法.
[此贴子已经被作者于2006-5-27 22:00:10编辑过] |