Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBScript文本到语音(到文本)_Vbscript - Fatal编程技术网

VBScript文本到语音(到文本)

VBScript文本到语音(到文本),vbscript,Vbscript,我用VBScript(我的经验有限)制作了一个非常简单的文本到语音程序。它只需打开一个命令提示符,您键入一些内容,然后Windows spvoice就会说出该消息 我希望此应用程序接收消息输入并将该文本添加到单独的.txt文件中。所以基本上,这将是文本到语音到文本。VBScript是否太有限,无法读取和写入文本文件 Dim message, sapi message=InputBox("Enter text:","Enter Text") Set

我用VBScript(我的经验有限)制作了一个非常简单的文本到语音程序。它只需打开一个命令提示符,您键入一些内容,然后Windows spvoice就会说出该消息

我希望此应用程序接收消息输入并将该文本添加到单独的.txt文件中。所以基本上,这将是文本到语音到文本。VBScript是否太有限,无法读取和写入文本文件

Dim message, sapi
  message=InputBox("Enter text:","Enter Text")
  Set sapi=CreateObject("sapi.spvoice")
  sapi.Speak message

您可以使用以下命令将消息写入文本文件

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile _ 
("C:\SpeechMessage.txt",2,true)
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing

编辑:

创建以下内容以避免C根目录上的权限问题:

C:\Speech\
并尝试以下代码,如果该文件不存在,则创建该文件,如果存在,则追加到该文件

Set objFileToWrite = CreateObject("Scripting.FileSystemObject")
If objFileToWrite.FileExists("C:\Speech\Message.txt")  then
       Set objFileToWrite = objFileToWrite.OpenTextFile("C:\Speech\SpeechMessage.txt",8,true)
Else 
      Set objFileToWrite = objFileToWrite.CreateTextFile("C:\Speech\SpeechMessage.txt")   
End If 
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing

您可以使用以下命令将消息写入文本文件

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile _ 
("C:\SpeechMessage.txt",2,true)
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing

编辑:

创建以下内容以避免C根目录上的权限问题:

C:\Speech\
并尝试以下代码,如果该文件不存在,则创建该文件,如果存在,则追加到该文件

Set objFileToWrite = CreateObject("Scripting.FileSystemObject")
If objFileToWrite.FileExists("C:\Speech\Message.txt")  then
       Set objFileToWrite = objFileToWrite.OpenTextFile("C:\Speech\SpeechMessage.txt",8,true)
Else 
      Set objFileToWrite = objFileToWrite.CreateTextFile("C:\Speech\SpeechMessage.txt")   
End If 
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing

这似乎奏效了。起初我遇到800A0046错误的问题。为了解决这个问题,我在C:驱动器中创建了一个新文件夹,并将其根目录下

Dim message, sapi, objFileToWrite

message=InputBox("What do you want me to say?","Speak to Me")
Set sapi=CreateObject("sapi.spvoice")
sapi.Speak message

Set objFileToWrite = 
CreateObject("Scripting.FileSystemObject")
_.OpenTextFile("C:\Speech\LiveChat.txt",2,true)
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing

这似乎奏效了。起初我遇到800A0046错误的问题。为了解决这个问题,我在C:驱动器中创建了一个新文件夹,并将其根目录下

Dim message, sapi, objFileToWrite

message=InputBox("What do you want me to say?","Speak to Me")
Set sapi=CreateObject("sapi.spvoice")
sapi.Speak message

Set objFileToWrite = 
CreateObject("Scripting.FileSystemObject")
_.OpenTextFile("C:\Speech\LiveChat.txt",2,true)
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing

我收到一个“权限被拒绝”错误。我必须以管理员身份运行吗?更具体地说,我得到800A0046error@Nikolajs在这种情况下,VBS不会创建该文件,您能否确认
C:\SpeechMessage.txt
存在,并且您拥有访问该文件的完全权限?为什么不建议使用相对路径(几乎总是可写的)?这似乎可行。奇怪的是,在我收到“权限被拒绝”错误之前,它不工作。我必须以管理员身份运行吗?更具体地说,我得到800A0046error@Nikolajs在这种情况下,VBS不会创建该文件,您能否确认
C:\SpeechMessage.txt
存在,并且您拥有访问该文件的完全权限?为什么不建议使用相对路径(几乎总是可写的)?这似乎可行。奇怪的是它以前不工作