百度語音合成

pom 

<!--百度語音識別-->
    <dependency>
      <groupId>com.baidu.aip</groupId>
      <artifactId>java-sdk</artifactId>
      <version>4.9.0</version>
    </dependency>

 測試類

//設置APPID/AK/SK
    public static final String APP_ID = "****************";
    public static final String API_KEY = "*******************";
    public static final String SECRET_KEY = "*************";
    public static AipSpeech client = null;
    public static void main(String[] args) {
        // 初始化一個AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);

        // 可選:設置網絡鏈接參數
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可選:設置代理服務器地址, http和socket二選一,或者均不設置
        //client.setHttpProxy("proxy_host", proxy_port);  // 設置http代理
        //client.setSocketProxy("proxy_host", proxy_port);  // 設置socket代理

        // 可選:設置log4j日誌輸出格式,若不設置,則使用默認配置
        // 也能夠直接經過jvm啓動參數設置此環境變量
        System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");

        // 調用接口
        TtsResponse res = client.synthesis("田老師你好,我是小度", "zh", 1, null);
        byte[] data = res.getData();
        JSONObject res1 = res.getResult();
        if (data != null) {
            try {
                Util.writeBytesToFileSystem(data, "output.mp3");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (res1 != null) {
            System.out.println(res1.toString(2));
        }

    }
相關文章
相關標籤/搜索