AI赋能音乐创作,人人都是音视频创作者

ai,音乐创作,人人,音视频,创作者 · 浏览次数 : 561

小编点评

**内容生成指南** **1.2.2查询异步任务状态** * 编写代码,获取指定异步任务的taskId。 * 使用`queryAsyncTaskInfo()`方法,获取该任务状态。 **1.2.3取消异步任务** * 编写代码,获取指定异步任务的taskId。 * 使用`cancelAsyncTask()`方法,取消该任务。 * 删除相应的任务数据。 **1.3.其他** * 代码中,示例值需要根据实际情况进行修改。 * 可以使用其他工具和库,进行代码生成。

正文

华为HMS Core音频编辑服务(Audio Editor Kit)依托自身AI技术的研发优势,上线全新的歌声合成音色及伴奏,给音视频创作者提供更多的创作可能。在短视频场景中,用户自定义歌词的歌声结合视频让用户感受到身临其境,自由表达自己的情绪;在虚拟偶像场景中,歌声合成功能赋予虚拟歌手们演唱风格各异的歌曲,带来创意无限。

HMS Core音频编辑服务歌声合成的AI Singer模型能力通过字级别输入歌词进行音素转换,就可以为用户创作音乐,也可预置曲目合成歌声。通过自研音高模型,让音高曲线在保持输入曲谱的音高精准度的同时改善自然度,更接近人的真实演唱。使用最新的生成式模型,带来更好的音色还原度、建模更多的演唱细节,同时高清声码器能够真实还原48k高清音质。

另外,用户通过自由调整颤音、滑音、呼吸音等功能,可根据情感需求调整歌声演唱技巧。当前歌声合成服务已开放了情流行女声、国风女声和民谣男声音色,未来会持续更新更多音色。

可点击试听音色效果:https://developer.huawei.com/consumer/cn/doc/development/Media-Guides/synthesis_timbre_audition-0000001336283673#section15944442132920?ha_source=hms1

华为HMS Core音频编辑服务(Audio Editor Kit)让机器“演唱”出真实度的歌声,仅需简单的集成获得,以下是开发者应用集成音频编辑服务歌声合成能力的具体步骤。

开发步骤

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信息,发送HTTPS POST调用同步接口(流式)。

示例代码(Java)如下所示:

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

请点击下载MusicXML文件,并上传:

     /**
     * 调用同步接口(流式)
     * @throws Exception IO异常
     */
    private static void syncTask() throws Exception {
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        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);
        configMap.put("wordDurationForceAlign", "false");
        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是要保存文件的路径(含文件名、PCM文件后缀)
                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());
        }
    }

使用预置曲目输入歌词:

   /**
     * 调用同步接口(流式)
     * @throws Exception IO异常
     */
    private static void syncTask() throws Exception {
        
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Object> configMap = new HashMap<>();
        String[] lyrics = {"跟随心跳的节拍", "感受自由的畅快", "把烦恼通通抛开", "我们一起嗨", "调整呼吸的节拍", "保持最好的状态", "奔向耀眼的未来", "哦康忙北北"};
        dataMap.put("lyrics", lyrics);
        dataMap.put("accompanimentId", "1");
        dataMap.put("isAutoFill", "false");
        dataMap.put("language", "chinese");
        configMap.put("type", 1);
        configMap.put("outputEncoderFormat", 0);
        configMap.put("wordDurationForceAlign", "false");
        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是要保存文件的路径(含文件名、PCM文件后缀)
                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());
        }
    }

注意:

上述代码中xxxxx对应的值请根据实际情况填写,具体取值请参见同步接口(流式)

2.2异步接口

2.2.1创建异步任务

通过access_token信息,发送HTTPS POST创建歌声合成异步任务。

示例代码(Java)如下所示:

其中requestUrl = "https://audioeditor-api-drcn.cloud.huawei.com/v1/audioeditor/gateway/ai/ttsing/async/task/create"。

请点击下载MusicXML文件,并上传:

     /**
     * 调用创建异步任务接口
     * @throws Exception IO异常
     */
    private static void creatAsyncTask() throws Exception {
        
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        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);
        configMap.put("wordDurationForceAlign", "false");
        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);
        }
    }

