java 语音输出

java利用微软自带库进行文字转语音输出,做个小记录

此方法基于微软自带库Sapi,暂时没有测试各个操作系统的兼容性

本次使用win7 32位操作系统

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();
        }
    }

  主要用到jacob.jar

posted @ 2017-01-23 11:12  RisingSun-J  阅读(658)  评论(0)    收藏  举报