zoukankan      html  css  js  c++  java
  • 使用VBS脚本语音朗读文字

    以下代码可朗读指定文本文件中的内容,中英文皆可。

    Dim fso,openFile,voice,str,filePath,fileCharset
    
    'filePath为要朗读的文本文件路径,根据实际替换
    filePath = "D:测试.txt"
    
    'fileCharset为要朗读的文本文件编码,根据实际替换
    fileCharset = "utf-8"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set voice = CreateObject("SAPI.SpVoice")
    Set openFile = fso.OpenTextFile(filePath, 1, True)
    '将从文本中读取的文字存入Str
    str = ReadFile(filePath, fileCharset)
    '朗读文字
    voice.Speak str
    
    '作用:从文件中读取文本
    '参数:
    'filePath:文件路径
    'charSet:文件编码格式
    Function ReadFile(filePath, charSet)
        Dim Str
        Set stm = CreateObject("Adodb.Stream")
        stm.Type = 2
        stm.mode = 3
        stm.charset = charSet
        stm.Open
        stm.loadfromfile filePath
        Str = stm.readtext
        stm.Close
        Set stm = Nothing
        ReadFile = Str
    End Function
    

    使用方法:

    1. 新建一个文本文件,如 “测试.txt”,在里面输入你想要朗读的文字并保存,保存时记住编码格式;
    2. 再新建一个文本文件,将以下代码粘贴进去;
    3. 将filePath修改为要朗读的文本文件的路径,将fileCharset修改为要朗读的文本文件的编码格式;
    4. 修改无误后将文件保存为 "ANSI" 或 “UTF-16 LE” 编码且文件名以 “.vbs” 结尾的文件;
    5. 双击刚才保存的vbs文件开始朗读。
  • 相关阅读:
    远程桌面无法复制粘贴
    tns no listener
    10046 trace and sql
    MySQL replace into 用法(insert into 的增强版)
    USB接口大百科:看完你就分得清充电线了
    世界富人的财富诀窍
    php 23种设计模式的趣味解释
    23种设计模式
    设计模式的分类记忆方法
    项目管理基础:考试必过神之冲刺背诵口诀精简
  • 原文地址:https://www.cnblogs.com/skyzou/p/12441513.html
Copyright © 2011-2022 走看看