当前位置:网站首页>虚拟偶像的歌声原来是这样生成的!
虚拟偶像的歌声原来是这样生成的!
2022-07-29 04:53:00 【nginx】

歌声合成服务可广泛应用于 音视频创意制作、影音娱乐、音乐教育、虚拟偶像等领域。例如,在音乐创作或短视频创意编辑时,歌声合成服务可以助力用户自由创作合成歌曲,使创作更加丰富多彩。在虚拟偶像领域,通过歌声合成,可以让虚拟人拥有特定音色歌唱能力,使其形象更生动。在音乐游戏或者歌唱教育中,歌声合成可以迅速生成标准参考声音,提高音频制作效率节省人力成本。
歌声合成效果
听到了歌声合成媲美真人的歌唱效果,是否迫不及待想上手使用了呢,以下是歌声合成的具体集成方法。快来亲自集成试试吧!
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"。
2.2异步接口
/*** 调用同步接口(流式)* @param accessToken 根据clientId和密钥获取的token* @throws Exception IO异常*/private static void syncTask(String accessToken) throws Exception {// 设置请求headerPostMethod 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);// 设置请求bodyMap<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.1创建异步任务
通过access_token信息,发送HTTPS POST创建歌声合成异步任务。
2.2.2查询异步任务状态
/*** 调用创建异步任务接口* @param accessToken 根据clientId和密钥获取的token* @throws Exception IO异常*/private static void creatAsyncTask(String accessToken) throws Exception {// 设置请求headerPostMethod 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);// 设置请求bodyMap<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);}}
通过access_token信息,发送HTTPS POST查询歌声合成异步任务状态。
2.2.3取消异步任务
/*** 调用查询异步任务状态接口* @param accessToken 根据clientId和密钥获取的token* @throws Exception IO异常*/private static void queryAsyncTaskInfo(String accessToken) throws Exception {// 设置请求headerPostMethod 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);// 设置请求bodyMap<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);}}
通过access_token信息,发送HTTPS POST取消异步任务。
除了歌声合成能力,音频编辑服务还提供音频基础编辑、AI配音伴奏提取、空间渲染、变声降噪等丰富的音频处理能力,为全球开发者提供性能优异、简单易用、开放性强的接口,帮助开发者轻松高效构建应用音频编辑能力。
/*** 调用取消异步任务接口* @param accessToken 根据clientId和密钥获取的token* @throws Exception IO异常*/private static void cancelAsuncTask(String accessToken) throws Exception {// 设置请求headerPostMethod 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);// 设置请求bodyMap<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);}}
了解更多详情>>
访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:GitHub、Gitee
关注我们,第一时间了解 HMS Core 最新技术资讯~
边栏推荐
- 使用更灵活、更方便的罗氏线圈
- 手机工作室网络如何组建?
- Connection database time zone setting
- STL source code analysis (Hou Jie) notes - STL overview
- How to avoid damage of oscilloscope current probe
- IOS interview preparation - Objective-C
- Data Lake: spark, a distributed open source processing engine
- WPS如何进行快速截屏?WPS快速截屏的方法
- 五个关联分析,领略数据分析师一大重要必会处理技能
- RecyclerView通过DPAD按键上下切换焦点 切换到界面外的控件时焦点会左右乱跳
猜你喜欢

Implementation of flutter gesture monitoring and Sketchpad

Torch.nn.crossentropyloss() details

数据湖:分布式开源处理引擎Spark

怎样监测微型的网站服务

Correct user dragging method

What are the core features of the digital transformation of state-owned construction enterprises?

如何避免示波器电流探头损坏

Delete blank pages in word documents

Command line interactive tools (latest version) inquirer practical tutorial

On prepayment of house purchase
随机推荐
Box horizontal vertical center layout (summary)
Un7.28: common commands of redis client.
WPS如何进行快速截屏?WPS快速截屏的方法
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
Opencv learning 1 (environment configuration)
Common current limiting methods
OpenCV环境搭建
Ethernet of network
Pycharm reports an error when connecting to the virtual machine database
After the spinning up installation is completed, use the tutorial to test whether it is successful. There are library "Glu" not found and 'from pyglet.gl import * error solutions
On prepayment of house purchase
1 sentence of code, get asp Net core binds multiple sources to the same class
2022杭电多校联赛第四场 题解
leetcode 763. Partition Labels 划分字母区间(中等)
Reveal installation configuration debugging
盒子水平垂直居中布局(总结)
[C language] PTA 7-47 binary leading zero
How to debug UDP port
Data Lake: spark, a distributed open source processing engine
Vscode configuration makefile compilation