• 使用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文件开始朗读。
  • 相关阅读:
    ‎CocosBuilder 学习笔记(2) ccbi 文件结构分析
    ‎Cocos2d-x 学习笔记(22) TableView
    ‎Cocos2d-x 学习笔记(21.1) ScrollView “甩出”效果与 deaccelerateScrolling 方法
    ‎Cocos2d-x 学习笔记(21) ScrollView (CCScrollView)
    pkg-config
    变量定义
    perror 与 strerror
    popen and system
    exit
    uint8_t
  • 原文地址:https://www.cnblogs.com/skyzou/p/12441513.html
Copyright © 2020-2023  润新知