当前位置:网站首页>The song of the virtual idol was originally generated in this way!

The song of the virtual idol was originally generated in this way!

2022-07-27 18:41:00 HMS Core

HMS Core Audio editing service (Audio Editor Kit)6.6.0 Version Online , New song synthesis ability . Through lyrics and tunes , Combined with different music styles, the machine can also generate highly authentic songs . Support word level input lyrics for phoneme conversion , Generate a song corresponding to the lyrics , Flexible pitch adjustment 、 Gliding 、 Breathing sounds 、 Vibrato and other detailed parameters , Make the song more authentic .

Voice synthesis services can be widely used in Creative production of audio and video 、 Video entertainment 、 music education 、 Virtual idol Other fields . for example , In music creation or short video creative editing , The song synthesis service can help users create and synthesize songs freely , Make the creation more colorful . In the field of virtual idols , Through singing synthesis , It can make virtual people have the ability to sing in a specific timbre , Make it more vivid . In music games or Singing Education , Song synthesis can quickly generate standard reference sound , Improve the efficiency of audio production and save labor costs .

Song synthesis effect

Heard the singing synthesis comparable to the singing effect of real people , Can't wait to use it , The following is the specific integration method of song synthesis . Come and try the integration yourself !

1. The development of preparation

1.1 Register as a developer

Before developing applications, you need to work in Huawei Developer alliance website Register as a developer and complete real name authentication , Please refer to Account registration authentication .

1.2 Create projects and applications

See Create project , Then under the project Create an Complete the creation of the application , Special configurations are as follows :

Selection platform : choice “Web”.

1.3 Open related services

Use Audio Editor Kit Service requires you to AppGallery Connect Open up Audio Editor Kit Service switch , Please refer to Turn on the service switch .

2. Song synthesis function integration

2.1 Synchronization interface ( streaming )

2.1.1 obtain access_token Authentication information

The client obtained by using the developer alliance interface ID And the corresponding key , send out HTTPS POST request , Get query access_token. For the acquisition method, see Client mode (Client Credentials).

2.1.2 according to access_token Call synchronization interface ( streaming )

Obtained through the above steps access_token Information , send out HTTPS POST Call synchronization interface ( streaming ).

Sample code (Java) As shown below :

among requestUrl = "https://audioeditor-api-drcn.cloud.huawei.com/v1/audioeditor/gateway/ai/ttsing/sync".

