1

我为 Text to Speech 创建了代码并在 Windows 7 中安装了 Microsoft Speech SDK。当我在 Internet Explorer 中打开此代码时,没有任何反应。

<html>
  <head>
  </head>
  <body>
  <input type="text" name="textinput" size="30">
   <script type="text/vbscript">
    Sub SpeakIt
       Dim msg, sapi
       msg= textinput.Value
       Set sapi=CreateObject("sapi.spvoice")
       sapi.Speak msg
     End Sub
   </script>
   <input type="button" value="speak" onClick="SpeakIt">
  </body>
</html>
4

2 回答 2

2

你需要在Speak按钮上调用 SpeakIt 函数的地方,所以试试这个:

<html>
<head>
</head>
<body>
  <input type="text" name="textinput" size="30">
  <script type="text/vbscript">
    Sub SpeakIt
       Dim msg, sapi
       msg= textinput.Value
       Set sapi=CreateObject("sapi.spvoice")
       sapi.Speak msg
     End Sub
 </script>
 <input type="button" value="speak" onClick="SpeakIt()">
 </body>
</html>

当然,用户会被警告页面上运行的 activeX 脚本。

于 2013-10-05T08:44:34.273 回答
0

以防万一,我必须证明可以使用另一个已安装的声音。

<script type="text/vbscript" language="VBScript"> 
             Sub SpeakIt
               Dim msg, sapi

               msg = "Stackoverflow is the best website to find solutions!"

               Set sapi=CreateObject("sapi.spvoice")
               ' Use it to see installed voices   
               'For Each Voice In sapi.getvoices
               '    I = I + 1
               '    msgbox "" & (I - 1) & " - " & Voice.GetDescription
               'Next

               with sapi
                   Set .voice = .getvoices.item(1) ' I use second installed voice
                   .Volume = 100
                   .Rate = -4
               end with

               sapi.Speak msg
             End Sub

             Sub OnLoad
                SpeakIt
             End Sub
    </script>
</head>
<body onload="OnLoad()" scroll="no">
于 2015-11-20T19:38:18.247 回答