@lee-zg/melange 1.0.0 → 1.2.2
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/README.md +14 -14
- package/dist/chunk-3RM45M64.js +1637 -0
- package/dist/chunk-3RM45M64.js.map +1 -0
- package/dist/{chunk-Q7XG6YN6.cjs → chunk-BEY4UAYF.cjs} +3 -5
- package/dist/chunk-BEY4UAYF.cjs.map +1 -0
- package/dist/{chunk-ALBD5XC5.js → chunk-GXFWPL5M.js} +4 -8
- package/dist/chunk-GXFWPL5M.js.map +1 -0
- package/dist/{chunk-352XNR3C.js → chunk-GZBY4BUP.js} +7 -24
- package/dist/chunk-GZBY4BUP.js.map +1 -0
- package/dist/{chunk-2PXWQDZC.js → chunk-ILNGTDQ4.js} +3 -5
- package/dist/chunk-ILNGTDQ4.js.map +1 -0
- package/dist/{chunk-Q73NOVWX.cjs → chunk-JLBTZPBY.cjs} +7 -24
- package/dist/chunk-JLBTZPBY.cjs.map +1 -0
- package/dist/{chunk-ZT6HVG4G.cjs → chunk-UYJUSNDI.cjs} +4 -8
- package/dist/chunk-UYJUSNDI.cjs.map +1 -0
- package/dist/chunk-YZVCK6VZ.cjs +1646 -0
- package/dist/chunk-YZVCK6VZ.cjs.map +1 -0
- package/dist/core/index.cjs +23 -23
- package/dist/core/index.js +1 -1
- package/dist/fp/index.cjs +45 -45
- package/dist/fp/index.js +1 -1
- package/dist/index.cjs +147 -147
- package/dist/index.js +4 -4
- package/dist/plugins/index.cjs +9 -9
- package/dist/plugins/index.d.cts +287 -133
- package/dist/plugins/index.d.ts +287 -133
- package/dist/plugins/index.js +1 -1
- package/dist/utils/index.cjs +73 -73
- package/dist/utils/index.js +1 -1
- package/package.json +5 -2
- package/dist/chunk-2PXWQDZC.js.map +0 -1
- package/dist/chunk-352XNR3C.js.map +0 -1
- package/dist/chunk-ALBD5XC5.js.map +0 -1
- package/dist/chunk-O7K662J5.cjs +0 -842
- package/dist/chunk-O7K662J5.cjs.map +0 -1
- package/dist/chunk-Q73NOVWX.cjs.map +0 -1
- package/dist/chunk-Q7XG6YN6.cjs.map +0 -1
- package/dist/chunk-YGMBCZJQ.js +0 -833
- package/dist/chunk-YGMBCZJQ.js.map +0 -1
- package/dist/chunk-ZT6HVG4G.cjs.map +0 -1
package/dist/plugins/index.d.ts
CHANGED
|
@@ -300,51 +300,150 @@ interface CustomProviderConfig {
|
|
|
300
300
|
type ProviderConfig = AzureSpeechConfig | GoogleSpeechConfig | AWSSpeechConfig | CustomProviderConfig;
|
|
301
301
|
|
|
302
302
|
/**
|
|
303
|
-
* @fileoverview 语音合成 (TTS) 实现
|
|
303
|
+
* @fileoverview 语音合成 (TTS) 实现 - 商业级版本 v2.0
|
|
304
304
|
* @module melange/plugins/speech/synthesis
|
|
305
|
-
* @description
|
|
305
|
+
* @description 生产级 Web 语音合成插件
|
|
306
|
+
*
|
|
307
|
+
* 架构:
|
|
308
|
+
* [UI层] -> [SpeechSynthesizerImpl] -> [NativeStrategy / CloudStrategy]
|
|
309
|
+
* |
|
|
310
|
+
* +-> [音频核心]: AudioContext, 流式播放
|
|
311
|
+
* +-> [适配器]: AzureAdapter, GoogleAdapter, TencentAdapter...
|
|
312
|
+
*
|
|
313
|
+
* 功能特性:
|
|
314
|
+
* 1. 多模式: 支持原生 Web Speech API & 云端 TTS 服务
|
|
315
|
+
* 2. 状态机: IDLE -> LOADING -> SPEAKING -> PAUSED
|
|
316
|
+
* 3. 插件化: 内置 Azure/Google/AWS/讯飞/腾讯/百度/阿里 适配器
|
|
317
|
+
* 4. 核心: AudioContext 流式播放 + 音频队列管理
|
|
318
|
+
* 5. 兼容性: 多浏览器支持 + 自动降级处理
|
|
306
319
|
*/
|
|
307
320
|
|
|
308
321
|
/**
|
|
309
|
-
*
|
|
310
|
-
|
|
322
|
+
* 合成器状态枚举
|
|
323
|
+
*/
|
|
324
|
+
declare enum SynthesisStatus {
|
|
325
|
+
/** 空闲状态 */
|
|
326
|
+
IDLE = "IDLE",
|
|
327
|
+
/** 加载中(获取语音/准备中) */
|
|
328
|
+
LOADING = "LOADING",
|
|
329
|
+
/** 正在播放 */
|
|
330
|
+
SPEAKING = "SPEAKING",
|
|
331
|
+
/** 已暂停 */
|
|
332
|
+
PAUSED = "PAUSED"
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* 合成引擎模式
|
|
336
|
+
*/
|
|
337
|
+
type SynthesisEngineMode = 'native' | 'cloud' | 'auto';
|
|
338
|
+
/**
|
|
339
|
+
* 云端 TTS 音频格式
|
|
340
|
+
*/
|
|
341
|
+
type CloudAudioFormat = 'mp3' | 'wav' | 'ogg' | 'pcm';
|
|
342
|
+
/**
|
|
343
|
+
* 云端合成结果接口
|
|
344
|
+
*/
|
|
345
|
+
interface ISynthesisResult {
|
|
346
|
+
/** 音频数据 */
|
|
347
|
+
audioData: ArrayBuffer;
|
|
348
|
+
/** 音频格式 */
|
|
349
|
+
format: CloudAudioFormat;
|
|
350
|
+
/** 音频时长 (ms) */
|
|
351
|
+
duration?: number;
|
|
352
|
+
/** 原始响应数据 */
|
|
353
|
+
original?: unknown;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* 云端语音信息
|
|
357
|
+
*/
|
|
358
|
+
interface ICloudVoice {
|
|
359
|
+
/** 语音 ID */
|
|
360
|
+
id: string;
|
|
361
|
+
/** 语音名称 */
|
|
362
|
+
name: string;
|
|
363
|
+
/** 语言代码 */
|
|
364
|
+
lang: string;
|
|
365
|
+
/** 性别 */
|
|
366
|
+
gender?: 'male' | 'female' | 'neutral';
|
|
367
|
+
/** 提供商名称 */
|
|
368
|
+
provider: string;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* 高级合成配置
|
|
372
|
+
*/
|
|
373
|
+
interface IAdvancedSynthesisConfig extends SynthesisConfig {
|
|
374
|
+
/** 合成引擎模式 */
|
|
375
|
+
mode?: SynthesisEngineMode;
|
|
376
|
+
/** 云端适配器 */
|
|
377
|
+
cloudAdapter?: ICloudSynthesisAdapter;
|
|
378
|
+
/** 音频格式偏好 */
|
|
379
|
+
audioFormat?: CloudAudioFormat;
|
|
380
|
+
/** 是否启用 SSML */
|
|
381
|
+
enableSSML?: boolean;
|
|
382
|
+
/** 是否预加载音频 */
|
|
383
|
+
preload?: boolean;
|
|
384
|
+
/** 音频缓存大小 */
|
|
385
|
+
cacheSize?: number;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* 云端合成适配器接口
|
|
389
|
+
* 提供统一的第三方语音合成服务集成接口
|
|
390
|
+
*/
|
|
391
|
+
interface ICloudSynthesisAdapter {
|
|
392
|
+
/** 适配器名称 */
|
|
393
|
+
readonly name: string;
|
|
394
|
+
/**
|
|
395
|
+
* 合成语音
|
|
396
|
+
* @param text 要合成的文本
|
|
397
|
+
* @param config 合成配置
|
|
398
|
+
* @returns 合成结果(音频数据)
|
|
399
|
+
*/
|
|
400
|
+
synthesize(text: string, config?: IAdvancedSynthesisConfig): Promise<ISynthesisResult>;
|
|
401
|
+
/**
|
|
402
|
+
* 获取可用语音列表
|
|
403
|
+
* @returns 语音列表
|
|
404
|
+
*/
|
|
405
|
+
getVoices?(): Promise<ICloudVoice[]>;
|
|
406
|
+
/**
|
|
407
|
+
* 检查适配器是否可用
|
|
408
|
+
* @returns 是否可用
|
|
409
|
+
*/
|
|
410
|
+
isAvailable?(): boolean;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* 语音合成器实现
|
|
414
|
+
* 统一封装原生合成和云端合成
|
|
311
415
|
*/
|
|
312
416
|
declare class SpeechSynthesizerImpl implements SpeechSynthesizer {
|
|
417
|
+
private strategy;
|
|
418
|
+
private config;
|
|
313
419
|
private _currentProvider;
|
|
314
420
|
private _status;
|
|
315
|
-
private provider;
|
|
316
|
-
private config;
|
|
317
421
|
private eventHandlers;
|
|
318
|
-
private
|
|
319
|
-
/**
|
|
320
|
-
* 当前使用的提供商类型
|
|
321
|
-
*/
|
|
422
|
+
private customProviders;
|
|
322
423
|
get currentProvider(): SpeechProviderType;
|
|
424
|
+
get status(): SpeechServiceStatus;
|
|
323
425
|
/**
|
|
324
|
-
*
|
|
426
|
+
* 获取当前合成状态
|
|
325
427
|
*/
|
|
326
|
-
get
|
|
428
|
+
get synthesisStatus(): SynthesisStatus;
|
|
327
429
|
/**
|
|
328
430
|
* 初始化语音合成器
|
|
329
|
-
* @param config - 合成配置
|
|
330
431
|
*/
|
|
331
432
|
initialize(config?: SynthesisConfig): Promise<void>;
|
|
332
433
|
/**
|
|
333
|
-
*
|
|
434
|
+
* 初始化合成策略
|
|
334
435
|
*/
|
|
335
|
-
private
|
|
436
|
+
private initializeStrategy;
|
|
336
437
|
/**
|
|
337
|
-
*
|
|
438
|
+
* 转发策略事件
|
|
338
439
|
*/
|
|
339
|
-
private
|
|
440
|
+
private forwardStrategyEvents;
|
|
340
441
|
/**
|
|
341
442
|
* 获取可用语音列表
|
|
342
443
|
*/
|
|
343
444
|
getVoices(): Promise<VoiceInfo[]>;
|
|
344
445
|
/**
|
|
345
446
|
* 朗读文本
|
|
346
|
-
* @param text - 要朗读的文本
|
|
347
|
-
* @param config - 可选的合成配置
|
|
348
447
|
*/
|
|
349
448
|
speak(text: string, config?: SynthesisConfig): Promise<void>;
|
|
350
449
|
/**
|
|
@@ -385,10 +484,12 @@ declare class SpeechSynthesizerImpl implements SpeechSynthesizer {
|
|
|
385
484
|
dispose(): void;
|
|
386
485
|
/**
|
|
387
486
|
* 注册自定义提供商
|
|
388
|
-
* @param type - 提供商类型
|
|
389
|
-
* @param provider - 提供商实例
|
|
390
487
|
*/
|
|
391
488
|
registerProvider(type: SpeechProviderType, provider: SynthesisProvider): void;
|
|
489
|
+
/**
|
|
490
|
+
* 使用云端适配器
|
|
491
|
+
*/
|
|
492
|
+
useCloudAdapter(adapter: ICloudSynthesisAdapter): void;
|
|
392
493
|
}
|
|
393
494
|
/**
|
|
394
495
|
* 创建语音合成器实例
|
|
@@ -397,26 +498,23 @@ declare class SpeechSynthesizerImpl implements SpeechSynthesizer {
|
|
|
397
498
|
*
|
|
398
499
|
* @example
|
|
399
500
|
* ```typescript
|
|
400
|
-
* //
|
|
501
|
+
* // 使用原生合成
|
|
401
502
|
* const synthesizer = await createSpeechSynthesizer({
|
|
402
503
|
* lang: 'zh-CN',
|
|
403
504
|
* rate: 1.0,
|
|
404
|
-
* pitch: 1.0,
|
|
405
505
|
* });
|
|
406
506
|
*
|
|
407
|
-
* //
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* console.log('朗读完成');
|
|
507
|
+
* // 使用云端合成 (Azure)
|
|
508
|
+
* const azureAdapter = new AzureSynthesisAdapter('key', 'eastasia');
|
|
509
|
+
* const cloudSynthesizer = await createSpeechSynthesizer({
|
|
510
|
+
* mode: 'cloud',
|
|
511
|
+
* cloudAdapter: azureAdapter,
|
|
413
512
|
* });
|
|
414
513
|
*
|
|
415
|
-
*
|
|
416
|
-
* synthesizer.dispose();
|
|
514
|
+
* await synthesizer.speak('你好,世界!');
|
|
417
515
|
* ```
|
|
418
516
|
*/
|
|
419
|
-
declare function createSpeechSynthesizer(config?: SynthesisConfig): Promise<SpeechSynthesizer>;
|
|
517
|
+
declare function createSpeechSynthesizer(config?: SynthesisConfig | IAdvancedSynthesisConfig): Promise<SpeechSynthesizer>;
|
|
420
518
|
/**
|
|
421
519
|
* 检查当前环境是否支持语音合成
|
|
422
520
|
* @returns 是否支持语音合成
|
|
@@ -436,134 +534,192 @@ declare function isSpeechSynthesisSupported(): boolean;
|
|
|
436
534
|
* await speak('Hello World', { lang: 'en-US', rate: 0.8 });
|
|
437
535
|
* ```
|
|
438
536
|
*/
|
|
439
|
-
declare function speak(text: string, config?: SynthesisConfig): Promise<void>;
|
|
537
|
+
declare function speak(text: string, config?: SynthesisConfig | IAdvancedSynthesisConfig): Promise<void>;
|
|
440
538
|
|
|
441
539
|
/**
|
|
442
|
-
* @fileoverview 语音识别 (STT) 实现
|
|
540
|
+
* @fileoverview 语音识别 (STT) 实现 - 商业级版本 v2.0
|
|
443
541
|
* @module melange/plugins/speech/recognition
|
|
444
|
-
* @description
|
|
542
|
+
* @description 生产级 Web 语音识别插件
|
|
543
|
+
*
|
|
544
|
+
* 架构:
|
|
545
|
+
* [UI层] -> [SpeechRecognizerImpl] -> [NativeStrategy / CloudStrategy]
|
|
546
|
+
* |
|
|
547
|
+
* +-> [音频核心]: Worklet, VAD, Resample
|
|
548
|
+
* +-> [适配器]: BaiduAdapter, XunfeiAdapter, TencentAdapter...
|
|
549
|
+
*
|
|
550
|
+
* 功能特性:
|
|
551
|
+
* 1. 多模式: 支持 WebSocket 流式识别 & HTTP 短语音识别
|
|
552
|
+
* 2. 状态机: IDLE -> CONNECTING -> RECORDING -> PROCESSING
|
|
553
|
+
* 3. 插件化: 内置 讯飞/腾讯/百度/阿里/Google/Azure 适配器
|
|
554
|
+
* 4. 核心: AudioWorklet + VAD + 自动重采样 + WAV编码
|
|
555
|
+
* 5. 兼容性: 自动降级处理 (ScriptProcessor) + 断网缓冲队列
|
|
445
556
|
*/
|
|
446
557
|
|
|
558
|
+
declare global {
|
|
559
|
+
interface Window {
|
|
560
|
+
SpeechRecognition?: unknown;
|
|
561
|
+
webkitSpeechRecognition?: unknown;
|
|
562
|
+
webkitAudioContext?: typeof AudioContext;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
447
565
|
/**
|
|
448
|
-
*
|
|
449
|
-
*/
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
566
|
+
* 识别器状态枚举
|
|
567
|
+
*/
|
|
568
|
+
declare enum RecognitionStatus {
|
|
569
|
+
/** 空闲状态 */
|
|
570
|
+
IDLE = "IDLE",
|
|
571
|
+
/** 连接中 */
|
|
572
|
+
CONNECTING = "CONNECTING",
|
|
573
|
+
/** 录音中 */
|
|
574
|
+
RECORDING = "RECORDING",
|
|
575
|
+
/** 处理中/上传中 */
|
|
576
|
+
PROCESSING = "PROCESSING"
|
|
454
577
|
}
|
|
455
578
|
/**
|
|
456
|
-
*
|
|
579
|
+
* 识别引擎模式
|
|
457
580
|
*/
|
|
458
|
-
|
|
459
|
-
readonly length: number;
|
|
460
|
-
readonly isFinal: boolean;
|
|
461
|
-
item(index: number): BrowserSpeechRecognitionAlternative | null;
|
|
462
|
-
[index: number]: BrowserSpeechRecognitionAlternative;
|
|
463
|
-
}
|
|
581
|
+
type RecognitionEngineMode = 'native' | 'cloud' | 'auto';
|
|
464
582
|
/**
|
|
465
|
-
*
|
|
583
|
+
* 云端传输协议类型
|
|
466
584
|
*/
|
|
467
|
-
|
|
468
|
-
readonly transcript: string;
|
|
469
|
-
readonly confidence: number;
|
|
470
|
-
}
|
|
585
|
+
type CloudTransportType = 'websocket' | 'http';
|
|
471
586
|
/**
|
|
472
|
-
*
|
|
587
|
+
* 识别结果接口
|
|
473
588
|
*/
|
|
474
|
-
interface
|
|
475
|
-
|
|
476
|
-
|
|
589
|
+
interface IRecognitionResult {
|
|
590
|
+
/** 识别文本 */
|
|
591
|
+
transcript: string;
|
|
592
|
+
/** 是否为最终结果 */
|
|
593
|
+
isFinal: boolean;
|
|
594
|
+
/** 置信度 (0-1) */
|
|
595
|
+
confidence: number;
|
|
596
|
+
/** 原始响应数据 */
|
|
597
|
+
original?: unknown;
|
|
477
598
|
}
|
|
478
599
|
/**
|
|
479
|
-
*
|
|
480
|
-
*/
|
|
481
|
-
interface
|
|
482
|
-
|
|
483
|
-
|
|
600
|
+
* 音频配置接口
|
|
601
|
+
*/
|
|
602
|
+
interface IAudioConfig {
|
|
603
|
+
/** 目标采样率 (默认 16000) */
|
|
604
|
+
sampleRate?: number;
|
|
605
|
+
/** VAD 阈值 (0.01 ~ 0.5) */
|
|
606
|
+
vadThreshold?: number;
|
|
607
|
+
/** VAD 静音超时 (ms) */
|
|
608
|
+
vadDuration?: number;
|
|
609
|
+
/** 是否启用回声消除 */
|
|
610
|
+
echoCancellation?: boolean;
|
|
611
|
+
/** 是否启用噪声抑制 */
|
|
612
|
+
noiseSuppression?: boolean;
|
|
613
|
+
/** 是否启用自动增益控制 */
|
|
614
|
+
autoGainControl?: boolean;
|
|
484
615
|
}
|
|
485
616
|
/**
|
|
486
|
-
*
|
|
487
|
-
*/
|
|
488
|
-
interface
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
onspeechend: ((this: BrowserSpeechRecognition, ev: Event) => void) | null;
|
|
504
|
-
onaudiostart: ((this: BrowserSpeechRecognition, ev: Event) => void) | null;
|
|
505
|
-
onaudioend: ((this: BrowserSpeechRecognition, ev: Event) => void) | null;
|
|
506
|
-
onnomatch: ((this: BrowserSpeechRecognition, ev: Event) => void) | null;
|
|
617
|
+
* 高级识别配置
|
|
618
|
+
*/
|
|
619
|
+
interface IAdvancedRecognitionConfig extends RecognitionConfig {
|
|
620
|
+
/** 识别引擎模式 */
|
|
621
|
+
mode?: RecognitionEngineMode;
|
|
622
|
+
/** 云端适配器 */
|
|
623
|
+
cloudAdapter?: ICloudRecognitionAdapter;
|
|
624
|
+
/** 传输协议 */
|
|
625
|
+
transport?: CloudTransportType;
|
|
626
|
+
/** 音频配置 */
|
|
627
|
+
audioConfig?: IAudioConfig;
|
|
628
|
+
/** 是否启用自动重连 */
|
|
629
|
+
autoReconnect?: boolean;
|
|
630
|
+
/** 最大重连次数 */
|
|
631
|
+
maxReconnectAttempts?: number;
|
|
632
|
+
/** 重连间隔 (ms) */
|
|
633
|
+
reconnectInterval?: number;
|
|
507
634
|
}
|
|
508
635
|
/**
|
|
509
|
-
*
|
|
636
|
+
* 云端识别适配器接口
|
|
637
|
+
* 提供统一的第三方语音识别服务集成接口
|
|
510
638
|
*/
|
|
511
|
-
interface
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
639
|
+
interface ICloudRecognitionAdapter {
|
|
640
|
+
/** 适配器名称 */
|
|
641
|
+
readonly name: string;
|
|
642
|
+
/**
|
|
643
|
+
* 获取 WebSocket 连接地址
|
|
644
|
+
* @returns WebSocket URL
|
|
645
|
+
*/
|
|
646
|
+
getConnectUrl?(): Promise<string> | string;
|
|
647
|
+
/**
|
|
648
|
+
* 获取握手参数
|
|
649
|
+
* @returns 握手消息
|
|
650
|
+
*/
|
|
651
|
+
getHandshakeParams?(): unknown;
|
|
652
|
+
/**
|
|
653
|
+
* HTTP 短语音识别
|
|
654
|
+
* @param audioData WAV/PCM 二进制数据
|
|
655
|
+
* @returns 识别结果
|
|
656
|
+
*/
|
|
657
|
+
recognizeShortAudio?(audioData: ArrayBuffer): Promise<IRecognitionResult>;
|
|
658
|
+
/**
|
|
659
|
+
* 转换音频数据格式
|
|
660
|
+
* @param pcmData PCM 原始数据
|
|
661
|
+
* @returns 转换后的数据
|
|
662
|
+
*/
|
|
663
|
+
transformAudioData?(pcmData: ArrayBuffer): ArrayBuffer | string;
|
|
664
|
+
/**
|
|
665
|
+
* 解析识别结果
|
|
666
|
+
* @param data 原始响应数据
|
|
667
|
+
* @returns 识别结果
|
|
668
|
+
*/
|
|
669
|
+
parseResult(data: unknown): IRecognitionResult | null;
|
|
670
|
+
/**
|
|
671
|
+
* 检查适配器是否可用
|
|
672
|
+
* @returns 是否可用
|
|
673
|
+
*/
|
|
674
|
+
isAvailable?(): boolean;
|
|
519
675
|
}
|
|
520
676
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
677
|
+
* 语音识别器实现
|
|
678
|
+
* 统一封装原生识别和云端识别
|
|
523
679
|
*/
|
|
524
680
|
declare class SpeechRecognizerImpl implements SpeechRecognizer {
|
|
681
|
+
private strategy;
|
|
682
|
+
private config;
|
|
525
683
|
private _currentProvider;
|
|
526
684
|
private _status;
|
|
527
|
-
private provider;
|
|
528
|
-
private config;
|
|
529
685
|
private eventHandlers;
|
|
530
|
-
private
|
|
531
|
-
/**
|
|
532
|
-
* 当前使用的提供商类型
|
|
533
|
-
*/
|
|
686
|
+
private customProviders;
|
|
534
687
|
get currentProvider(): SpeechProviderType;
|
|
688
|
+
get status(): SpeechServiceStatus;
|
|
535
689
|
/**
|
|
536
|
-
*
|
|
690
|
+
* 获取当前识别状态
|
|
537
691
|
*/
|
|
538
|
-
get
|
|
692
|
+
get recognitionStatus(): RecognitionStatus;
|
|
539
693
|
/**
|
|
540
694
|
* 初始化语音识别器
|
|
541
|
-
* @param config - 识别配置
|
|
542
695
|
*/
|
|
543
696
|
initialize(config?: RecognitionConfig): Promise<void>;
|
|
544
697
|
/**
|
|
545
|
-
*
|
|
698
|
+
* 初始化识别策略
|
|
546
699
|
*/
|
|
547
|
-
private
|
|
700
|
+
private initializeStrategy;
|
|
548
701
|
/**
|
|
549
|
-
*
|
|
702
|
+
* 转发策略事件
|
|
550
703
|
*/
|
|
551
|
-
private
|
|
704
|
+
private forwardStrategyEvents;
|
|
552
705
|
/**
|
|
553
|
-
*
|
|
554
|
-
|
|
706
|
+
* 转换识别结果格式
|
|
707
|
+
*/
|
|
708
|
+
private convertResult;
|
|
709
|
+
/**
|
|
710
|
+
* 开始识别
|
|
555
711
|
*/
|
|
556
712
|
start(config?: RecognitionConfig): Promise<void>;
|
|
557
713
|
/**
|
|
558
|
-
*
|
|
714
|
+
* 停止识别
|
|
559
715
|
*/
|
|
560
716
|
stop(): void;
|
|
561
717
|
/**
|
|
562
|
-
*
|
|
718
|
+
* 中止识别
|
|
563
719
|
*/
|
|
564
720
|
abort(): void;
|
|
565
721
|
/**
|
|
566
|
-
*
|
|
722
|
+
* 是否正在识别
|
|
567
723
|
*/
|
|
568
724
|
isListening(): boolean;
|
|
569
725
|
/**
|
|
@@ -584,60 +740,58 @@ declare class SpeechRecognizerImpl implements SpeechRecognizer {
|
|
|
584
740
|
dispose(): void;
|
|
585
741
|
/**
|
|
586
742
|
* 注册自定义提供商
|
|
587
|
-
* @param type - 提供商类型
|
|
588
|
-
* @param provider - 提供商实例
|
|
589
743
|
*/
|
|
590
744
|
registerProvider(type: SpeechProviderType, provider: RecognitionProvider): void;
|
|
745
|
+
/**
|
|
746
|
+
* 使用云端适配器
|
|
747
|
+
*/
|
|
748
|
+
useCloudAdapter(adapter: ICloudRecognitionAdapter): void;
|
|
591
749
|
}
|
|
592
750
|
/**
|
|
593
751
|
* 创建语音识别器实例
|
|
594
|
-
* @param config
|
|
752
|
+
* @param config 识别配置
|
|
595
753
|
* @returns 语音识别器实例
|
|
596
754
|
*
|
|
597
755
|
* @example
|
|
598
756
|
* ```typescript
|
|
599
|
-
* //
|
|
757
|
+
* // 使用原生识别
|
|
600
758
|
* const recognizer = await createSpeechRecognizer({
|
|
601
759
|
* lang: 'zh-CN',
|
|
602
760
|
* continuous: true,
|
|
603
|
-
* interimResults: true,
|
|
604
761
|
* });
|
|
605
762
|
*
|
|
606
|
-
* //
|
|
763
|
+
* // 使用云端识别 (百度)
|
|
764
|
+
* const baiduAdapter = new BaiduAdapter('your-access-token');
|
|
765
|
+
* const cloudRecognizer = await createSpeechRecognizer({
|
|
766
|
+
* mode: 'cloud',
|
|
767
|
+
* cloudAdapter: baiduAdapter,
|
|
768
|
+
* transport: 'http',
|
|
769
|
+
* });
|
|
770
|
+
*
|
|
607
771
|
* recognizer.on('result', (event) => {
|
|
608
|
-
*
|
|
609
|
-
* console.log('识别结果:', event.result.bestTranscript);
|
|
610
|
-
* }
|
|
772
|
+
* console.log('识别结果:', event.result?.bestTranscript);
|
|
611
773
|
* });
|
|
612
774
|
*
|
|
613
|
-
* // 开始识别
|
|
614
775
|
* await recognizer.start();
|
|
615
|
-
*
|
|
616
|
-
* // 停止识别
|
|
617
|
-
* recognizer.stop();
|
|
618
|
-
*
|
|
619
|
-
* // 销毁
|
|
620
|
-
* recognizer.dispose();
|
|
621
776
|
* ```
|
|
622
777
|
*/
|
|
623
|
-
declare function createSpeechRecognizer(config?: RecognitionConfig): Promise<SpeechRecognizer>;
|
|
778
|
+
declare function createSpeechRecognizer(config?: RecognitionConfig | IAdvancedRecognitionConfig): Promise<SpeechRecognizer>;
|
|
624
779
|
/**
|
|
625
780
|
* 检查当前环境是否支持语音识别
|
|
626
|
-
* @returns
|
|
781
|
+
* @returns 是否支持
|
|
627
782
|
*/
|
|
628
783
|
declare function isSpeechRecognitionSupported(): boolean;
|
|
629
784
|
/**
|
|
630
785
|
* 快速进行一次语音识别
|
|
631
|
-
* @param config
|
|
786
|
+
* @param config 识别配置
|
|
632
787
|
* @returns 识别结果
|
|
633
788
|
*
|
|
634
789
|
* @example
|
|
635
790
|
* ```typescript
|
|
636
|
-
* // 进行一次语音识别
|
|
637
791
|
* const result = await listen({ lang: 'zh-CN' });
|
|
638
792
|
* console.log('识别结果:', result.bestTranscript);
|
|
639
793
|
* ```
|
|
640
794
|
*/
|
|
641
|
-
declare function listen(config?: RecognitionConfig): Promise<RecognitionResult>;
|
|
795
|
+
declare function listen(config?: RecognitionConfig | IAdvancedRecognitionConfig): Promise<RecognitionResult>;
|
|
642
796
|
|
|
643
797
|
export { type AWSSpeechConfig, type AzureSpeechConfig, type BaseSpeechConfig, type CustomProviderConfig, type GoogleSpeechConfig, type ProviderConfig, type RecognitionConfig, type RecognitionEvent, type RecognitionEventHandler, type RecognitionEventType, type RecognitionProvider, type RecognitionResult, type RecognitionResultItem, type SpeechError, type SpeechProviderType, type SpeechRecognizer, SpeechRecognizerImpl, type SpeechServiceStatus, type SpeechSynthesizer, SpeechSynthesizerImpl, type SynthesisConfig, type SynthesisEvent, type SynthesisEventHandler, type SynthesisEventType, type SynthesisProvider, type VoiceInfo, createSpeechRecognizer, createSpeechSynthesizer, isSpeechRecognitionSupported, isSpeechSynthesisSupported, listen, speak };
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { SpeechRecognizerImpl, SpeechSynthesizerImpl, createSpeechRecognizer, createSpeechSynthesizer, isSpeechRecognitionSupported, isSpeechSynthesisSupported, listen, speak } from '../chunk-
|
|
1
|
+
export { SpeechRecognizerImpl, SpeechSynthesizerImpl, createSpeechRecognizer, createSpeechSynthesizer, isSpeechRecognitionSupported, isSpeechSynthesisSupported, listen, speak } from '../chunk-3RM45M64.js';
|
|
2
2
|
import '../chunk-7QVYU63E.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|