< html xmlns ="http://www.w3.org/1999/xhtml" > < head > < title > 网页朗读程序 </ title > < script type ="text/javascript" > ... //定义并创建ActiveX控件 var VoiceObj = new ActiveXObject("Sapi.SpVoice"); //选择朗读语言 function ChangeVoice() ...{ var i = parseInt( idsVoices.value ); VoiceObj.Voice = VoiceObj.GetVoices().Item(i); } //选择声卡 function ChangeAudioOutput() ...{ var i = parseInt( idsAudioOutputs.value ); VoiceObj.AudioOutput = VoiceObj.GetAudioOutputs().Item(i); } //开始朗读 function Speek(SpeekString) ...{ try ...{ VoiceObj.Speak(SpeekString,1); } catch(exception) ...{ alert(exception.description); } } //停止朗读 function Stop() ...{ try ...{ VoiceObj.Speak("", 2); } catch(exception) ...{ alert(exception.description); } } //初始化页面 function InitializeControls() ...{ var VoicesToken = VoiceObj.GetVoices(); var AudioOutputsToken = VoiceObj.GetAudioOutputs(); for( var i=0; i<VoicesToken.Count; i++ ) ...{ var oOption = document.createElement("option"); idsVoices.options.add(oOption); oOption.innerText = VoicesToken.Item(i).GetDescription(); oOption.value = i; } for( var i=0; i<AudioOutputsToken.Count; i++ ) ...{ var oOption = document.createElement("option"); idsAudioOutputs.options.add(oOption); oOption.innerText = AudioOutputsToken.Item(i).GetDescription(); oOption.value = i; } } </ script > </ head > < body > < div style ="text-align: center" > < table border ="1" cellpadding ="0" cellspacing ="0" style ="width: 600px" > < tr > < td align ="left" colspan ="4" valign ="top" > </ td > </ tr > < tr > < td align ="left" colspan ="4" valign ="top" > </ td > </ tr > < tr > < td align ="left" valign ="top" > 获取朗读语言包 </ td > < td align ="left" valign ="top" > < select id ="idsVoices" onchange ="ChangeVoice()" style ="width: 234px" > </ select > </ td > < td align ="left" valign ="top" > 获取声卡的信息 </ td > < td align ="left" valign ="top" style ="width: 187px" > < select id ="idsAudioOutputs" onchange ="ChangeVoice()" style ="width: 234px" > </ select > </ td > </ tr > < tr > < td align ="left" colspan ="4" valign ="top" style ="text-align: center" > < a href ="#" onmouseover ='Speek("测试程序")' onmouseout ="Stop()" > 测试程序 </ a > </ td > </ tr > </ table > </ div > < script type ="text/javascript" > ... InitializeControls(); </ script > </ body > </ html >