更新记录
1.0.0(2026-06-06)
语音合成语音播放
平台兼容性
uni-app(4.75)
| Vue2 |
Vue2插件版本 |
Vue3 |
Vue3插件版本 |
Chrome |
Safari |
app-vue |
app-vue插件版本 |
app-nvue |
Android |
Android插件版本 |
iOS |
鸿蒙 |
| √ |
1.0.0 |
√ |
1.0.0 |
× |
× |
√ |
1.0.0 |
× |
10.0 |
1.0.0 |
× |
× |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| × |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
yao-abb-cosy-voice
阿里云实时语音合成+语音播放
vue2代码示例
<view class="content">
<button type="primary" @click="startSynthesis">开始合成</button>
<button type="primary" @click="stopPlay">停止播放</button>
<CosyVoice ref="refCosyVoice" :cosyOption="cosyOption"></CosyVoice>
</view>
import CosyVoice from '@/uni_modules/yao-abb-cosy-voice/components/CosyVoice/CosyVoice.vue';
export default {
data() {
return {
cosyOption:{
voice:"longanhuan_v3", //合成音色 参考文档https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list
apiKey:"", //自己申请的key
model:"cosyvoice-v3-flash",//合成模型 参考文档https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list
volume:50,//音量[0, 100]
rate: 1,//语速[0.5, 2.0]
pitch: 1,//音调[0.5, 2.0]
enable_ssml: false,
language_hints:["zh","en","fr","de","ja","ko","ru","pt","th","id","vi"] //要合成的语言
},
textList:[
'古时候宋国有个农夫,',
'一天正在田里耕作,',
'忽然一只野兔慌慌张张狂奔过来,',
'一头撞在田边的老树桩上,',
'折断脖子当场死了。',
'农夫大喜,',
'丢下农具,',
'捡起兔子回家美美吃了一顿。',
'从这以后,',
'他再也不愿下地辛苦耕田,',
'天天守在树桩旁边,',
'等着再有兔子撞死在木桩上。',
'日子一天天过去,',
'田里的庄稼全都荒芜,',
'他再也没有捡到第二只兔子,',
'反倒成了宋国人的笑柄。'
]
}
},
methods:{
sendText(){
//开始合成
var i = 0;
var inter = setInterval(()=>{
//发送要合成的文本
this.$refs.refCosyVoice.send(this.textList[i]);
i++;
if(i == this.textList.length){
clearInterval(inter);
//结束语音合成(必须)
this.$refs.refCosyVoice.stopSend();
}
},300)
},
stopPlay(){
this.$refs.refCosyVoice.stopAudio();
},
startSynthesis(){
//初始化音频
this.$refs.refCosyVoice.createAudio();
this.$refs.refCosyVoice.connectSocket((res)=>{
if(res.message == "task-started"){
this.sendText();
}
if(res.message == "result-generated"){
//将获取到的的音频编码写入并输出
this.$refs.refCosyVoice.writeAudioData(res.base64);
}
});
}
},
components:{
CosyVoice
}
}
vue3代码示例
<view class="content">
<button type="primary" @click="startSynthesis">开始合成</button>
<button type="primary" @click="stopPlay">停止播放</button>
<CosyVoice ref="refCosyVoice" :cosyOption="cosyOption"></CosyVoice>
</view>
import CosyVoice from '@/uni_modules/yao-abb-cosy-voice/components/CosyVoice/CosyVoice.vue';
import {ref} from 'vue';
const refCosyVoice = ref(null);
const cosyOption = ref({
voice:"longanhuan_v3", //合成音色 参考文档https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list
apiKey:"", //自己申请的key
model:"cosyvoice-v3-flash",//合成模型 参考文档https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list
volume:50,//音量[0, 100]
rate: 1,//语速[0.5, 2.0]
pitch: 1,//音调[0.5, 2.0]
enable_ssml: false,
language_hints:["zh","en","fr","de","ja","ko","ru","pt","th","id","vi"] //要合成的语言
});
const textList = ref([
'古时候宋国有个农夫,',
'一天正在田里耕作,',
'忽然一只野兔慌慌张张狂奔过来,',
'一头撞在田边的老树桩上,',
'折断脖子当场死了。',
'农夫大喜,',
'丢下农具,',
'捡起兔子回家美美吃了一顿。',
'从这以后,',
'他再也不愿下地辛苦耕田,',
'天天守在树桩旁边,',
'等着再有兔子撞死在木桩上。',
'日子一天天过去,',
'田里的庄稼全都荒芜,',
'他再也没有捡到第二只兔子,',
'反倒成了宋国人的笑柄。'
]);
const sendText = () => {
//开始合成
var i = 0;
var inter = setInterval(()=>{
//发送要合成的文字
refCosyVoice.value.send(textList.value[i]);
i++;
if(i == textList.value.length){
clearInterval(inter);
//结束语音合成(必须)
refCosyVoice.value.stopSend();
}
},300)
}
const stopPlay = () => {
//停止播放
refCosyVoice.value.stopAudio();
}
const startSynthesis = () => {
//初始化音频
refCosyVoice.value.createAudio();
refCosyVoice.value.connectSocket((res)=>{
if(res.message == "task-started"){
sendText();
}
if(res.message == "result-generated"){
//将获取到的的音频编码写入并输出
refCosyVoice.value.writeAudioData(res.base64);
}
});
}