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

HMS CoreAudio editing service (Audio Editor Kit) version 6.6.0 is launched, and the singing synthesis ability is added. Through lyrics and tunes, combined with different musical styles, the machine can also generate highly authentic songs. It supports the input of lyrics at the word level for phoneme conversion, and generates the song corresponding to the lyrics. It can flexibly adjust the pitch, glide, breath, vibrato and other detailed parameters to make the song more authentic.

Song synthesis services can be widely used in audio and video creative production, video entertainment, music education, virtual idols and other fields. For example, in music creation or short video creative editing, song synthesis service can help users create synthetic songs freely, making creation more colorful. In the field of virtual idols, through song synthesis, virtual people can have the ability to sing with specific timbres, making their images more vivid. In music games or singing education, singing synthesis can quickly generate standard reference sound, improve audio production efficiency and save labor costs.

Song synthesis effect

After hearing that the singing effect of singing synthesis is comparable to that of real people, can't wait to use it? The following is the specific integration method of singing synthesis. Come and try the integration yourself!

1. Development preparation

1.1 register as a developer

You need to work in Huawei before developing applications Developer alliance website Register as a developer on and complete real name authentication. For specific methods, see Account registration authentication.

1.2 project creation and Application

See also Create project , and then under the project Create app Complete the creation of the application. The special configuration is as follows:

Select platform: select Web.

1.3 open related services

To use the Audio Editor Kit service, you need to turn on the Audio Editor Kit service switch on AppGallery Connect. For specific steps, see Turn on the service switch.

2. Song synthesis function integration

2.1 synchronous interface (streaming)

2.1.1 get access_token authentication information

Use the client ID and corresponding key obtained from the developer alliance interface to send HTTPS POST request and obtain query access_token. For the method of obtaining, see Client mode(Client Credentials).

2.1.2 according to access_token call synchronization interface (streaming)

Access obtained through the above steps_ Token information, send HTTPS POST to call the synchronization interface (streaming).

The sample code (Java) is as follows:

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

/**
     * Call synchronization interface (streaming)
     * @param accessToken token obtained according to clientId and key
     * @throws Exception IO abnormal
     */
    private static void syncTask(String accessToken) throws Exception {
        // Set 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 request body
        Map<String, Object> bodyMap = new HashMap<>();
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Object> configMap = new HashMap<>();
        // filePath is the path of MusicXML file (including file name and 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 (including file name and 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 task

Through access_token information, send HTTPS POST to create voice synthesis asynchronous task.

  /**
     * Call to create asynchronous task interface
     * @param accessToken token obtained according to clientId and key
     * @throws Exception IO abnormal
     */
    private static void creatAsyncTask(String accessToken) throws Exception {
        // Set 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 request body
        Map<String, Object> bodyMap = new HashMap<>();
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Object> configMap = new HashMap<>();
        // filePath is the path of MusicXML file (including file name and 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 querying asynchronous task status

Through access_token information, send HTTPS POST to query the asynchronous task status of song synthesis.

  /**
     * Call the interface to query asynchronous task status
     * @param accessToken token obtained according to clientId and key
     * @throws Exception IO abnormal
     */
    private static void queryAsyncTaskInfo(String accessToken) throws Exception {
        // Set 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 request body
        Map<String, Object> bodyMap = new HashMap<>();
        // The value corresponding to taskId is the task ID (taskId) returned when creating an asynchronous task
        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

Through access_token information, send HTTPS POST to cancel the asynchronous task.

  /**
     * Call cancel asynchronous task interface
     * @param accessToken token obtained according to clientId and key
     * @throws Exception IO abnormal
     */
    private static void cancelAsuncTask(String accessToken) throws Exception {
        // Set 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 request body
        Map<String, Object> bodyMap = new HashMap<>();
        // The value corresponding to taskId is the task ID (taskId) returned when creating an asynchronous task
        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 rich audio processing capabilities such as audio basic editing, AI dubbing accompaniment extraction, spatial rendering, sound change and noise reduction, and provides global developers with excellent performance, easy-to-use, and open interfaces to 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: GitHub,Gitee

Follow us and learn the latest technical information of HMS Core at the first time~

Posted by nthomp on Wed, 03 Aug 2022 02:31:23 +0930