@wq-hook/volcano-react 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +262 -2
- package/dist/index.d.ts +262 -2
- package/dist/index.js +774 -26
- package/dist/index.mjs +769 -26
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -179,7 +179,7 @@ declare function useVolcanoTTS({ ttsConfig, audioParams, }: UseTTSParams): {
|
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
interface TTSMetric {
|
|
182
|
-
name: 'tts_request' | 'tts_latency' | 'tts_cache_hit' | 'tts_error';
|
|
182
|
+
name: 'tts_request' | 'tts_latency' | 'tts_cache_hit' | 'tts_error' | 'tts_synthesis_finished';
|
|
183
183
|
labels: {
|
|
184
184
|
voice?: string;
|
|
185
185
|
speed?: number;
|
|
@@ -266,6 +266,266 @@ interface UseMessageTTSReturn {
|
|
|
266
266
|
|
|
267
267
|
declare function useMessageTTS({ ttsConfig, audioParams, autoPlay, metricsCollector, onPlayStart, onPlayPause, onPlayResume, onPlayEnd, onError, exclusive, fallbackVoice, visualization, }: UseMessageTTSParams): UseMessageTTSReturn;
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* 流式文本分段
|
|
271
|
+
*/
|
|
272
|
+
interface StreamTextSegment {
|
|
273
|
+
/** 分段索引 */
|
|
274
|
+
index: number;
|
|
275
|
+
/** 分段内容 */
|
|
276
|
+
content: string;
|
|
277
|
+
/** 分段长度 */
|
|
278
|
+
length: number;
|
|
279
|
+
/** 是否已发送 */
|
|
280
|
+
sent: boolean;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* 流式文本分段器配置
|
|
284
|
+
*/
|
|
285
|
+
interface StreamingSplitOptions {
|
|
286
|
+
/** 单段最大字符数(默认150) */
|
|
287
|
+
maxLength?: number;
|
|
288
|
+
/** 单段最小字符数(默认10) */
|
|
289
|
+
minLength?: number;
|
|
290
|
+
/** 分段完成回调 */
|
|
291
|
+
onSegmentComplete?: (segment: StreamTextSegment) => void;
|
|
292
|
+
/** 所有分段完成回调 */
|
|
293
|
+
onAllComplete?: (segments: StreamTextSegment[]) => void;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* useStreamTTS 参数
|
|
297
|
+
*/
|
|
298
|
+
interface UseStreamTTSParams {
|
|
299
|
+
/** TTS配置 */
|
|
300
|
+
ttsConfig: TTSConfig;
|
|
301
|
+
/** 音频参数 */
|
|
302
|
+
audioParams?: AudioParams;
|
|
303
|
+
/** 是否自动播放(默认:true) */
|
|
304
|
+
autoPlay?: boolean;
|
|
305
|
+
/** 指标收集器 */
|
|
306
|
+
metricsCollector?: MetricsCollector;
|
|
307
|
+
/** 播放开始回调 */
|
|
308
|
+
onPlayStart?: () => void;
|
|
309
|
+
/** 播放暂停回调 */
|
|
310
|
+
onPlayPause?: () => void;
|
|
311
|
+
/** 播放恢复回调 */
|
|
312
|
+
onPlayResume?: () => void;
|
|
313
|
+
/** 播放结束回调 */
|
|
314
|
+
onPlayEnd?: () => void;
|
|
315
|
+
/** 错误回调 */
|
|
316
|
+
onError?: (error: Error) => void;
|
|
317
|
+
/** 可视化配置 */
|
|
318
|
+
visualization?: VisualizationConfig;
|
|
319
|
+
/** 单段最大字符数(默认150) */
|
|
320
|
+
maxSegmentLength?: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* useStreamTTS 返回值
|
|
324
|
+
*/
|
|
325
|
+
interface UseStreamTTSReturn {
|
|
326
|
+
/** WebSocket 是否已连接 */
|
|
327
|
+
isConnected: boolean;
|
|
328
|
+
/** 会话是否已启动 */
|
|
329
|
+
isSessionStarted: boolean;
|
|
330
|
+
/** 是否正在合成 */
|
|
331
|
+
isSynthesizing: boolean;
|
|
332
|
+
/** 是否正在播放 */
|
|
333
|
+
isPlaying: boolean;
|
|
334
|
+
/** 是否暂停 */
|
|
335
|
+
isPaused: boolean;
|
|
336
|
+
/** 错误信息 */
|
|
337
|
+
error: string | null;
|
|
338
|
+
/** 累计的流式文本(原始,未格式化) */
|
|
339
|
+
streamText: string;
|
|
340
|
+
/** 播放进度(0-100) */
|
|
341
|
+
progress: number;
|
|
342
|
+
/** 建立 WebSocket 连接 */
|
|
343
|
+
connect: () => Promise<void>;
|
|
344
|
+
/** 接收流式文本块 */
|
|
345
|
+
onMessage: (chunk: string) => void;
|
|
346
|
+
/** 结束流式输入 */
|
|
347
|
+
finishStream: () => Promise<void>;
|
|
348
|
+
/** 暂停播放 */
|
|
349
|
+
pause: () => void;
|
|
350
|
+
/** 恢复播放 */
|
|
351
|
+
resume: () => void;
|
|
352
|
+
/** 停止(断开连接,清理资源) */
|
|
353
|
+
stop: () => void;
|
|
354
|
+
/** 跳转到指定进度 */
|
|
355
|
+
seek: (percentage: number) => void;
|
|
356
|
+
/** 获取频率数据 */
|
|
357
|
+
getFrequencyData: () => Uint8Array;
|
|
358
|
+
/** 获取时域数据 */
|
|
359
|
+
getTimeDomainData: () => Uint8Array;
|
|
360
|
+
/** 可视化数据 */
|
|
361
|
+
visualizationData: VisualizationData;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Session 音频缓存条目
|
|
365
|
+
*/
|
|
366
|
+
interface SessionAudioCacheEntry {
|
|
367
|
+
/** 原始流式文本 */
|
|
368
|
+
streamText: string;
|
|
369
|
+
/** 音频数据 */
|
|
370
|
+
audioBuffers: ArrayBuffer[];
|
|
371
|
+
/** 缓存时间 */
|
|
372
|
+
timestamp: number;
|
|
373
|
+
/** 音色 */
|
|
374
|
+
voice: string;
|
|
375
|
+
/** 语速 */
|
|
376
|
+
speed: number;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* 流式 TTS Hook
|
|
381
|
+
*
|
|
382
|
+
* 适用于 AI 对话实时语音合成场景:
|
|
383
|
+
* 1. connect() - 建立 WebSocket 连接
|
|
384
|
+
* 2. onMessage(chunk) - 接收 SSE 流式文本并实时分段合成
|
|
385
|
+
* 3. finishStream() - 结束流式输入,完成合成
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```tsx
|
|
389
|
+
* const { connect, onMessage, finishStream, isPlaying } = useStreamTTS({
|
|
390
|
+
* ttsConfig: { token, appid, resourceId },
|
|
391
|
+
* audioParams: { speaker: "zh_female_tianmei" },
|
|
392
|
+
* });
|
|
393
|
+
*
|
|
394
|
+
* // SSE 事件处理
|
|
395
|
+
* useEffect(() => {
|
|
396
|
+
* const eventSource = new EventSource("/api/chat");
|
|
397
|
+
* eventSource.onopen = () => connect();
|
|
398
|
+
* eventSource.onmessage = (e) => onMessage(e.data);
|
|
399
|
+
* eventSource.onerror = async () => {
|
|
400
|
+
* await finishStream();
|
|
401
|
+
* eventSource.close();
|
|
402
|
+
* };
|
|
403
|
+
* }, []);
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
declare function useStreamTTS({ ttsConfig, audioParams, autoPlay, metricsCollector, onPlayStart, onPlayPause, onPlayResume, onPlayEnd, onError, visualization, maxSegmentLength, }: UseStreamTTSParams): UseStreamTTSReturn;
|
|
407
|
+
/**
|
|
408
|
+
* 获取 Session 音频缓存(供 useMessageTTS 使用)
|
|
409
|
+
* @param instanceId - 实例 ID
|
|
410
|
+
*/
|
|
411
|
+
declare function getSessionAudioCache(instanceId: string): SessionAudioCacheEntry | undefined;
|
|
412
|
+
/**
|
|
413
|
+
* 清除 Session 音频缓存
|
|
414
|
+
* @param instanceId - 实例 ID
|
|
415
|
+
*/
|
|
416
|
+
declare function clearSessionAudioCache(instanceId: string): void;
|
|
417
|
+
/**
|
|
418
|
+
* 根据文本查找匹配的 Session 缓存
|
|
419
|
+
* @param streamText - 流式文本
|
|
420
|
+
* @param voice - 音色
|
|
421
|
+
* @param speed - 语速
|
|
422
|
+
*/
|
|
423
|
+
declare function findSessionCacheByText(streamText: string, voice: string, speed: number): SessionAudioCacheEntry | undefined;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 流式文本分段器
|
|
427
|
+
*
|
|
428
|
+
* 功能:
|
|
429
|
+
* - 接收流式文本输入(逐字符或逐 token)
|
|
430
|
+
* - 实时检测分段边界
|
|
431
|
+
* - 触发分段回调
|
|
432
|
+
*
|
|
433
|
+
* 分段规则:
|
|
434
|
+
* 1. 换行符 \n(立即分段,保持段落结构)
|
|
435
|
+
* 2. 字符数限制(智能拆分,优先在句子边界)
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```ts
|
|
439
|
+
* const splitter = new StreamingTextSplitter({
|
|
440
|
+
* maxLength: 150,
|
|
441
|
+
* onSegmentComplete: (segment) => {
|
|
442
|
+
* console.log('分段完成:', segment);
|
|
443
|
+
* }
|
|
444
|
+
* });
|
|
445
|
+
*
|
|
446
|
+
* // 流式输入
|
|
447
|
+
* splitter.onChunk('Hello');
|
|
448
|
+
* splitter.onChunk(' ');
|
|
449
|
+
* splitter.onChunk('World');
|
|
450
|
+
* splitter.onChunk('\n'); // 触发分段
|
|
451
|
+
* splitter.complete();
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
declare class StreamingTextSplitter {
|
|
455
|
+
/** 当前缓冲区 */
|
|
456
|
+
private buffer;
|
|
457
|
+
/** 分段索引计数器 */
|
|
458
|
+
private segmentIndex;
|
|
459
|
+
/** 已完成的分段列表 */
|
|
460
|
+
private segments;
|
|
461
|
+
/** 单段最大字符数 */
|
|
462
|
+
private readonly maxLength;
|
|
463
|
+
/** 单段最小字符数 */
|
|
464
|
+
private readonly minLength;
|
|
465
|
+
/** 分段完成回调 */
|
|
466
|
+
private readonly onSegmentComplete?;
|
|
467
|
+
/** 所有分段完成回调 */
|
|
468
|
+
private readonly onAllComplete?;
|
|
469
|
+
/** 是否已完成 */
|
|
470
|
+
private isCompleted;
|
|
471
|
+
constructor(options?: StreamingSplitOptions);
|
|
472
|
+
/**
|
|
473
|
+
* 接收流式文本块
|
|
474
|
+
* @param chunk - 文本块
|
|
475
|
+
*/
|
|
476
|
+
onChunk(chunk: string): void;
|
|
477
|
+
/**
|
|
478
|
+
* 检测分段边界
|
|
479
|
+
* @param chunk - 最新接收的文本块
|
|
480
|
+
* @returns 是否应该分段
|
|
481
|
+
*/
|
|
482
|
+
private detectBoundary;
|
|
483
|
+
/**
|
|
484
|
+
* 在句子边界强制拆分超长段落
|
|
485
|
+
*/
|
|
486
|
+
private forceSplitAtSentenceBoundary;
|
|
487
|
+
/**
|
|
488
|
+
* 使用指定缓冲区内容刷新为分段
|
|
489
|
+
* @param bufferToFlush - 要分段的缓冲区内容
|
|
490
|
+
*/
|
|
491
|
+
private flushSegmentWithBuffer;
|
|
492
|
+
/**
|
|
493
|
+
* 刷新当前缓冲区为分段
|
|
494
|
+
*/
|
|
495
|
+
private flushSegment;
|
|
496
|
+
/**
|
|
497
|
+
* 拆分超长分段
|
|
498
|
+
* @param segment - 超长的分段
|
|
499
|
+
* @returns 拆分后的分段数组
|
|
500
|
+
*/
|
|
501
|
+
private splitLongSegment;
|
|
502
|
+
/**
|
|
503
|
+
* 完成流式输入
|
|
504
|
+
* 处理剩余的缓冲区内容
|
|
505
|
+
*/
|
|
506
|
+
complete(): void;
|
|
507
|
+
/**
|
|
508
|
+
* 重置分段器状态
|
|
509
|
+
*/
|
|
510
|
+
reset(): void;
|
|
511
|
+
/**
|
|
512
|
+
* 获取当前缓冲区内容
|
|
513
|
+
*/
|
|
514
|
+
getBuffer(): string;
|
|
515
|
+
/**
|
|
516
|
+
* 获取已分段的列表
|
|
517
|
+
*/
|
|
518
|
+
getSegments(): StreamTextSegment[];
|
|
519
|
+
/**
|
|
520
|
+
* 获取统计信息
|
|
521
|
+
*/
|
|
522
|
+
getStats(): {
|
|
523
|
+
bufferLength: number;
|
|
524
|
+
segmentCount: number;
|
|
525
|
+
totalChars: number;
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
269
529
|
/**
|
|
270
530
|
* TextSplitter 类型声明
|
|
271
531
|
*
|
|
@@ -355,4 +615,4 @@ interface AudioProgressBarProps {
|
|
|
355
615
|
|
|
356
616
|
declare const AudioProgressBar: React$1.FC<AudioProgressBarProps>;
|
|
357
617
|
|
|
358
|
-
export { type ASRHookParams, type ASRHookReturn, type ASRStatus, type AudioParams, AudioProgressBar, type AudioProgressBarProps, AudioWaveVisualizer, type AudioWaveVisualizerProps, type AuthParams, type ConnectionStatus, type MessageStatus, type TTSConfig, type TTSInstance, type TTSMessage, type TextSegment, type UseMessageTTSParams, type UseMessageTTSReturn, type UseTTSParams, type UseVTSOptions, type UseVTSReturn, type VisualizationConfig, type VisualizationData, splitTextByDelimiters, useMessageTTS, useVolcanoASR, useVolcanoTTS };
|
|
618
|
+
export { type ASRHookParams, type ASRHookReturn, type ASRStatus, type AudioParams, AudioProgressBar, type AudioProgressBarProps, AudioWaveVisualizer, type AudioWaveVisualizerProps, type AuthParams, type ConnectionStatus, type MessageStatus, type SessionAudioCacheEntry, type StreamTextSegment, type StreamingSplitOptions, StreamingTextSplitter, type TTSConfig, type TTSInstance, type TTSMessage, type TextSegment, type UseMessageTTSParams, type UseMessageTTSReturn, type UseStreamTTSParams, type UseStreamTTSReturn, type UseTTSParams, type UseVTSOptions, type UseVTSReturn, type VisualizationConfig, type VisualizationData, clearSessionAudioCache, findSessionCacheByText, getSessionAudioCache, splitTextByDelimiters, useMessageTTS, useStreamTTS, useVolcanoASR, useVolcanoTTS };
|
package/dist/index.d.ts
CHANGED
|
@@ -179,7 +179,7 @@ declare function useVolcanoTTS({ ttsConfig, audioParams, }: UseTTSParams): {
|
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
interface TTSMetric {
|
|
182
|
-
name: 'tts_request' | 'tts_latency' | 'tts_cache_hit' | 'tts_error';
|
|
182
|
+
name: 'tts_request' | 'tts_latency' | 'tts_cache_hit' | 'tts_error' | 'tts_synthesis_finished';
|
|
183
183
|
labels: {
|
|
184
184
|
voice?: string;
|
|
185
185
|
speed?: number;
|
|
@@ -266,6 +266,266 @@ interface UseMessageTTSReturn {
|
|
|
266
266
|
|
|
267
267
|
declare function useMessageTTS({ ttsConfig, audioParams, autoPlay, metricsCollector, onPlayStart, onPlayPause, onPlayResume, onPlayEnd, onError, exclusive, fallbackVoice, visualization, }: UseMessageTTSParams): UseMessageTTSReturn;
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* 流式文本分段
|
|
271
|
+
*/
|
|
272
|
+
interface StreamTextSegment {
|
|
273
|
+
/** 分段索引 */
|
|
274
|
+
index: number;
|
|
275
|
+
/** 分段内容 */
|
|
276
|
+
content: string;
|
|
277
|
+
/** 分段长度 */
|
|
278
|
+
length: number;
|
|
279
|
+
/** 是否已发送 */
|
|
280
|
+
sent: boolean;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* 流式文本分段器配置
|
|
284
|
+
*/
|
|
285
|
+
interface StreamingSplitOptions {
|
|
286
|
+
/** 单段最大字符数(默认150) */
|
|
287
|
+
maxLength?: number;
|
|
288
|
+
/** 单段最小字符数(默认10) */
|
|
289
|
+
minLength?: number;
|
|
290
|
+
/** 分段完成回调 */
|
|
291
|
+
onSegmentComplete?: (segment: StreamTextSegment) => void;
|
|
292
|
+
/** 所有分段完成回调 */
|
|
293
|
+
onAllComplete?: (segments: StreamTextSegment[]) => void;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* useStreamTTS 参数
|
|
297
|
+
*/
|
|
298
|
+
interface UseStreamTTSParams {
|
|
299
|
+
/** TTS配置 */
|
|
300
|
+
ttsConfig: TTSConfig;
|
|
301
|
+
/** 音频参数 */
|
|
302
|
+
audioParams?: AudioParams;
|
|
303
|
+
/** 是否自动播放(默认:true) */
|
|
304
|
+
autoPlay?: boolean;
|
|
305
|
+
/** 指标收集器 */
|
|
306
|
+
metricsCollector?: MetricsCollector;
|
|
307
|
+
/** 播放开始回调 */
|
|
308
|
+
onPlayStart?: () => void;
|
|
309
|
+
/** 播放暂停回调 */
|
|
310
|
+
onPlayPause?: () => void;
|
|
311
|
+
/** 播放恢复回调 */
|
|
312
|
+
onPlayResume?: () => void;
|
|
313
|
+
/** 播放结束回调 */
|
|
314
|
+
onPlayEnd?: () => void;
|
|
315
|
+
/** 错误回调 */
|
|
316
|
+
onError?: (error: Error) => void;
|
|
317
|
+
/** 可视化配置 */
|
|
318
|
+
visualization?: VisualizationConfig;
|
|
319
|
+
/** 单段最大字符数(默认150) */
|
|
320
|
+
maxSegmentLength?: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* useStreamTTS 返回值
|
|
324
|
+
*/
|
|
325
|
+
interface UseStreamTTSReturn {
|
|
326
|
+
/** WebSocket 是否已连接 */
|
|
327
|
+
isConnected: boolean;
|
|
328
|
+
/** 会话是否已启动 */
|
|
329
|
+
isSessionStarted: boolean;
|
|
330
|
+
/** 是否正在合成 */
|
|
331
|
+
isSynthesizing: boolean;
|
|
332
|
+
/** 是否正在播放 */
|
|
333
|
+
isPlaying: boolean;
|
|
334
|
+
/** 是否暂停 */
|
|
335
|
+
isPaused: boolean;
|
|
336
|
+
/** 错误信息 */
|
|
337
|
+
error: string | null;
|
|
338
|
+
/** 累计的流式文本(原始,未格式化) */
|
|
339
|
+
streamText: string;
|
|
340
|
+
/** 播放进度(0-100) */
|
|
341
|
+
progress: number;
|
|
342
|
+
/** 建立 WebSocket 连接 */
|
|
343
|
+
connect: () => Promise<void>;
|
|
344
|
+
/** 接收流式文本块 */
|
|
345
|
+
onMessage: (chunk: string) => void;
|
|
346
|
+
/** 结束流式输入 */
|
|
347
|
+
finishStream: () => Promise<void>;
|
|
348
|
+
/** 暂停播放 */
|
|
349
|
+
pause: () => void;
|
|
350
|
+
/** 恢复播放 */
|
|
351
|
+
resume: () => void;
|
|
352
|
+
/** 停止(断开连接,清理资源) */
|
|
353
|
+
stop: () => void;
|
|
354
|
+
/** 跳转到指定进度 */
|
|
355
|
+
seek: (percentage: number) => void;
|
|
356
|
+
/** 获取频率数据 */
|
|
357
|
+
getFrequencyData: () => Uint8Array;
|
|
358
|
+
/** 获取时域数据 */
|
|
359
|
+
getTimeDomainData: () => Uint8Array;
|
|
360
|
+
/** 可视化数据 */
|
|
361
|
+
visualizationData: VisualizationData;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Session 音频缓存条目
|
|
365
|
+
*/
|
|
366
|
+
interface SessionAudioCacheEntry {
|
|
367
|
+
/** 原始流式文本 */
|
|
368
|
+
streamText: string;
|
|
369
|
+
/** 音频数据 */
|
|
370
|
+
audioBuffers: ArrayBuffer[];
|
|
371
|
+
/** 缓存时间 */
|
|
372
|
+
timestamp: number;
|
|
373
|
+
/** 音色 */
|
|
374
|
+
voice: string;
|
|
375
|
+
/** 语速 */
|
|
376
|
+
speed: number;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* 流式 TTS Hook
|
|
381
|
+
*
|
|
382
|
+
* 适用于 AI 对话实时语音合成场景:
|
|
383
|
+
* 1. connect() - 建立 WebSocket 连接
|
|
384
|
+
* 2. onMessage(chunk) - 接收 SSE 流式文本并实时分段合成
|
|
385
|
+
* 3. finishStream() - 结束流式输入,完成合成
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```tsx
|
|
389
|
+
* const { connect, onMessage, finishStream, isPlaying } = useStreamTTS({
|
|
390
|
+
* ttsConfig: { token, appid, resourceId },
|
|
391
|
+
* audioParams: { speaker: "zh_female_tianmei" },
|
|
392
|
+
* });
|
|
393
|
+
*
|
|
394
|
+
* // SSE 事件处理
|
|
395
|
+
* useEffect(() => {
|
|
396
|
+
* const eventSource = new EventSource("/api/chat");
|
|
397
|
+
* eventSource.onopen = () => connect();
|
|
398
|
+
* eventSource.onmessage = (e) => onMessage(e.data);
|
|
399
|
+
* eventSource.onerror = async () => {
|
|
400
|
+
* await finishStream();
|
|
401
|
+
* eventSource.close();
|
|
402
|
+
* };
|
|
403
|
+
* }, []);
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
declare function useStreamTTS({ ttsConfig, audioParams, autoPlay, metricsCollector, onPlayStart, onPlayPause, onPlayResume, onPlayEnd, onError, visualization, maxSegmentLength, }: UseStreamTTSParams): UseStreamTTSReturn;
|
|
407
|
+
/**
|
|
408
|
+
* 获取 Session 音频缓存(供 useMessageTTS 使用)
|
|
409
|
+
* @param instanceId - 实例 ID
|
|
410
|
+
*/
|
|
411
|
+
declare function getSessionAudioCache(instanceId: string): SessionAudioCacheEntry | undefined;
|
|
412
|
+
/**
|
|
413
|
+
* 清除 Session 音频缓存
|
|
414
|
+
* @param instanceId - 实例 ID
|
|
415
|
+
*/
|
|
416
|
+
declare function clearSessionAudioCache(instanceId: string): void;
|
|
417
|
+
/**
|
|
418
|
+
* 根据文本查找匹配的 Session 缓存
|
|
419
|
+
* @param streamText - 流式文本
|
|
420
|
+
* @param voice - 音色
|
|
421
|
+
* @param speed - 语速
|
|
422
|
+
*/
|
|
423
|
+
declare function findSessionCacheByText(streamText: string, voice: string, speed: number): SessionAudioCacheEntry | undefined;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 流式文本分段器
|
|
427
|
+
*
|
|
428
|
+
* 功能:
|
|
429
|
+
* - 接收流式文本输入(逐字符或逐 token)
|
|
430
|
+
* - 实时检测分段边界
|
|
431
|
+
* - 触发分段回调
|
|
432
|
+
*
|
|
433
|
+
* 分段规则:
|
|
434
|
+
* 1. 换行符 \n(立即分段,保持段落结构)
|
|
435
|
+
* 2. 字符数限制(智能拆分,优先在句子边界)
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```ts
|
|
439
|
+
* const splitter = new StreamingTextSplitter({
|
|
440
|
+
* maxLength: 150,
|
|
441
|
+
* onSegmentComplete: (segment) => {
|
|
442
|
+
* console.log('分段完成:', segment);
|
|
443
|
+
* }
|
|
444
|
+
* });
|
|
445
|
+
*
|
|
446
|
+
* // 流式输入
|
|
447
|
+
* splitter.onChunk('Hello');
|
|
448
|
+
* splitter.onChunk(' ');
|
|
449
|
+
* splitter.onChunk('World');
|
|
450
|
+
* splitter.onChunk('\n'); // 触发分段
|
|
451
|
+
* splitter.complete();
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
declare class StreamingTextSplitter {
|
|
455
|
+
/** 当前缓冲区 */
|
|
456
|
+
private buffer;
|
|
457
|
+
/** 分段索引计数器 */
|
|
458
|
+
private segmentIndex;
|
|
459
|
+
/** 已完成的分段列表 */
|
|
460
|
+
private segments;
|
|
461
|
+
/** 单段最大字符数 */
|
|
462
|
+
private readonly maxLength;
|
|
463
|
+
/** 单段最小字符数 */
|
|
464
|
+
private readonly minLength;
|
|
465
|
+
/** 分段完成回调 */
|
|
466
|
+
private readonly onSegmentComplete?;
|
|
467
|
+
/** 所有分段完成回调 */
|
|
468
|
+
private readonly onAllComplete?;
|
|
469
|
+
/** 是否已完成 */
|
|
470
|
+
private isCompleted;
|
|
471
|
+
constructor(options?: StreamingSplitOptions);
|
|
472
|
+
/**
|
|
473
|
+
* 接收流式文本块
|
|
474
|
+
* @param chunk - 文本块
|
|
475
|
+
*/
|
|
476
|
+
onChunk(chunk: string): void;
|
|
477
|
+
/**
|
|
478
|
+
* 检测分段边界
|
|
479
|
+
* @param chunk - 最新接收的文本块
|
|
480
|
+
* @returns 是否应该分段
|
|
481
|
+
*/
|
|
482
|
+
private detectBoundary;
|
|
483
|
+
/**
|
|
484
|
+
* 在句子边界强制拆分超长段落
|
|
485
|
+
*/
|
|
486
|
+
private forceSplitAtSentenceBoundary;
|
|
487
|
+
/**
|
|
488
|
+
* 使用指定缓冲区内容刷新为分段
|
|
489
|
+
* @param bufferToFlush - 要分段的缓冲区内容
|
|
490
|
+
*/
|
|
491
|
+
private flushSegmentWithBuffer;
|
|
492
|
+
/**
|
|
493
|
+
* 刷新当前缓冲区为分段
|
|
494
|
+
*/
|
|
495
|
+
private flushSegment;
|
|
496
|
+
/**
|
|
497
|
+
* 拆分超长分段
|
|
498
|
+
* @param segment - 超长的分段
|
|
499
|
+
* @returns 拆分后的分段数组
|
|
500
|
+
*/
|
|
501
|
+
private splitLongSegment;
|
|
502
|
+
/**
|
|
503
|
+
* 完成流式输入
|
|
504
|
+
* 处理剩余的缓冲区内容
|
|
505
|
+
*/
|
|
506
|
+
complete(): void;
|
|
507
|
+
/**
|
|
508
|
+
* 重置分段器状态
|
|
509
|
+
*/
|
|
510
|
+
reset(): void;
|
|
511
|
+
/**
|
|
512
|
+
* 获取当前缓冲区内容
|
|
513
|
+
*/
|
|
514
|
+
getBuffer(): string;
|
|
515
|
+
/**
|
|
516
|
+
* 获取已分段的列表
|
|
517
|
+
*/
|
|
518
|
+
getSegments(): StreamTextSegment[];
|
|
519
|
+
/**
|
|
520
|
+
* 获取统计信息
|
|
521
|
+
*/
|
|
522
|
+
getStats(): {
|
|
523
|
+
bufferLength: number;
|
|
524
|
+
segmentCount: number;
|
|
525
|
+
totalChars: number;
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
269
529
|
/**
|
|
270
530
|
* TextSplitter 类型声明
|
|
271
531
|
*
|
|
@@ -355,4 +615,4 @@ interface AudioProgressBarProps {
|
|
|
355
615
|
|
|
356
616
|
declare const AudioProgressBar: React$1.FC<AudioProgressBarProps>;
|
|
357
617
|
|
|
358
|
-
export { type ASRHookParams, type ASRHookReturn, type ASRStatus, type AudioParams, AudioProgressBar, type AudioProgressBarProps, AudioWaveVisualizer, type AudioWaveVisualizerProps, type AuthParams, type ConnectionStatus, type MessageStatus, type TTSConfig, type TTSInstance, type TTSMessage, type TextSegment, type UseMessageTTSParams, type UseMessageTTSReturn, type UseTTSParams, type UseVTSOptions, type UseVTSReturn, type VisualizationConfig, type VisualizationData, splitTextByDelimiters, useMessageTTS, useVolcanoASR, useVolcanoTTS };
|
|
618
|
+
export { type ASRHookParams, type ASRHookReturn, type ASRStatus, type AudioParams, AudioProgressBar, type AudioProgressBarProps, AudioWaveVisualizer, type AudioWaveVisualizerProps, type AuthParams, type ConnectionStatus, type MessageStatus, type SessionAudioCacheEntry, type StreamTextSegment, type StreamingSplitOptions, StreamingTextSplitter, type TTSConfig, type TTSInstance, type TTSMessage, type TextSegment, type UseMessageTTSParams, type UseMessageTTSReturn, type UseStreamTTSParams, type UseStreamTTSReturn, type UseTTSParams, type UseVTSOptions, type UseVTSReturn, type VisualizationConfig, type VisualizationData, clearSessionAudioCache, findSessionCacheByText, getSessionAudioCache, splitTextByDelimiters, useMessageTTS, useStreamTTS, useVolcanoASR, useVolcanoTTS };
|