Cool-Admin-Node
后台管理系统开发、Api接口开发
Cool-Admin-Node
后台管理系统开发、Api接口开发
Cool-Admin-Java
后台管理系统开发、Api接口开发
Cool-Admin-Vue
后台管理系统开发前端
Cool Uni
移动端基于 uni-app 的跨端开发框架
Cool Team(即将推出)
Ai多智能体团队协作完成任务
技术指导
提供专业的技术指导服务
定制开发
外包,承接各类软件开发
低价云服务器
特价、低价的云服务器
发布帖子
寻求帮助或分享知识
发布插件
分享您的插件
Cool-Admin-Node
Cool-Admin-Java
Cool-Admin-Vue
Cool Uni
Cool Team(即将推出)
技术指导
定制开发
低价云服务器
发布帖子
发布插件
实时语音识别与合成
实时语音与识别与合成,基于阿里云的智能语音交互,可以很方便地使用该能力
调用插件的时候需要用到标识,标识是唯一的,不能重复,建议使用英文,不要使用中文,对应插件 plugin.json
中的 key
字段
{
"accessKeyId": "阿里云的accessKeyId",
"accessKeySecret": "阿里云的accessKeySecret",
"appkey": "项目的对应的appkey,可以在智能语音交互控制台获得",
"expired": 120
}
下面是插件提供的一些方法
获得 Token
/**
* 获得Token
*/
async getToken()
语音合成
/** 语音合成
* @param content 文本内容
* @param callback 回调函数
* @param params 参数
*/
async textToSpeech(
content: string,
callback: (data: { event: string; buffer: Buffer }) => void,
params?: {
text?: string;
voice?: string;
format?: string;
sample_rate?: number;
volume?: number;
speech_rate?: number;
pitch_rate?: number;
enable_subtitle?: boolean;
platform?: string;
}
)
语音识别
/**
* 语音识别
* @param buffer 语音数据
* @param taskId 任务ID
* @param stop 是否停止
* @param callback 回调函数
* @param params 参数
*/
async speechToText(
buffer: Buffer,
callback: (data: { event: string; data: any }) => void,
taskId: string,
stop = false,
params?: {
format?: string;
sample_rate?: number;
enable_intermediate_result?: boolean;
enable_punctuation_predition?: boolean;
enable_inverse_text_normalization?: boolean;
}
)
@Inject()
pluginService: PluginService;
// 获取插件实例
const instance = await this.pluginService.getInstance('voice-ali');
// 语音合成
instance.textToSpeech(
"COOL为开发者而生",
(data) => {
console.log(data);
}
);
// 语音识别
let audioStream = fs.createReadStream("test.pcm", {
encoding: "binary",
highWaterMark: 1024,
});
audioStream.on("data", async (chunk) => {
instance.speechToText(
Buffer.from(chunk, "binary"),
(data) => {
console.log(data);
},
"xxx"
);
});