@sonoba/voice-client
v0.5.2
Published
Voice Pipeline SDK — WebSocket, VAD, audio playback
Downloads
974
Readme
@sonoba/voice-client
日本語特化 Voice Pipeline の Core SDK。LiveKit WebRTC 接続・クライアントサイド VAD(Silero)・音声再生をワンパッケージで提供します。
インストール
npm install @sonoba/voice-clientクイックスタート
import { SonobaVoiceClient } from '@sonoba/voice-client';
const client = new SonobaVoiceClient({
pipelineUrl: 'https://pipeline.example.com',
});
client.on('transcript:user', ({ text }) => console.log('あなた:', text));
// transcript:agent.text は **delta**(前回 emit からの差分)。表示時は streamId 単位で蓄積する。
client.on('transcript:agent', ({ text, isFinal, streamId }) => {
console.log('AI delta:', text, isFinal ? '(final)' : '');
});
client.on('status:change', (status) => console.log('状態:', status));
await client.connect();オプション
const client = new SonobaVoiceClient({
pipelineUrl: 'https://pipeline.example.com', // 必須: Pipeline Server の base URL
// --- VAD(Silero ONNX、デフォルト ON) ---
vad: true,
vadModelUrl: '/silero_vad.onnx',
vadOptions: {
activationThreshold: 0.5, // 平滑後 probability の閾値
smoothingAlpha: 0.35, // ExpFilter alpha、(0, 1]、低いほど平滑が強い
minSpeechMs: 200, // これより短い発話は drop(cough 除去)
minSilenceMs: 600, // この長さの無音で utterance 確定(日本語の間に最適化)
},
// --- バージイン ---
autoBargeIn: true, // TTS 再生中の発話で自動 bargeIn() を発火(デフォルト: true)
bargeInThreshold: 300, // 自動 barge-in までの持続発話 ms(デフォルト: 300)
vadCancelThreshold: 250, // これより短い発話は vad:cancel として扱う(デフォルト: 250)
// --- コールバック(コンストラクタで登録) ---
callbacks: {
'status:change': (status) => console.log(status),
'error': (err) => console.error(err),
},
});メソッド
| メソッド / プロパティ | 説明 |
|---------|------|
| connect(config?) | Pipeline Server からトークンを取得し LiveKit に接続。オプションで SessionConfig を渡せる |
| disconnect() | 切断、VAD・リモートオーディオ等のリソース解放 |
| setMuted(muted) | マイクのミュート切り替え |
| isMuted() | 現在のミュート状態を返す |
| sendText(text) | テキスト入力を text:input で送信 |
| bargeIn() | audio:barge_in をサーバーに送信(割り込み)。エージェント非再生中は no-op |
| setPipelineUrl(url) | 次回 connect() で使う Pipeline Server URL を更新 |
| getSessionId() | 現在のセッション ID を返す(未接続時は null) |
| playing | エージェントが TTS 再生中なら true(getter) |
| status | 現在の ConnectionStatus(getter) |
イベント一覧
client.on('status:change', (status) => {}); // 接続状態の変化
client.on('session:ack', (data) => {}); // session 受理(sessionId を含む)
client.on('transcript:user', ({ text }) => {}); // ユーザー発話の認識結果
client.on('transcript:agent', ({ text, isFinal, streamId }) => {}); // AI 返答 (delta)
client.on('audio:tts_start', (data) => {}); // TTS ストリーム開始(server 起点)
client.on('audio:tts_end', (data) => {}); // TTS ストリーム終了(server 起点)
client.on('audio:playback_end', (data) => {}); // ローカル再生バッファ消化完了(audio:tts_end とは独立、順序不定)
client.on('audio:binary', (data) => {}); // 生の音声フレーム(上級者向け)
client.on('vad:start', () => {}); // 発話開始検出
client.on('vad:end', () => {}); // 発話終了検出
client.on('vad:cancel', () => {}); // 短すぎる発話を misfire として破棄
client.on('mic:muted', (muted) => {}); // ミュート状態変化
client.on('error', (err) => {}); // エラー
client.on('custom', ({ type, data }) => {}); // 未知の server message を passthroughライセンス
MIT © sonoba