使用预置曲目输入歌词:

/**
     * 调用创建异步任务接口
     * @throws Exception IO异常
     */
    private static void creatAsyncTask() throws Exception {
        
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        postMethod.setRequestHeader("Authorization","Bearer " + accessToken);
        // 设置请求body
        Map<String, Object> bodyMap = new HashMap<>();
        Map<String, Object> dataMap = new HashMap<>();
        Map<String, Object> configMap = new HashMap<>();
        String[] lyrics = {"跟随心跳的节拍", "感受自由的畅快", "把烦恼通通抛开", "我们一起嗨", "调整呼吸的节拍", "保持最好的状态", "奔向耀眼的未来", "哦康忙北北"};
        dataMap.put("lyrics", lyrics);
        dataMap.put("accompanimentId", "1");
        dataMap.put("isAutoFill", "false");
        dataMap.put("language", "chinese");
        configMap.put("type", 1);
        configMap.put("outputEncoderFormat", 0);
        configMap.put("wordDurationForceAlign", "false");
        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);
        }
    }

注意:

上述代码中xxxxx对应的值请根据实际情况填写,具体取值请参见创建异步任务

2.2.2查询异步任务状态

用户创建异步任务后,可以通过调用该接口,获取任务处理状态等信息。任务处理完成后,会返回任务的下载地址,直接访问该地址即可下载文件。

通过access_token信息,和创建异步任务获取到的taskId发送HTTPS POST查询歌声合成异步任务状态。

示例代码(Java)如下所示:

其中requestUrl = "https://audioeditor-api-drcn.cloud.huawei.com/v1/audioeditor/gateway/ai/ttsing/async/task/status"。

  /**
     * 调用查询异步任务状态接口
     * @param taskId 创建异步任务获取的taskId
     * @throws Exception IO异常
     */
    private static void queryAsyncTaskInfo(String taskId) throws Exception {
        
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        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);
        }
    }

注意:

上述代码中xxxxx对应的值请根据实际情况填写,具体取值请参见查询异步任务状态

2.2.3取消异步任务

用户创建歌声合成异步任务后,可以通过调用此接口,取消指定异步任务并删除相应任务数据。

通过access_token信息和创建异步任务获取到的taskId,发送HTTPS POST取消异步任务。

示例代码(Java)如下所示:

其中requestUrl = "https://audioeditor-api-drcn.cloud.huawei.com/v1/audioeditor/gateway/ai/ttsing/async/task/cancel"。

  /**
     * 调用取消异步任务接口
     * @param taskId 创建异步任务获取的taskId
     * @throws Exception IO异常
     */
    private static void cancelAsyncTask(String taskId) throws Exception {
        
        // 设置请求header
        PostMethod postMethod = new PostMethod(requestUrl);
        // 设置文本类型(String),例:"application/json;charset=utf-8"
        postMethod.setRequestHeader("Content-Type", contentType);
        // 设置请求ID(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("X-Request-ID", requestId);
        // 设置App包名(String),例:"com.huawei.demo"
        postMethod.setRequestHeader("X-Package-Name", pacageName);
        // 设置App所在国家(String),例:"cn"
        postMethod.setRequestHeader("X-Country-Code", countryCode);
        // 设置App标识(String),例:"9af1aeda-531b-407a-80b4-65b40ef77bd6"
        postMethod.setRequestHeader("HMS-APPLICATION-ID", applicationId);
        // 设置证书指纹(String),例:"xxxxxxxxxxxxxxx"
        postMethod.setRequestHeader("certFingerprint", certFingerprint);
        // 设置动态获取的AccessToken(String)
        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);
        }
    }

注意:

上述代码中xxxxx对应的值请根据实际情况填写,具体取值请参见取消异步任务

除了歌声合成能力,音频编辑服务还提供音频基础剪辑、AI配音、音源分离、空间渲染、变声降噪等音频处理能力,更多信息可以访问官网获得

了解更多详情>>

访问华为开发者联盟官网
获取开发指导文档
华为移动服务开源仓库地址:GitHubGitee

关注我们,第一时间了解 HMS Core 最新技术资讯~

