qc-ui-lit 0.3.1 → 0.3.3
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.js +3 -2
- package/dist/tools/Speech/Speech.js +54 -0
- package/dist/tools/Speech/index.d.ts +73 -0
- package/dist/tools/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,5 +9,6 @@ import { t as _ } from "./tools/date/date.js";
|
|
|
9
9
|
import { t as v } from "./tools/deepClone/deepClone.js";
|
|
10
10
|
import { a as y, i as b, n as x, o as S, r as C, t as w } from "./tools/fullscreen/fullscreen.js";
|
|
11
11
|
import { n as T, t as E } from "./tools/EventBus/EventBus.js";
|
|
12
|
-
import { t as D } from "./tools/
|
|
13
|
-
|
|
12
|
+
import { t as D } from "./tools/Speech/Speech.js";
|
|
13
|
+
import { t as O } from "./tools/changeCoordinate/changeCoordinate.js";
|
|
14
|
+
export { t as AMap, r as EChartsElement, E as EventBus, O as MapCorrect, o as QCButton, _ as QCDate, n as QCLoading, h as QCReplicable, a as QCResize, D as Speech, p as clearSelection, T as createEventBus, i as debounce, v as deepClone, w as enterFullscreen, x as exitFullscreen, d as getDomText, C as getFullscreenElement, l as getSelectedText, s as hasSelection, b as isFullscreen, e as loadAMap, y as onFullscreenChange, c as readText, f as selectInputText, m as selectText, g as throttle, S as toggleFullscreen, u as writeText };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/tools/Speech/index.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
constructor(e = {}) {
|
|
4
|
+
this.queue = [], this.currentIndex = 0, this.playing = !1, this.paused = !1, this.synth = window.speechSynthesis, this.lang = e.lang ?? "zh-CN", this.rate = e.rate ?? 1, this.pitch = e.pitch ?? 1, this.volume = e.volume ?? 1, this.onStart = e.onStart, this.onPause = e.onPause, this.onResume = e.onResume, this.onEnd = e.onEnd, this.onFinish = e.onFinish, this.onError = e.onError;
|
|
5
|
+
}
|
|
6
|
+
createUtterance(e) {
|
|
7
|
+
let t = new SpeechSynthesisUtterance(e);
|
|
8
|
+
return t.lang = this.lang, t.rate = this.rate, t.pitch = this.pitch, t.volume = this.volume, t;
|
|
9
|
+
}
|
|
10
|
+
playNext() {
|
|
11
|
+
if (this.currentIndex >= this.queue.length) {
|
|
12
|
+
this.playing = !1, this.paused = !1, this.onFinish?.();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let e = this.createUtterance(this.queue[this.currentIndex]);
|
|
16
|
+
e.onstart = () => {
|
|
17
|
+
this.onStart?.();
|
|
18
|
+
}, e.onend = () => {
|
|
19
|
+
this.onEnd?.(), this.currentIndex++, this.playNext();
|
|
20
|
+
}, e.onerror = (e) => {
|
|
21
|
+
this.onError?.(e), this.currentIndex++, this.playNext();
|
|
22
|
+
}, requestAnimationFrame(() => {
|
|
23
|
+
this.synth.speak(e);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
speak(...e) {
|
|
27
|
+
return this.stop(), this.queue = e.filter((e) => e.trim().length > 0), this.currentIndex = 0, this.playing = !0, this.paused = !1, this.queue.length === 0 || this.playNext(), this;
|
|
28
|
+
}
|
|
29
|
+
append(...e) {
|
|
30
|
+
let t = e.filter((e) => e.trim().length > 0);
|
|
31
|
+
if (t.length === 0) return this;
|
|
32
|
+
let n = this.playing;
|
|
33
|
+
return this.queue.push(...t), n || (this.playing = !0, this.paused = !1, this.playNext()), this;
|
|
34
|
+
}
|
|
35
|
+
pause() {
|
|
36
|
+
return this.playing && !this.paused && (this.synth.pause(), this.paused = !0, this.onPause?.()), this;
|
|
37
|
+
}
|
|
38
|
+
resume() {
|
|
39
|
+
return this.playing && this.paused && (this.synth.resume(), this.paused = !1, this.onResume?.()), this;
|
|
40
|
+
}
|
|
41
|
+
stop() {
|
|
42
|
+
return this.synth.cancel(), this.queue = [], this.currentIndex = 0, this.playing = !1, this.paused = !1, this;
|
|
43
|
+
}
|
|
44
|
+
getStatus() {
|
|
45
|
+
return {
|
|
46
|
+
playing: this.playing,
|
|
47
|
+
paused: this.paused,
|
|
48
|
+
currentIndex: this.currentIndex,
|
|
49
|
+
total: this.queue.length
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { e as t };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface SpeechOptions {
|
|
2
|
+
/** 语言,默认 'zh-CN' */
|
|
3
|
+
lang?: string;
|
|
4
|
+
/** 语速,0.1 ~ 10,默认 1 */
|
|
5
|
+
rate?: number;
|
|
6
|
+
/** 音调,0 ~ 2,默认 1 */
|
|
7
|
+
pitch?: number;
|
|
8
|
+
/** 音量,0 ~ 1,默认 1 */
|
|
9
|
+
volume?: number;
|
|
10
|
+
/** 开始播放回调 */
|
|
11
|
+
onStart?: () => void;
|
|
12
|
+
/** 暂停回调 */
|
|
13
|
+
onPause?: () => void;
|
|
14
|
+
/** 恢复播放回调 */
|
|
15
|
+
onResume?: () => void;
|
|
16
|
+
/** 当前文本播放结束回调 */
|
|
17
|
+
onEnd?: () => void;
|
|
18
|
+
/** 全部文本播放完毕回调 */
|
|
19
|
+
onFinish?: () => void;
|
|
20
|
+
/** 错误回调 */
|
|
21
|
+
onError?: (event: SpeechSynthesisErrorEvent) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare class Speech {
|
|
24
|
+
lang: string;
|
|
25
|
+
rate: number;
|
|
26
|
+
pitch: number;
|
|
27
|
+
volume: number;
|
|
28
|
+
onStart?: () => void;
|
|
29
|
+
onPause?: () => void;
|
|
30
|
+
onResume?: () => void;
|
|
31
|
+
onEnd?: () => void;
|
|
32
|
+
onFinish?: () => void;
|
|
33
|
+
onError?: (event: SpeechSynthesisErrorEvent) => void;
|
|
34
|
+
/** 待播放的文本队列 */
|
|
35
|
+
private queue;
|
|
36
|
+
/** 当前播放索引 */
|
|
37
|
+
private currentIndex;
|
|
38
|
+
/** 是否正在播放 */
|
|
39
|
+
private playing;
|
|
40
|
+
/** 是否暂停中 */
|
|
41
|
+
private paused;
|
|
42
|
+
private synth;
|
|
43
|
+
constructor(options?: SpeechOptions);
|
|
44
|
+
/** 创建语音合成 utterance */
|
|
45
|
+
private createUtterance;
|
|
46
|
+
/** 播放队列中的下一段文本 */
|
|
47
|
+
private playNext;
|
|
48
|
+
/**
|
|
49
|
+
* 添加文本到播放队列并立即开始播放
|
|
50
|
+
* @param texts 要朗读的文本,可传多个
|
|
51
|
+
*/
|
|
52
|
+
speak(...texts: string[]): this;
|
|
53
|
+
/**
|
|
54
|
+
* 追加文本到播放队列末尾
|
|
55
|
+
* 如果当前正在播放,追加的文本会在当前文本播放完后自动播放
|
|
56
|
+
* @param texts 要追加的文本
|
|
57
|
+
*/
|
|
58
|
+
append(...texts: string[]): this;
|
|
59
|
+
/** 暂停播放 */
|
|
60
|
+
pause(): this;
|
|
61
|
+
/** 恢复播放 */
|
|
62
|
+
resume(): this;
|
|
63
|
+
/** 停止播放并清空队列 */
|
|
64
|
+
stop(): this;
|
|
65
|
+
/** 获取当前播放状态 */
|
|
66
|
+
getStatus(): {
|
|
67
|
+
playing: boolean;
|
|
68
|
+
paused: boolean;
|
|
69
|
+
currentIndex: number;
|
|
70
|
+
total: number;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export default Speech;
|
package/dist/tools/index.d.ts
CHANGED