您的位置:首页 > 汽车 > 新车 > 上海哪家做网站关键词排名_大连网站推广_广告软文范例_网络营销公司网络推广

上海哪家做网站关键词排名_大连网站推广_广告软文范例_网络营销公司网络推广

2024/10/21 17:17:19 来源:https://blog.csdn.net/tianyaleixiaowu/article/details/142999128  浏览:    关键词:上海哪家做网站关键词排名_大连网站推广_广告软文范例_网络营销公司网络推广
上海哪家做网站关键词排名_大连网站推广_广告软文范例_网络营销公司网络推广

目前自定义TTS(文字转语音)技术已经比较成熟了,在很多场景都有运用。比较常见的多是一些系统预制好的音色,然后提供文字,即可出来这个音色出来的音频。

随着AI技术的不断发展,以及大家对自定义音色的产品诉求有所增加(譬如导航用自己的声音、用女神的声音、录别人一段音然后假装是这个人说话),现在也能比较容易的实现自己录一段音频,然后以此为模板,后续生成该音色的音频,即语音复刻功能。

下面我们用java实现一个语音复刻功能,其实比较简单,刻出来的音色也还算可以,听起来和本人相似度8成,好在是免费的。想要更相似的程度,就需要花钱了。

第一步 准备自己的录音文件

自行准备一个音频文件,可以用手机自己录个导出来,格式:WAV、MP3、M4A。时长就15秒左右即可。

然后将音频上传到阿里云oss中,得到一个oss地址,主要目的是获得一个可以公开访问的音频地址。也可以上传到别处,如果音频直接就是一个网络地址也可以。具体文档地址是:简介与SDK代码示例_智能语音交互(ISI)-阿里云帮助中心

然后开通阿里云智能语音服务,https://common-buy.aliyun.com/?spm=a2c4g.11186623.0.0.767c21f5AUyKdW&commodityCode=nlsService

开通之后你就可以复刻自己的音频了。

第二步 复刻自己音色的模型

<dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.6.4</version>
</dependency>
package org.example;import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;public class CosyVoiceDemo {//域名private static final String DOMAIN = "nls-slp.cn-shanghai.aliyuncs.com";// API版本private static final String API_VERSION = "2019-08-19";private static final IAcsClient client;static {// 创建DefaultAcsClient实例并初始化DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai",System.getenv("AK_ID"),System.getenv("AK_SECRET"));client = new DefaultAcsClient(profile);}public static void main(String[] args) throws InterruptedException {String voicePrefix = "your-voice-prefix";String url = "your-file-url";cosyClone(voicePrefix, url);//cosyList(voicePrefix);}private static void cosyList(String voicePrefix) {CommonRequest request = buildRequest("ListCosyVoice");request.putBodyParameter("VoicePrefix", voicePrefix);String response = sendRequest(request);System.out.println(response);}private static void cosyClone(String voicePrefix, String url) {CommonRequest cloneRequest = buildRequest("CosyVoiceClone");cloneRequest.putBodyParameter("VoicePrefix", voicePrefix);cloneRequest.putBodyParameter("Url", url);// 设定等待超时时间为15scloneRequest.setSysReadTimeout(15000);long startTime = System.currentTimeMillis();String response = sendRequest(cloneRequest);long endTime = System.currentTimeMillis();System.out.println(response);System.out.println("cost: "+ (endTime - startTime) + " 毫秒");}private static CommonRequest buildRequest(String popApiName) {CommonRequest request = new CommonRequest();request.setMethod(MethodType.POST);request.setDomain(DOMAIN);request.setVersion(API_VERSION);request.setAction(popApiName);request.setProtocol(ProtocolType.HTTPS);return request;}private static String sendRequest(CommonRequest request) {try {CommonResponse response = client.getCommonResponse(request);return response.getData();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return null;}
}

填入你在智能语音交互那里得到的AK、Secret,填入音频地址,然后调用cosyClone方法,该方法执行完毕后会得到一个你设置的前缀开通的模型名称,保存这个模型名,后续用TTS生成音频时就用这个模型名称。

第三步 根据模型生成任意文字的音频

复刻出自己音色的模型后,你就可以使用这个模型去生成任意文字的音频了。

文档地址是流式文本语音合成Java SDK_智能语音交互(ISI)-阿里云帮助中心

见最下面的代码FlowingSpeechSynthesizerDemo,里面修改synthesizer.setVoice("siyue")这里修改为你上一步复刻出来的模型名称,flowingTts.wav这个文件地址换成你要保存的地址。然后就可以运行后,就能得到一个复刻好的声音了,听一听吧。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com