当前位置:网站首页>虚拟偶像的歌声原来是这样生成的!
虚拟偶像的歌声原来是这样生成的!
2022-07-27 16:12:00 【HMS Core】
HMS Core音频编辑服务(Audio Editor Kit)6.6.0版本上线,新增歌声合成能力。通过歌词和曲调,结合不同的曲风让机器也能生成真实度极高的歌声。支持字级别输入歌词进行音素转换,生成对应歌词的歌声,可灵活调整音高、滑音、呼吸音、颤音等细节参数,让歌声更真实。

歌声合成服务可广泛应用于音视频创意制作、影音娱乐、音乐教育、虚拟偶像等领域。例如,在音乐创作或短视频创意编辑时,歌声合成服务可以助力用户自由创作合成歌曲,使创作更加丰富多彩。在虚拟偶像领域,通过歌声合成,可以让虚拟人拥有特定音色歌唱能力,使其形象更生动。在音乐游戏或者歌唱教育中,歌声合成可以迅速生成标准参考声音,提高音频制作效率节省人力成本。
听到了歌声合成媲美真人的歌唱效果,是否迫不及待想上手使用了呢,以下是歌声合成的具体集成方法。快来亲自集成试试吧!
1.开发准备
1.1注册成为开发者
在开发应用前需要在华为开发者联盟网站上注册成为开发者并完成实名认证,具体方法请参见帐号注册认证。
1.2创建项目及应用
参见创建项目,然后在项目下创建应用完成应用的创建,特殊配置如下:
选择平台:选择“Web”。
1.3打开相关服务
使用Audio Editor Kit服务需要您在AppGallery Connect上打开Audio Editor Kit服务开关,具体操作步骤请参见打开服务开关。
2.歌声合成功能集成
2.1同步接口(流式)
2.1.1获取access_token鉴权信息
使用开发者联盟界面获得的客户端ID以及对应密钥,发送HTTPS POST请求,获取查询access_token。获取方式请参见客户端模式(Client Credentials)。
2.1.2根据access_token调用同步接口(流式)
通过以上步骤获取的access_token信息,发送HTTPS POST调用同步接口(流式)。
示例代码(Java)如下所示:
其中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异步接口
2.2.1创建异步任务
通过access_token信息,发送HTTPS POST创建歌声合成异步任务。
/** * 调用创建异步任务接口 * @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查询异步任务状态
通过access_token信息,发送HTTPS POST查询歌声合成异步任务状态。
/** * 调用查询异步任务状态接口 * @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取消异步任务
通过access_token信息,发送HTTPS POST取消异步任务。
/** * 调用取消异步任务接口 * @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); } }除了歌声合成能力,音频编辑服务还提供音频基础编辑、AI配音伴奏提取、空间渲染、变声降噪等丰富的音频处理能力,为全球开发者提供性能优异、简单易用、开放性强的接口,帮助开发者轻松高效构建应用音频编辑能力。
了解更多详情>>
访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:GitHub、Gitee
关注我们,第一时间了解 HMS Core 最新技术资讯~
边栏推荐
猜你喜欢

2021.7.28 notes
![[MIT 6.S081] Lab 4: traps](/img/8b/ca4819f8b1cfc6233745a124790674.png)
[MIT 6.S081] Lab 4: traps

深度学习:GAT
![[mit 6.s081] LEC 1: introduction and examples notes](/img/5d/2fc4bde8eebbb22605d314b5292e05.png)
[mit 6.s081] LEC 1: introduction and examples notes

2021.7.30笔记 索引
![[mit 6.s081] LEC 9: interrupts notes](/img/b6/a8d39aa7ede4eb1c5a74e6d15b3b1c.png)
[mit 6.s081] LEC 9: interrupts notes

Let's move forward together, the 10th anniversary of Google play!

MySQL learns the relationship between Day2 Sorting Query / aggregation function / grouping query / paging query / constraint / multiple tables
![[mit 6.s081] LEC 4: page tables notes](/img/30/f1e12d669b656a0b14aa8c7b210085.png)
[mit 6.s081] LEC 4: page tables notes

Binary tree concept
随机推荐
[mit 6.s081] LEC 4: page tables notes
Installation and deployment of zabbix6.0
[MIT 6.S081] Lab 7: Multithreading
[MIT 6.S081] Lab 6: Copy-on-Write Fork for xv6
RSA encryption and decryption (compatible with wechat applet environment)
The first PCIe 5.0 SSD master of Jiangsu Huacun: TSMC 12NM process, mass production in 2020
[MIT 6.S081] Lab 9: file system
MySQL learning day3 multi table query / transaction / DCL
[mit 6.s081] LEC 9: interrupts notes
[MIT 6.S081] Lab 5: xv6 lazy page allocation
Deep learning: Gan case exercise -minst handwritten digits
搭建一个简单的知识问答系统
XML学习 Day1 : xml / Jsoup解析器 / selector选择器 /Xpath选择器
Deep learning - paper reading: action structural graph convolution network as-gcn
深度学习-论文阅读:动作结构性图卷积网络AS-GCN
@Datetimeformat received less than minutes and seconds, conversion times type exception
Is it difficult to operate email safely? COREMAIL joins hands with cloud store to create a new ecosystem of corporate email office!
2021.7.30 note index
MySQL学习 Day1 DDL、DML、DQL基础查询
Solution to invalid SQL Server connection to server