蘭雅sRGB 个人笔记 https://262235.xyz
提供编程和电脑应用视频教程,工具和源代码
C, C++, Python Programming, Source Code, Video

旧Hexo博客 | Github | IP定位WebAPI | Docker Hub
编程中文文档 | 网盘分享 | 中文Linux命令

CorelVBA 使用多线程 CreateThread 解决人工语音导致脚本卡住,还没有解决

CorelVBA 使用多线程 CreateThread 解决人工语音导致脚本卡住,还没有解决

#If VBA7 Then
  Private Declare PtrSafe Function CreateThread Lib "kernel32" (ByVal Fkfpnhh As Long, ByVal Xref As Long, ByVal Jxnj As Long, Mlgstptp As Long, ByVal Bydro As Long, Rny As Long) As Long
  Private Declare PtrSafe Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
#Else
  Private Declare Function CreateThread Lib "kernel32" (ByVal Fkfpnhh As Long, ByVal Xref As Long, ByVal Jxnj As Long, Mlgstptp As Long, ByVal Bydro As Long, Rny As Long) As Long
  Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
#End If
Public id As Long

Private Function Speech_Speak(message As String)
  Dim sapi
  Set sapi = CreateObject("sapi.spvoice")
  sapi.Rate = 0
  sapi.Speak message
End Function


Public Function Speak_Msg(message As String)
Speak_Help = Val(GetSetting("262235.xyz", "Settings", "SpeakHelp", "1"))
If Val(Speak_Help) = 8 Then
  id = CreateThread(0, 0, Speech_Speak(message), 0, 0, 0)

  Call TerminateThread(id, ByVal 0&)
Else
  ' 不说话
End If

End Function

VBA 人工语音示例代码

Sub Speech_Speak()
 
Dim objSV
Set objSV = CreateObject("SAPI.SpVoice")
objSV.Speak ("大家好,我是" & objSV.Voice.GetDescription & ",下面我给大家说一段绕口令.")
objSV.Rate = 5
objSV.Speak ("巴老爷有八十八棵芭蕉树 来了八十八个把式要在巴老爷八十八棵芭蕉树下住 巴老爷拔了八十八棵芭蕉树 不让八十八个把式在八十八棵芭蕉树下住 八十八个把式烧了八十八棵芭蕉树 巴老爷在八十八棵树边哭")
objSV.Rate = 0
objSV.Speak ("太快了屌爆了有木有,我慢一点再说一次吧.")
objSV.Rate = 3
objSV.Speak ("巴老爷有八十八棵芭蕉树 来了八十八个把式要在巴老爷八十八棵芭蕉树下住 巴老爷拔了八十八棵芭蕉树 不让八十八个把式在八十八棵芭蕉树下住 八十八个把式烧了八十八棵芭蕉树 巴老爷在八十八棵树边哭")
objSV.Rate = 0
objSV.Speak ("本期节目到此结束.谢谢收听!")
 
End Sub
本原创文章自由转载,转载请注明本博来源及网址 | 当前页面:蘭雅sRGB 个人笔记 » CorelVBA 使用多线程 CreateThread 解决人工语音导致脚本卡住,还没有解决