与AI赋能音乐创作,人人都是音视频创作者相似的内容:

AI赋能音乐创作,人人都是音视频创作者

华为HMS Core音频编辑服务(Audio Editor Kit)依托自身AI技术的研发优势,上线全新的歌声合成音色及伴奏,给音视频创作者提供更多的创作可能。在短视频场景中,用户自定义歌词的歌声结合视频让用户感受到身临其境,自由表达自己的情绪;在虚拟偶像场景中,歌声合成功能赋予虚拟歌手们演唱风格各

Karpor - 让 AI 全面赋能 Kubernetes!

Karpor 是一个现代化的 Kubernetes 可视化工具,核心特性聚焦在 搜索、 洞察、✨ AI ,目标是更方便快捷地连接平台和多集群,并用 AI 赋能 Kubernetes,从大量集群资源中提炼关键性的洞察提供给开发者和平台团队,帮助他们更好地理解集群并做出决策。

服装行业多模态算法个性化产品定制方案

本文是想利用AI赋能服装设计师,设计好看、好穿、好卖的服装,利用GPT+数据洞察、柔性快反+数智化供应链以及AIGC降低设计门槛和库存成本,快速反应市场时尚流行趋势,并进行落地实践

2024年,AI驱动测试管理工具会有哪些发展前景呢?

随着人工智能技术的日新月异,2024年的测试管理工具将迎来全新的发展机遇。AI赋能将助力测试管理工具实现前所未有的智能化升级,为软件研发团队带来革命性的变革。 一、什么是AI? 人工智能(AI)是一种能够模仿人类智能行为的技术。它通过模拟人类大脑的功能来解决复杂问题,具有学习、推理、感知、预测等能力

笔精墨妙,妙手丹青,微软开源可视化版本的ChatGPT:Visual ChatGPT,人工智能AI聊天发图片,Python3.10实现

说时迟那时快,微软第一时间发布开源库Visual ChatGPT,把 ChatGPT 的人工智能AI能力和Stable Diffusion以及ControlNet进行了整合。常常被互联网人挂在嘴边的“赋能”一词,几乎已经变成了笑话,但这回,微软玩了一次真真正正的AI“赋能”,彻底打通了人工智能“闭环

当线下门店遇上AI:华为云ModelBox携手佳华科技客流分析实践

摘要:在赋能传统门店客流经营数字化转型方面,华为云ModelBox与伙伴佳华科技合作推出的“华为云客流统计项目”,算是一次成功的探索。 本文分享自华为云社区《当线下门店遇上AI—华为云ModelBox携手佳华科技客流分析实践》,作者: 华为云社区精选 。 现如今,AI技术蓬勃发展,相关的理论技术和应

昇腾CANN:为你开启机器人开发的Buff 加成

摘要:昇腾AI提供了全栈技术和产品,构筑人工智能的算力基座,赋能上层应用 本文分享自华为云社区《昇腾CANN:为你开启机器人开发的Buff 加成》,作者:华为云社区精选 。 昇腾AI基础软硬件平台 人类在最近1万多年的发展中,经历了农耕时代、蒸汽机时代、电力时代、互联网时代,21世纪,进入了人工智能

搭载AI之后的表格插件又有哪些新的改变

摘要:本文由葡萄城技术团队于博客园原创并首发。葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。 在[《大火的ChatGPT与SpreadJS结合会有哪些意想不到的效果》](https://www.grapecity.com.cn/blogs/chatgpt-meets-spreadjs

现代数据平台要实现自助用数,要解决的三个问题

摘要:华为云FusionInsight MRS HetuEngine持续提升自助用数分析平台的可服务、易运维能力,基于AI技术持续提升对数据分析平台的智能化赋能水平,引领现代数据分析平台向专业化、智能化、易运维、高性能方向演进。 本文分享自华为云社区《现代数据平台要实现自助用数还要解决的三大问题》,

大模型重塑软件开发,华为云AI原生应用架构设计与实践分享

在ArchSummit全球架构师峰会2024上,华为云aPaaS平台首席架构师马会彬受邀出席,和技术爱好者分享AI原生应用引擎的架构与实践。