Public Function 文字转语音(ByVal 文本内容 As String, Optional ByVal 音量 As Long = 100, Optional ByVal 语速 As Long = 0, Optional ByVal 语音引擎名字 As String = "VW Hui")
Dim objVoice As Object
Dim colVoice As Object
Dim i As Long, cnVoice As Long, enVoice As Long
Set objVoice = CreateObject("SAPI.SpVoice")
Set colVoice = objVoice.GetVoices() '获得语音引擎集合
objVoice.Volume = 音量 '设置音量,0到100,数字越大音量越大
objVoice.Rate = 语速 '语音速度
'得到所需语音引擎的编号
cnVoice = 0 For i = 0 To colVoice.Count - 1
'选择语音引擎
'Debug.Print colVoice(i).ID
If Right(colVoice(i).ID, Len(语音引擎名字)) = 语音引擎名字 Then
cnVoice = i
Next
Set objVoice.Voice = colVoice.Item(cnVoice) '设置语音引擎
objVoice.Speak 文本内容
Set objVoice = Nothing
Set colVoice = Nothing
End Function
© 版权声明
文章版权归作者所有,未经允许请勿转载。