@christianriedl/utils 1.0.91 → 1.0.92
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.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/useSpeechRecognition.d.ts +104 -0
- package/dist/useSpeechRecognition.js +79 -0
- package/dist/useSpeechRecognition.js.map +1 -0
- package/dist/useSpeechSynthesis.d.ts +49 -0
- package/dist/useSpeechSynthesis.js +96 -0
- package/dist/useSpeechSynthesis.js.map +1 -0
- package/package.json +2 -2
- package/src/components/Microphone.vue +45 -0
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,6 @@ export * from './appConfig';
|
|
|
12
12
|
export * from './statistics';
|
|
13
13
|
export * from './marshalBE';
|
|
14
14
|
export * from './marshalLE';
|
|
15
|
+
export * from './useSpeechRecognition';
|
|
16
|
+
export * from './useSpeechSynthesis';
|
|
15
17
|
export { InjectionKey, Ref, ref, reactive, toRaw, isRef, watchEffect } from 'vue';
|
package/dist/index.js
CHANGED
|
@@ -12,5 +12,7 @@ export * from './appConfig';
|
|
|
12
12
|
export * from './statistics';
|
|
13
13
|
export * from './marshalBE';
|
|
14
14
|
export * from './marshalLE';
|
|
15
|
+
export * from './useSpeechRecognition';
|
|
16
|
+
export * from './useSpeechSynthesis';
|
|
15
17
|
export { ref, reactive, toRaw, isRef, watchEffect } from 'vue';
|
|
16
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAqB,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAqB,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export type SpeechRecognitionErrorCode = 'aborted' | 'audio-capture' | 'bad-grammar' | 'language-not-supported' | 'network' | 'no-speech' | 'not-allowed' | 'service-not-allowed';
|
|
3
|
+
interface SpeechGrammar {
|
|
4
|
+
src: string;
|
|
5
|
+
weight: number;
|
|
6
|
+
}
|
|
7
|
+
interface SpeechGrammarList {
|
|
8
|
+
readonly length: number;
|
|
9
|
+
addFromString: (string: string, weight?: number) => void;
|
|
10
|
+
addFromURI: (src: string, weight?: number) => void;
|
|
11
|
+
item: (index: number) => SpeechGrammar;
|
|
12
|
+
[index: number]: SpeechGrammar;
|
|
13
|
+
}
|
|
14
|
+
export interface SpeechRecognitionErrorEvent extends Event {
|
|
15
|
+
readonly error: SpeechRecognitionErrorCode;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
}
|
|
18
|
+
interface SpeechRecognitionEvent extends Event {
|
|
19
|
+
readonly resultIndex: number;
|
|
20
|
+
readonly results: SpeechRecognitionResultList;
|
|
21
|
+
}
|
|
22
|
+
interface SpeechRecognitionEventMap {
|
|
23
|
+
audioend: Event;
|
|
24
|
+
audiostart: Event;
|
|
25
|
+
end: Event;
|
|
26
|
+
error: SpeechRecognitionErrorEvent;
|
|
27
|
+
nomatch: SpeechRecognitionEvent;
|
|
28
|
+
result: SpeechRecognitionEvent;
|
|
29
|
+
soundend: Event;
|
|
30
|
+
soundstart: Event;
|
|
31
|
+
speechend: Event;
|
|
32
|
+
speechstart: Event;
|
|
33
|
+
start: Event;
|
|
34
|
+
}
|
|
35
|
+
export interface SpeechRecognition extends EventTarget {
|
|
36
|
+
continuous: boolean;
|
|
37
|
+
grammars: SpeechGrammarList;
|
|
38
|
+
interimResults: boolean;
|
|
39
|
+
lang: string;
|
|
40
|
+
maxAlternatives: number;
|
|
41
|
+
onaudioend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
42
|
+
onaudiostart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
43
|
+
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
44
|
+
onerror: ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => any) | null;
|
|
45
|
+
onnomatch: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
|
|
46
|
+
onresult: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
|
|
47
|
+
onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
48
|
+
onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
49
|
+
onspeechend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
50
|
+
onspeechstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
51
|
+
onstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
|
52
|
+
abort: () => void;
|
|
53
|
+
start: () => void;
|
|
54
|
+
stop: () => void;
|
|
55
|
+
addEventListener: (<K extends keyof SpeechRecognitionEventMap>(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void);
|
|
56
|
+
removeEventListener: (<K extends keyof SpeechRecognitionEventMap>(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | EventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void);
|
|
57
|
+
}
|
|
58
|
+
export interface UseSpeechRecognitionOptions {
|
|
59
|
+
/**
|
|
60
|
+
* Controls whether continuous results are returned for each recognition, or only a single result.
|
|
61
|
+
*
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
continuous?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Controls whether interim results should be returned (true) or not (false.) Interim results are results that are not yet final
|
|
67
|
+
*
|
|
68
|
+
* @default true
|
|
69
|
+
*/
|
|
70
|
+
interimResults?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Language for SpeechRecognition
|
|
73
|
+
*
|
|
74
|
+
* @default 'en-US'
|
|
75
|
+
*/
|
|
76
|
+
lang?: Ref<string>;
|
|
77
|
+
/**
|
|
78
|
+
* A number representing the maximum returned alternatives for each result.
|
|
79
|
+
*
|
|
80
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/maxAlternatives
|
|
81
|
+
* @default 1
|
|
82
|
+
*/
|
|
83
|
+
maxAlternatives?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Reactive SpeechRecognition.
|
|
87
|
+
*
|
|
88
|
+
* @see https://vueuse.org/useSpeechRecognition
|
|
89
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition SpeechRecognition
|
|
90
|
+
* @param options
|
|
91
|
+
*/
|
|
92
|
+
export declare function useSpeechRecognition(options?: UseSpeechRecognitionOptions): {
|
|
93
|
+
isSupported: boolean;
|
|
94
|
+
isListening: Ref<boolean>;
|
|
95
|
+
isFinal: Ref<boolean>;
|
|
96
|
+
recognition: SpeechRecognition;
|
|
97
|
+
result: Ref<string>;
|
|
98
|
+
error: Ref<SpeechRecognitionErrorEvent>;
|
|
99
|
+
toggle: (value?: boolean) => void;
|
|
100
|
+
start: () => void;
|
|
101
|
+
stop: () => void;
|
|
102
|
+
};
|
|
103
|
+
export type UseSpeechRecognitionReturn = ReturnType<typeof useSpeechRecognition>;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { toRef, toValue, ref, shallowRef, watch } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Reactive SpeechRecognition.
|
|
4
|
+
*
|
|
5
|
+
* @see https://vueuse.org/useSpeechRecognition
|
|
6
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition SpeechRecognition
|
|
7
|
+
* @param options
|
|
8
|
+
*/
|
|
9
|
+
export function useSpeechRecognition(options = {}) {
|
|
10
|
+
const { interimResults = true, continuous = true, maxAlternatives = 1 } = options;
|
|
11
|
+
const lang = toRef(options.lang || 'en-US');
|
|
12
|
+
const isListening = ref(false);
|
|
13
|
+
const isFinal = ref(false);
|
|
14
|
+
const result = ref('');
|
|
15
|
+
const error = shallowRef(undefined);
|
|
16
|
+
const toggle = (value = !isListening.value) => {
|
|
17
|
+
isListening.value = value;
|
|
18
|
+
};
|
|
19
|
+
const start = () => {
|
|
20
|
+
isListening.value = true;
|
|
21
|
+
};
|
|
22
|
+
const stop = () => {
|
|
23
|
+
isListening.value = false;
|
|
24
|
+
};
|
|
25
|
+
const SpeechRecognition = window && (window.SpeechRecognition || window.webkitSpeechRecognition);
|
|
26
|
+
const isSupported = !!SpeechRecognition;
|
|
27
|
+
let recognition;
|
|
28
|
+
if (isSupported) {
|
|
29
|
+
recognition = new SpeechRecognition();
|
|
30
|
+
recognition.continuous = continuous;
|
|
31
|
+
recognition.interimResults = interimResults;
|
|
32
|
+
recognition.lang = toValue(lang);
|
|
33
|
+
recognition.maxAlternatives = maxAlternatives;
|
|
34
|
+
recognition.onstart = () => {
|
|
35
|
+
isFinal.value = false;
|
|
36
|
+
};
|
|
37
|
+
watch(lang, (lang) => {
|
|
38
|
+
if (recognition && !isListening.value)
|
|
39
|
+
recognition.lang = lang;
|
|
40
|
+
});
|
|
41
|
+
recognition.onresult = (event) => {
|
|
42
|
+
const currentResult = event.results[event.resultIndex];
|
|
43
|
+
const { transcript } = currentResult[0];
|
|
44
|
+
isFinal.value = currentResult.isFinal;
|
|
45
|
+
result.value = transcript;
|
|
46
|
+
error.value = undefined;
|
|
47
|
+
};
|
|
48
|
+
recognition.onerror = (event) => {
|
|
49
|
+
error.value = event;
|
|
50
|
+
};
|
|
51
|
+
recognition.onend = () => {
|
|
52
|
+
isListening.value = false;
|
|
53
|
+
recognition.lang = toValue(lang);
|
|
54
|
+
};
|
|
55
|
+
watch(isListening, () => {
|
|
56
|
+
if (isListening.value)
|
|
57
|
+
recognition.start();
|
|
58
|
+
else
|
|
59
|
+
recognition.stop();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/*
|
|
63
|
+
tryOnScopeDispose(() => {
|
|
64
|
+
isListening.value = false
|
|
65
|
+
})
|
|
66
|
+
*/
|
|
67
|
+
return {
|
|
68
|
+
isSupported,
|
|
69
|
+
isListening,
|
|
70
|
+
isFinal,
|
|
71
|
+
recognition,
|
|
72
|
+
result,
|
|
73
|
+
error,
|
|
74
|
+
toggle,
|
|
75
|
+
start,
|
|
76
|
+
stop,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=useSpeechRecognition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechRecognition.js","sourceRoot":"","sources":["../src/useSpeechRecognition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAO,MAAM,KAAK,CAAC;AAwGlE;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAuC,EAAE;IAC1E,MAAM,EACF,cAAc,GAAG,IAAI,EACrB,UAAU,GAAG,IAAI,EACjB,eAAe,GAAG,CAAC,EACtB,GAAG,OAAO,CAAA;IAEX,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,CAAA;IAC3C,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;IAC9B,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC,CAAA;IACtB,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAiD,CAAA;IAEnF,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE;QAC1C,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;IAC7B,CAAC,CAAA;IAED,MAAM,KAAK,GAAG,GAAG,EAAE;QACf,WAAW,CAAC,KAAK,GAAG,IAAI,CAAA;IAC5B,CAAC,CAAA;IAED,MAAM,IAAI,GAAG,GAAG,EAAE;QACd,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;IAC7B,CAAC,CAAA;IAED,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAE,MAAc,CAAC,iBAAiB,IAAK,MAAc,CAAC,uBAAuB,CAAC,CAAA;IAClH,MAAM,WAAW,GAAG,CAAC,CAAC,iBAAiB,CAAC;IAExC,IAAI,WAA0C,CAAA;IAE9C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gBACjB,WAAY,CAAC,KAAK,EAAE,CAAA;;gBAEpB,WAAY,CAAC,IAAI,EAAE,CAAA;QAC3B,CAAC,CAAC,CAAA;KACL;IACD;;;;KAIC;IAED,OAAO;QACH,WAAW;QACX,WAAW;QACX,OAAO;QACP,WAAW;QACX,MAAM;QACN,KAAK;QAEL,MAAM;QACN,KAAK;QACL,IAAI;KACP,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export type UseSpeechSynthesisStatus = 'init' | 'play' | 'pause' | 'end';
|
|
3
|
+
export interface UseSpeechSynthesisOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Language for SpeechSynthesis
|
|
6
|
+
*
|
|
7
|
+
* @default 'en-US'
|
|
8
|
+
*/
|
|
9
|
+
lang?: Ref<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Gets and sets the pitch at which the utterance will be spoken at.
|
|
12
|
+
*
|
|
13
|
+
* @default 1
|
|
14
|
+
*/
|
|
15
|
+
pitch?: Ref<SpeechSynthesisUtterance['pitch']>;
|
|
16
|
+
/**
|
|
17
|
+
* Gets and sets the speed at which the utterance will be spoken at.
|
|
18
|
+
*
|
|
19
|
+
* @default 1
|
|
20
|
+
*/
|
|
21
|
+
rate?: Ref<SpeechSynthesisUtterance['rate']>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets and sets the voice that will be used to speak the utterance.
|
|
24
|
+
*/
|
|
25
|
+
voice?: Ref<SpeechSynthesisVoice>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets and sets the volume that the utterance will be spoken at.
|
|
28
|
+
*
|
|
29
|
+
* @default 1
|
|
30
|
+
*/
|
|
31
|
+
volume?: SpeechSynthesisUtterance['volume'];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reactive SpeechSynthesis.
|
|
35
|
+
*
|
|
36
|
+
* @see https://vueuse.org/useSpeechSynthesis
|
|
37
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis SpeechSynthesis
|
|
38
|
+
*/
|
|
39
|
+
export declare function useSpeechSynthesis(text: Ref<string>, options?: UseSpeechSynthesisOptions): {
|
|
40
|
+
isSupported: boolean;
|
|
41
|
+
isPlaying: Ref<boolean>;
|
|
42
|
+
status: Ref<UseSpeechSynthesisStatus>;
|
|
43
|
+
utterance: import("vue").ComputedRef<SpeechSynthesisUtterance>;
|
|
44
|
+
error: Ref<SpeechSynthesisErrorEvent>;
|
|
45
|
+
stop: () => void;
|
|
46
|
+
toggle: (value?: boolean) => void;
|
|
47
|
+
speak: () => void;
|
|
48
|
+
};
|
|
49
|
+
export type UseSpeechSynthesisReturn = ReturnType<typeof useSpeechSynthesis>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { computed, ref, shallowRef, watch, toRef, toValue } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Reactive SpeechSynthesis.
|
|
4
|
+
*
|
|
5
|
+
* @see https://vueuse.org/useSpeechSynthesis
|
|
6
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis SpeechSynthesis
|
|
7
|
+
*/
|
|
8
|
+
export function useSpeechSynthesis(text, options = {}) {
|
|
9
|
+
const { pitch = 1, rate = 1, volume = 1 } = options;
|
|
10
|
+
const synth = window && window.speechSynthesis;
|
|
11
|
+
const isSupported = !!synth;
|
|
12
|
+
const isPlaying = ref(false);
|
|
13
|
+
const status = ref('init');
|
|
14
|
+
const spokenText = toRef(text || '');
|
|
15
|
+
const lang = toRef(options.lang || 'en-US');
|
|
16
|
+
const error = shallowRef(undefined);
|
|
17
|
+
const toggle = (value = !isPlaying.value) => {
|
|
18
|
+
isPlaying.value = value;
|
|
19
|
+
};
|
|
20
|
+
const bindEventsForUtterance = (utterance) => {
|
|
21
|
+
utterance.lang = toValue(lang);
|
|
22
|
+
utterance.voice = toValue(options.voice) || null;
|
|
23
|
+
utterance.pitch = toValue(pitch);
|
|
24
|
+
utterance.rate = toValue(rate);
|
|
25
|
+
utterance.volume = volume;
|
|
26
|
+
utterance.onstart = () => {
|
|
27
|
+
isPlaying.value = true;
|
|
28
|
+
status.value = 'play';
|
|
29
|
+
};
|
|
30
|
+
utterance.onpause = () => {
|
|
31
|
+
isPlaying.value = false;
|
|
32
|
+
status.value = 'pause';
|
|
33
|
+
};
|
|
34
|
+
utterance.onresume = () => {
|
|
35
|
+
isPlaying.value = true;
|
|
36
|
+
status.value = 'play';
|
|
37
|
+
};
|
|
38
|
+
utterance.onend = () => {
|
|
39
|
+
isPlaying.value = false;
|
|
40
|
+
status.value = 'end';
|
|
41
|
+
};
|
|
42
|
+
utterance.onerror = (event) => {
|
|
43
|
+
error.value = event;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const utterance = computed(() => {
|
|
47
|
+
isPlaying.value = false;
|
|
48
|
+
status.value = 'init';
|
|
49
|
+
const newUtterance = new SpeechSynthesisUtterance(spokenText.value);
|
|
50
|
+
bindEventsForUtterance(newUtterance);
|
|
51
|
+
return newUtterance;
|
|
52
|
+
});
|
|
53
|
+
const speak = () => {
|
|
54
|
+
synth.cancel();
|
|
55
|
+
if (utterance)
|
|
56
|
+
synth.speak(utterance.value);
|
|
57
|
+
};
|
|
58
|
+
const stop = () => {
|
|
59
|
+
synth.cancel();
|
|
60
|
+
isPlaying.value = false;
|
|
61
|
+
};
|
|
62
|
+
if (isSupported) {
|
|
63
|
+
bindEventsForUtterance(utterance.value);
|
|
64
|
+
watch(lang, (lang) => {
|
|
65
|
+
if (utterance.value && !isPlaying.value)
|
|
66
|
+
utterance.value.lang = lang;
|
|
67
|
+
});
|
|
68
|
+
if (options.voice) {
|
|
69
|
+
watch(options.voice, () => {
|
|
70
|
+
synth.cancel();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
watch(isPlaying, () => {
|
|
74
|
+
if (isPlaying.value)
|
|
75
|
+
synth.resume();
|
|
76
|
+
else
|
|
77
|
+
synth.pause();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/*
|
|
81
|
+
tryOnScopeDispose(() => {
|
|
82
|
+
isPlaying.value = false
|
|
83
|
+
})
|
|
84
|
+
*/
|
|
85
|
+
return {
|
|
86
|
+
isSupported,
|
|
87
|
+
isPlaying,
|
|
88
|
+
status,
|
|
89
|
+
utterance,
|
|
90
|
+
error,
|
|
91
|
+
stop,
|
|
92
|
+
toggle,
|
|
93
|
+
speak,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=useSpeechSynthesis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechSynthesis.js","sourceRoot":"","sources":["../src/useSpeechSynthesis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAO,OAAO,EAAE,MAAM,KAAK,CAAC;AAmC5E;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAC9B,IAAiB,EACjB,UAAqC,EAAE;IAEvC,MAAM,EACF,KAAK,GAAG,CAAC,EACT,IAAI,GAAG,CAAC,EACR,MAAM,GAAG,CAAC,EACb,GAAG,OAAO,CAAA;IAEX,MAAM,KAAK,GAAG,MAAM,IAAK,MAAc,CAAC,eAAkC,CAAA;IAC1E,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAA;IAC3B,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;IAC5B,MAAM,MAAM,GAAG,GAAG,CAA2B,MAAM,CAAC,CAAA;IAEpD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,CAAA;IAC3C,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAA+C,CAAA;IAEjF,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG,CAAC,SAAS,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;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christianriedl/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.92",
|
|
4
4
|
"description": "Interfaces, local storage, service worker, configuration, application state",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "Christian Riedl",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"vue": "^3.
|
|
19
|
+
"vue": "^3.4.38"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^18.11.18",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch } from 'vue'
|
|
3
|
+
import { useSpeechRecognition } from '@christianriedl/utils';
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{ lang?: string, maxAlternatives?: number, size?: string, cls?: string, variant?: string }>();
|
|
6
|
+
const emits = defineEmits<{
|
|
7
|
+
(e: 'result', result: string): void,
|
|
8
|
+
(e: 'listening', isListening: boolean): void,
|
|
9
|
+
(e: 'final', visFinal: boolean): void
|
|
10
|
+
}>();
|
|
11
|
+
|
|
12
|
+
const sz = props.size ? props.size : "large";
|
|
13
|
+
const cls = props.cls ? props.cls : "bg-office";
|
|
14
|
+
const vari = props.variant ? props.variant : "tonal";
|
|
15
|
+
const lang = ref('de-AT');
|
|
16
|
+
const maxAlternatives = ref(1);
|
|
17
|
+
|
|
18
|
+
if (props.lang)
|
|
19
|
+
lang.value = props.lang;
|
|
20
|
+
if (props.maxAlternatives)
|
|
21
|
+
maxAlternatives.value = props.maxAlternatives;
|
|
22
|
+
|
|
23
|
+
const speech = useSpeechRecognition({
|
|
24
|
+
lang,
|
|
25
|
+
maxAlternatives,
|
|
26
|
+
continuous: false,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const sampled = ref<string[]>([])
|
|
30
|
+
|
|
31
|
+
function onStart() {
|
|
32
|
+
speech.result.value = ''
|
|
33
|
+
speech.start()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { isListening, isFinal, stop, result } = speech
|
|
37
|
+
watch(isListening, isListening => emits("listening", isListening.value));
|
|
38
|
+
watch(isFinal, isFinal => emits("final", isFinal.value));
|
|
39
|
+
watch(result, result => emits("result", result.value));
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<v-btn :size="sz" :class="cls" :variant="vari" icon="$microphone" :color="isListening ? 'red' : 'white'", @click="onStart"></v-btn>
|
|
44
|
+
</template>
|
|
45
|
+
|