sapi.Speak.jpg

1.打开记事本复制如下代码到文件中

2.另存文件名 windows_voice.vbs

3.双击 windows_voice.vbs 电脑就能和你对话了

Dim message, sapi
MsgBox("请戴上耳机听我说....")
message = "这是在您的微软视窗系统上进行的简单语音测试。"
Set sapi = CreateObject("sapi.spvoice")
sapi.Speak message

修改另存 readbook.vbs 就能读取 book.txt的小说了

Dim message, sapi
MsgBox("请戴上耳机听我说....")
message = "这是在您的微软视窗系统上进行的简单语音测试。"
Set sapi = CreateObject("sapi.spvoice")
sapi.Speak message


Const ForReading = 1

Dim fs, ts
set fs = CreateObject("Scripting.FileSystemObject")
set ts = fs.OpenTextFile("book.txt", ForReading)
Do Until ts.AtEndOfStream
    message = ts.ReadLine
    if message <> "" Then
        sapi.Speak message
    End if
Loop
ts.Close
set ts = Nothing
set fs = Nothing

本代码英语原版

Dim message, sapi
MsgBox("Please use the headset and listen to what I have to say...")
message = "This is a simple voice test on your Microsoft Windows."
Set sapi = CreateObject("sapi.spvoice")
sapi.Speak message

好像还可以帮你读取邮件,Win7系统测试没有成功

  • windows-greetings-voice.vbs

    Set Sapi = Wscript.CreateObject("SAPI.SpVoice")
    dim str
    
    if hour(time) < 12 then
      Sapi.speak "Good Morning"
    else
      if hour(time) > 12 then
          if hour(time) > 16 then
              Sapi.speak "Good evening"
          else
              Sapi.speak "Good afternoon"
          end if
      end if
    end if
    
    Sapi.speak "The current day is"
    Sapi.speak date
    
    Sapi.speak "The current time is"
    
    if hour(time) > 12 then
      Sapi.speak hour(time)-12
    else
      if hour(time) = 0 then
          Sapi.speak "12"
      else
          Sapi.speak hour(time)
      end if
    end if
    
    if minute(time) < 10 then
      Sapi.speak "o"
    
      if minute(time) < 1 then
          Sapi.speak "clock"
      else
          Sapi.speak minute(time)
      end if
    else
      Sapi.speak minute(time)
    end if
    if hour(time) > 12 then
      Sapi.speak "P.M."
      else
          if hour(time) = 0 then
              if minute(time) = 0 then
                  Sapi.speak "Midnight"
              else
                  Sapi.speak "A.M."
              end if
          else
              if hour(time) = 12 then
                  if minute(time) = 0 then
                      Sapi.speak "Noon"
              else
                  Sapi.speak "P.M."
              end if
          else
              Sapi.speak "A.M."
          end if
      end if
     end if
    
    Sapi.speak "Checking for new messages. Please standby."
    WScript.Sleep 2000
    
    Set otl = createobject("outlook.application")
    Set session = otl.getnamespace("mapi")
    
    session.logon
      Set inbox = session.getdefaultfolder(6)
      c = 0
    
      For Each m In inbox.items
          If m.unread Then c = c + 1
      Next
    session.logoff
    
    s = "s"
    If c = 1 Then s = ""
    
    Sapi.speak "You have" & c & "unread message" & s
分类: 学习编程

0 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注