MetaStudio数字人语音合成管理
引导式阅读
Java
MetaStudio数字人语音合成管理
作者
c***r
上架时间
2024-08-20 10:21:45

1、功能介绍

华为云提供了MetaStudio服务端SDK,您可以直接集成服务端SDK来调用MetaStudio的相关API,从而实现对MetaStudio的快速操作。

您将学到什么?

如何通过java版SDK来体验MetaStudio服务的数字人语音合成管理功能。

2、开发时序图

image

3、前置条件

  • 1、已注册华为帐号并开通华为云,已进行实名认证
  • 2、已具备开发环境 ,支持Java JDK 1.8及其以上版本。
  • 3、已获取账号对应的 Access Key(AK)和 Secret Access Key(SK)。请在华为云控制台“我的凭证 > 访问密钥”页面上创建和查看您的AK/SK。具体请参见 访问密钥
  • 4、已获取MetaStudio服务对应区域的项目ID,请在控制台“我的凭证 > API凭证”页面上查看项目ID。具体请参见API凭证

4、SDK获取和安装

您可以通过Maven配置所依赖的数字内容生产线SDK

<dependency> <groupId>com.huaweicloud.sdk</groupId> <artifactId>huaweicloud-sdk-metastudio</artifactId> <version>3.1.78</version> </dependency>

5、接口参数说明

关于接口参数的详细说明可参见: a.创建TTS试听任务

b.获取TTS试听文件

6、关键代码片段

6.1、创建TTS试听任务

/** * 创建TTS试听任务 * */ private static String createTtsAudition(MetaStudioClient client, String emotion) { logger.info("createTtsAudition start"); CreateTtsAuditionRequest request = new CreateTtsAuditionRequest() .withBody(new CreateTtsAuditionRequestBody() .withText("<your text>") .withEmotion(emotion)); String jobId = ""; try { CreateTtsAuditionResponse response = client.createTtsAudition(request); jobId = response.getJobId(); logger.info("createTtsAudition" + response.toString()); } catch (ClientRequestException e) { logger.error("createTtsAudition ClientRequestException" + e.getHttpStatusCode()); logger.error("createTtsAudition ClientRequestException" + e); } catch (ServerResponseException e) { logger.error("createTtsAudition ServerResponseException" + e.getHttpStatusCode()); logger.error("createTtsAudition ServerResponseException" + e.getMessage()); } return jobId; }

6.2、获取TTS试听文件

/** * 获取TTS试听文件 * */ private static void showTtsAuditionFile(MetaStudioClient client, String jobId) { logger.info("showTtsAuditionFile start"); ShowTtsAuditionFileRequest request = new ShowTtsAuditionFileRequest() .withJobId(jobId); try { ShowTtsAuditionFileResponse response = client.showTtsAuditionFile(request); logger.info("showTtsAuditionFile" + response.toString()); } catch (ClientRequestException e) { logger.error("showTtsAuditionFile ClientRequestException" + e.getHttpStatusCode()); logger.error("showTtsAuditionFile ClientRequestException" + e); } catch (ServerResponseException e) { logger.error("showTtsAuditionFile ServerResponseException" + e.getHttpStatusCode()); logger.error("showTtsAuditionFile ServerResponseException" + e.getMessage()); } }

7、运行结果

创建TTS试听任务

{ "job_id": "0ce83e***" }

获取TTS试听文件

{ "is-file-complete": false, "message": null, "files": [] }

8、参考

本示例的代码工程仅用于简单演示,实际开发过程中应严格遵循开发指南。访问以下链接可以获取详细信息:开发指南