/**     *  Call synchronization interface ( streaming )     * @param accessToken  according to clientId And key acquisition token     * @throws Exception IO abnormal      */    private static void syncTask(String accessToken) throws Exception {        //  Set the request header        PostMethod postMethod = new PostMethod(requestUrl);        postMethod.setRequestHeader("Content-Type","application/json;charset=utf-8");        postMethod.setRequestHeader("X-Request-ID","9af1aeda-531b-407a-80b4-65b40ef77bd6");        postMethod.setRequestHeader("X-Package-Name","com.huawei.demo");        postMethod.setRequestHeader("X-Country-Code","cn");        postMethod.setRequestHeader("HMS-APPLICATION-ID","123456");        postMethod.setRequestHeader("certFingerprint","xxxxx");        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);        //  Set the request body        Map<String, Object> bodyMap = new HashMap<>();        Map<String, Object> dataMap = new HashMap<>();        Map<String, Object> configMap = new HashMap<>();        // filePath yes MusicXML File path ( Include file name 、 suffix )        String lyricFilePath = "filePath";        dataMap.put("lyric", FileUtils.readFileToString(new File(lyricFilePath), "UTF-8"));        dataMap.put("language", "chinese");        configMap.put("type", 1);        configMap.put("outputEncoderFormat", 0);        bodyMap.put("data", dataMap);        bodyMap.put("config", configMap);        RequestEntity requestEntity = new StringRequestEntity(JSONObject.toJSONString(bodyMap),"application/json" ,"UTF-8");        postMethod.setRequestEntity(requestEntity);        HttpClient httpClient = new HttpClient();        int ret = httpClient.executeMethod(postMethod);        if (ret == 200) {            Header responseHeader = postMethod.getResponseHeader("content-type");            if ("application/octet-stream".equals(responseHeader.getValue())) {                InputStream rpsContent = postMethod.getResponseBodyAsStream();                // filePath Is the path to save the file ( Include file name 、 suffix )                String filePath = "filePath";                FileUtils.copyInputStreamToFile(rpsContent, new File(filePath));            } else {                String errorString = postMethod.getResponseBodyAsString();                System.out.println(errorString);            }        } else {            System.out.println("callApi failed: ret =" + ret + " rsp=" + postMethod.getResponseBodyAsString());        }    }

2.2 Asynchronous interface

2.2.1 Create asynchronous tasks

adopt access_token Information , send out HTTPS POST Create song synthesis asynchronous task .

  /**     *  Call to create an asynchronous task interface      * @param accessToken  according to clientId And key acquisition token     * @throws Exception IO abnormal      */    private static void creatAsyncTask(String accessToken) throws Exception {        //  Set the request header        PostMethod postMethod = new PostMethod(requestUrl);        postMethod.setRequestHeader("Content-Type","application/json;charset=utf-8");        postMethod.setRequestHeader("X-Request-ID","9af1aeda-531b-407a-80b4-65b40ef77bd6");        postMethod.setRequestHeader("X-Package-Name","com.huawei.demo");        postMethod.setRequestHeader("X-Country-Code","cn");        postMethod.setRequestHeader("HMS-APPLICATION-ID","123456");        postMethod.setRequestHeader("certFingerprint","xxxxx");        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);        //  Set the request body        Map<String, Object> bodyMap = new HashMap<>();        Map<String, Object> dataMap = new HashMap<>();        Map<String, Object> configMap = new HashMap<>();        // filePath yes MusicXML File path ( Include file name 、 suffix )        String lyricFilePath = "filePath";        dataMap.put("lyric", FileUtils.readFileToString(new File(lyricFilePath), "UTF-8"));        dataMap.put("language", "chinese");        configMap.put("type", 1);        configMap.put("outputEncoderFormat", 0);        bodyMap.put("data", dataMap);        bodyMap.put("config", configMap);        RequestEntity requestEntity = new StringRequestEntity(JSONObject.toJSONString(bodyMap),"application/json" ,"UTF-8");        postMethod.setRequestEntity(requestEntity);        HttpClient httpClient = new HttpClient();        int ret = httpClient.executeMethod(postMethod);        String rpsContent = postMethod.getResponseBodyAsString();        if (ret == 200) {            System.out.println(rpsContent);        } else {            System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent);        }    }

2.2.2 Query asynchronous task status

adopt access_token Information , send out HTTPS POST Query song synthesis asynchronous task status .

  /**     *  Call the interface for querying asynchronous task status      * @param accessToken  according to clientId And key acquisition token     * @throws Exception IO abnormal      */    private static void queryAsyncTaskInfo(String accessToken) throws Exception {        //  Set the request header        PostMethod postMethod = new PostMethod(requestUrl);        postMethod.setRequestHeader("Content-Type","application/json;charset=utf-8");        postMethod.setRequestHeader("X-Request-ID","9af1aeda-531b-407a-80b4-65b40ef77bd6");        postMethod.setRequestHeader("X-Package-Name","com.huawei.demo");        postMethod.setRequestHeader("X-Country-Code","cn");        postMethod.setRequestHeader("HMS-APPLICATION-ID","123456");        postMethod.setRequestHeader("certFingerprint","xxxxx");        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);        //  Set the request body        Map<String, Object> bodyMap = new HashMap<>();        // taskId The corresponding value is the task returned when creating the asynchronous task ID(taskId)        bodyMap.put("taskId", "taskId");        RequestEntity requestEntity = new StringRequestEntity(JSONObject.toJSONString(bodyMap),"application/json" ,"UTF-8");        postMethod.setRequestEntity(requestEntity);        HttpClient httpClient = new HttpClient();        int ret = httpClient.executeMethod(postMethod);        String rpsContent = postMethod.getResponseBodyAsString();        if (ret == 200) {            System.out.println(rpsContent);        } else {            System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent);        }    }

2.2.3 Cancel asynchronous task

adopt access_token Information , send out HTTPS POST Cancel asynchronous task .

  /**     *  Call to cancel the asynchronous task interface      * @param accessToken  according to clientId And key acquisition token     * @throws Exception IO abnormal      */    private static void cancelAsuncTask(String accessToken) throws Exception {        //  Set the request header        PostMethod postMethod = new PostMethod(requestUrl);        postMethod.setRequestHeader("Content-Type","application/json;charset=utf-8");        postMethod.setRequestHeader("X-Request-ID","9af1aeda-531b-407a-80b4-65b40ef77bd6");        postMethod.setRequestHeader("X-Package-Name","com.huawei.demo");        postMethod.setRequestHeader("X-Country-Code","cn");        postMethod.setRequestHeader("HMS-APPLICATION-ID","123456");        postMethod.setRequestHeader("certFingerprint","xxxxx");        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);        //  Set the request body        Map<String, Object> bodyMap = new HashMap<>();        // taskId The corresponding value is the task returned when creating the asynchronous task ID(taskId)        bodyMap.put("taskId", "taskId");        RequestEntity requestEntity = new StringRequestEntity(JSONObject.toJSONString(bodyMap),"application/json" ,"UTF-8");        postMethod.setRequestEntity(requestEntity);        HttpClient httpClient = new HttpClient();        int ret = httpClient.executeMethod(postMethod);        String rpsContent = postMethod.getResponseBodyAsString();        if (ret == 200) {            System.out.println(rpsContent);        } else {            System.out.println("callApi failed: ret =" + ret + " rsp=" + rpsContent);        }    }

In addition to the ability to synthesize songs , Audio editing service It also provides basic audio editing 、AI Dubbing accompaniment extraction 、 Spatial rendering 、 Rich audio processing capabilities such as variable sound and noise reduction , Provide excellent performance for developers around the world 、 Simple and easy to use 、 An open interface , Help developers easily and efficiently build application audio editing capabilities .

Learn more >>

visit Official website of Huawei developer Alliance
obtain Development guidance document
Huawei mobile service open source warehouse address :GitHubGitee

Pay attention to our , The first time to understand HMS Core Latest technical information ~

原网站

版权声明
本文为[HMS Core]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207271612411078.html