java字符串输入然后语音输出

1.将jacob.jar考到项目中进行构建路径。

2.将jacob-1.17-M2-x32.dll或者jacob-1.17-M2-x64.dll,考到系统盘:\Windows\System32\下面。

3.将jacob-1.17-M2-x32.dll或者jacob-1.17-M2-x64.dll,考到JDK安装目录的bin下面。

public static void main(String[] args) throws IOException {
 
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
 
        Dispatch sapo = sap.getObject();
        try {
 
            // 音量 0-100
            sap.setProperty("Volume", new Variant(100));
            // 语音朗读速度 -10 到 +10
            sap.setProperty("Rate", new Variant(2));
 
 
            // 执行朗读
            Dispatch.call(sapo, "Speak", new Variant("I am work"));
 
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sapo.safeRelease();
            sap.safeRelease();
        }
    }

  

 
posted @ 2022-09-30 19:29  彼时听风  阅读(168)  评论(0)    收藏  举报