午日节高兴!送TTS发音代码,求意见!

美高梅在线登录,?speak("蒲节欢愉!"卡塔尔(قطر‎

OptionExplicitPublicFunctionExtractFileName(ByValstrTextAsString)AsStringDimiPosAsIntegeriPos=InStrRev(strText,"\")ExtractFileName=VBA.Mid$(strText,iPos+1)EndFunction'---------------------------------------------------------------------------------------'过程名:Speak'时间:2013/6/9'作者:杨过.网狐.cn(csdnbcrun)'功能:调用MicrosoftSpeech读出一段文字'参数:strText要朗读的文本,返回值true为成功'说明:因为暂时还不知道更好的选择合适中文语音库的办法,这里采用了strShortVoiceId参数和查找特殊字符串的办法'备注:星辰设计室VB一群:283362041,星辰学园BASIC辅导群:289219875'TTS语音包下载:'---------------------------------------------------------------------------------------PublicFunctionSpeak(ByValstrTextAsString,OptionalByValstrShortVoiceIdAsString="MS-Lili-2052-20-DSK")AsBoolean'DimobjVoiceAsSpeechLib.SpVoice,colVoiceAsISpeechObjectTokensDimobjVoiceAsObject,colVoiceAsObjectDimstrSliceAsString,cnVoiceAsLongDimiAsIntegerOnErrorGoToSpeak_ErrorSpeak=False'SetobjVoice=NewSpeechLib.SpVoiceSetobjVoice=CreateObject("SAPI.SpVoice")SetcolVoice=objVoice.GetVoices()'获得语音引擎集合cnVoice=colVoice.CountobjVoice.Volume=100'设置音量,0到100,数字越大音量越大objVoice.Rate=1'SetobjVoice.Voice=colVoice.Item(cnVoice-1)DimoVoiceItemAsObject,sTokenIdAsStringFori=0TocolVoice.Count-1SetoVoiceItem=colVoice.Item(i)'下面是取得形如这样的字符串的最后面一部分:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MS-Anna-1033-20-DSKsTokenId=ExtractFileName(oVoiceItem.Id)If(StrComp(sTokenId,strShortVoiceId)=0)ThenSetobjVoice.Voice=oVoiceItemExitForElseIf(InStr(1,sTokenId,"2052")0)_Or(InStr(1,sTokenId,"chinese",VbCompareMethod.vbTextCompare)0)ThenSetobjVoice.Voice=oVoiceItemExitForEndIfEndIfNextiIf(objVoice.VoiceIsNothing)ThenExitFunctionDebug.PrintobjVoice.RateDimlTime1AsLong,lTime2AsLong'lTime1=GetTickCount'strText="WelcometouseKingsoftPowerword"CallobjVoice.Speak(strText)',SVSFlagsAsync'lTime2=GetTickCount'Debug.Print"Timeused:"(lTime2-lTime1)Speak=TrueOnErrorGoTo0ExitFunctionSpeak_Error:'MsgBox"Error"Err.Number"("Err.Description")inprocedureSpeakofModulemdlCommon"EndFunction