@wq-hook/volcano-sdk
v1.0.2
Published
Volcano Engine ASR & TTS Core SDK
Readme
@wq-hook/volcano-sdk
火山引擎 ASR & TTS 的核心 SDK,封装了 WebSocket 通信协议,适用于任何 JavaScript/TypeScript 环境。
安装
pnpm add @wq-hook/volcano-sdk功能
- WebsocketMSE: 封装了火山引擎 TTS 的 WebSocket 协议,支持流式接收音频数据。
- WebsocketRecordRTC: 封装了火山引擎 ASR 的 WebSocket 协议,支持实时麦克风录音并传输。
使用
TTS (语音合成)
import { WebsocketMSE } from '@wq-hook/volcano-sdk/tts';
const client = WebsocketMSE({ autoStartSession: true });
const url = client.start({
url: 'wss://openspeech.bytedance.com/api/v3/tts/bidirection?api_access_key=...',
config: {
// 火山引擎 TTS 配置参数
req_params: {
speaker: 'zh_female_vv_uranus_bigtts',
audio_params: {
format: 'mp3',
sample_rate: 24000
}
}
},
onMessage: (data) => {
// 接收到音频数据 (ArrayBuffer)
console.log('Received audio chunk', data.byteLength);
},
onSessionFinished: () => {
console.log('Synthesis finished');
}
});
// 发送文本
client.sendText('你好,世界');
client.finishSession();ASR (语音识别)
import { WebsocketRecordRTC } from '@wq-hook/volcano-sdk/asr';
const client = new WebsocketRecordRTC();
await client.start({
url: 'wss://openspeech.bytedance.com/api/v2/asr?appid=...',
onMessage: (text, isFinal) => {
console.log('Recognition result:', text, isFinal ? '(Final)' : '(Partial)');
}
});
// 停止录音
// client.stop();