HMS Core audio editing service (Audio Editor Kit) version 6.6.0 is launched, adding the ability to synthesize singing voices. Through lyrics and tunes, combined with different genres, the machine can also generate highly realistic singing voices. Support word-level input lyrics for phoneme conversion, generate corresponding lyrics, and flexibly adjust detailed parameters such as pitch, glide, breath, and vibrato to make the singing more realistic.

The singing voice synthesis service can be widely used in audio and video creative production, audio and video entertainment, music education, virtual idols and other fields. For example, in music creation or creative editing of short videos, the singing voice synthesis service can help users freely create synthetic songs, making the creation more colorful. In the field of virtual idols, through the synthesis of singing voices, the virtual human can have the ability to sing with specific timbres and make its image more vivid. In music games or singing education, singing voice synthesis can quickly generate standard reference sounds, improve audio production efficiency and save labor costs.

vocal synthesis effect

After hearing the singing effect of singing voice synthesis that is comparable to that of a real person, can't wait to get started? The following is the specific integration method of singing voice synthesis. Come and try the integration for yourself!

1. Development preparation

1.1 Register as a developer

Before developing an app, you need to register as a developer on the HUAWEI Developer Alliance website and complete real-name authentication. For details, see Account Registration Authentication .

1.2 Create projects and applications

See Create a project , and then create an application under the project to 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 details, see Turning on the Service Switch .

2. Integration of singing voice synthesis function

2.1 Synchronous interface (streaming)

2.1.1 Obtain access_token authentication information

Use the client ID and corresponding key obtained from the developer alliance interface to send an HTTPS POST request to obtain the query access_token. For the acquisition method, see Client Credentials.

2.1.2 Call the synchronous interface (streaming) according to the access_token

Through the access_token information obtained in the above steps, send HTTPS POST to call the synchronous interface (streaming).

The sample code (Java) looks like this:

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

 /**
     * 调用同步接口(流式)
     * @param accessToken 根据clientId和密钥获取的token
     * @throws Exception IO异常
     */
    private static void syncTask(String accessToken) throws Exception {
        // 设置请求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);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Object> configMap = new HashMap<>();
        // filePath是MusicXML文件路径(含文件名、后缀)
        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是要保存文件的路径(含文件名、后缀)
                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

Through the access_token information, send HTTPS POST to create an asynchronous task of singing voice synthesis.

 /**
     * 调用创建异步任务接口
     * @param accessToken 根据clientId和密钥获取的token
     * @throws Exception IO异常
     */
    private static void creatAsyncTask(String accessToken) throws Exception {
        // 设置请求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);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Object> configMap = new HashMap<>();
        // filePath是MusicXML文件路径(含文件名、后缀)
        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 the status of asynchronous tasks

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

 /**
     * 调用查询异步任务状态接口
     * @param accessToken 根据clientId和密钥获取的token
     * @throws Exception IO异常
     */
    private static void queryAsyncTaskInfo(String accessToken) throws Exception {
        // 设置请求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);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        // taskId对应的值是创建异步任务时返回的任务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 Cancelling asynchronous tasks

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

 /**
     * 调用取消异步任务接口
     * @param accessToken 根据clientId和密钥获取的token
     * @throws Exception IO异常
     */
    private static void cancelAsuncTask(String accessToken) throws Exception {
        // 设置请求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);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        // taskId对应的值是创建异步任务时返回的任务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 singing voice synthesis capabilities, the audio editing service also provides rich audio processing capabilities such as basic audio editing, AI dubbing and accompaniment extraction, spatial rendering, voice changing and noise reduction, and provides global developers with high-performance, easy-to-use, and open interfaces. Help developers easily and efficiently build application audio editing capabilities.

Learn more details>>

Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee

Follow us to know the latest technical information of HMS Core for the first time~


HarmonyOS_SDK
596 声望11.7k 粉丝

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙应用,和开发者共同成长。