@capacitor-community/text-to-speech 2.0.1 → 2.1.0

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/esm/web.js CHANGED
@@ -1,92 +1,92 @@
1
- import { WebPlugin } from '@capacitor/core';
2
- export class TextToSpeechWeb extends WebPlugin {
3
- constructor() {
4
- super();
5
- this.speechSynthesis = null;
6
- if ('speechSynthesis' in window) {
7
- this.speechSynthesis = window.speechSynthesis;
8
- window.addEventListener('beforeunload', () => {
9
- this.stop();
10
- });
11
- }
12
- }
13
- async speak(options) {
14
- if (!this.speechSynthesis) {
15
- this.throwUnsupportedError();
16
- }
17
- await this.stop();
18
- const speechSynthesis = this.speechSynthesis;
19
- const utterance = this.createSpeechSynthesisUtterance(options);
20
- return new Promise((resolve, reject) => {
21
- utterance.onend = () => {
22
- resolve();
23
- };
24
- utterance.onerror = (event) => {
25
- reject(event);
26
- };
27
- speechSynthesis.speak(utterance);
28
- });
29
- }
30
- async stop() {
31
- if (!this.speechSynthesis) {
32
- this.throwUnsupportedError();
33
- }
34
- this.speechSynthesis.cancel();
35
- }
36
- async getSupportedLanguages() {
37
- const voices = this.getSpeechSynthesisVoices();
38
- const languages = voices.map(voice => voice.lang);
39
- const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
40
- return { languages: filteredLanguages };
41
- }
42
- async getSupportedVoices() {
43
- const voices = this.getSpeechSynthesisVoices();
44
- return { voices };
45
- }
46
- async isLanguageSupported(options) {
47
- const result = await this.getSupportedLanguages();
48
- const isLanguageSupported = result.languages.includes(options.lang);
49
- return { supported: isLanguageSupported };
50
- }
51
- async openInstall() {
52
- this.throwUnimplementedError();
53
- }
54
- createSpeechSynthesisUtterance(options) {
55
- const voices = this.getSpeechSynthesisVoices();
56
- const utterance = new SpeechSynthesisUtterance();
57
- const { text, lang, rate, pitch, volume, voice } = options;
58
- if (voice) {
59
- utterance.voice = voices[voice];
60
- }
61
- if (volume) {
62
- utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
63
- }
64
- if (rate) {
65
- utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
66
- }
67
- if (pitch) {
68
- utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
69
- }
70
- if (lang) {
71
- utterance.lang = lang;
72
- }
73
- utterance.text = text;
74
- return utterance;
75
- }
76
- getSpeechSynthesisVoices() {
77
- if (!this.speechSynthesis) {
78
- this.throwUnsupportedError();
79
- }
80
- if (!this.supportedVoices || this.supportedVoices.length < 1) {
81
- this.supportedVoices = this.speechSynthesis.getVoices();
82
- }
83
- return this.supportedVoices;
84
- }
85
- throwUnsupportedError() {
86
- throw this.unavailable('SpeechSynthesis API not available in this browser.');
87
- }
88
- throwUnimplementedError() {
89
- throw this.unimplemented('Not implemented on web.');
90
- }
91
- }
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class TextToSpeechWeb extends WebPlugin {
3
+ constructor() {
4
+ super();
5
+ this.speechSynthesis = null;
6
+ if ('speechSynthesis' in window) {
7
+ this.speechSynthesis = window.speechSynthesis;
8
+ window.addEventListener('beforeunload', () => {
9
+ this.stop();
10
+ });
11
+ }
12
+ }
13
+ async speak(options) {
14
+ if (!this.speechSynthesis) {
15
+ this.throwUnsupportedError();
16
+ }
17
+ await this.stop();
18
+ const speechSynthesis = this.speechSynthesis;
19
+ const utterance = this.createSpeechSynthesisUtterance(options);
20
+ return new Promise((resolve, reject) => {
21
+ utterance.onend = () => {
22
+ resolve();
23
+ };
24
+ utterance.onerror = (event) => {
25
+ reject(event);
26
+ };
27
+ speechSynthesis.speak(utterance);
28
+ });
29
+ }
30
+ async stop() {
31
+ if (!this.speechSynthesis) {
32
+ this.throwUnsupportedError();
33
+ }
34
+ this.speechSynthesis.cancel();
35
+ }
36
+ async getSupportedLanguages() {
37
+ const voices = this.getSpeechSynthesisVoices();
38
+ const languages = voices.map(voice => voice.lang);
39
+ const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
40
+ return { languages: filteredLanguages };
41
+ }
42
+ async getSupportedVoices() {
43
+ const voices = this.getSpeechSynthesisVoices();
44
+ return { voices };
45
+ }
46
+ async isLanguageSupported(options) {
47
+ const result = await this.getSupportedLanguages();
48
+ const isLanguageSupported = result.languages.includes(options.lang);
49
+ return { supported: isLanguageSupported };
50
+ }
51
+ async openInstall() {
52
+ this.throwUnimplementedError();
53
+ }
54
+ createSpeechSynthesisUtterance(options) {
55
+ const voices = this.getSpeechSynthesisVoices();
56
+ const utterance = new SpeechSynthesisUtterance();
57
+ const { text, lang, rate, pitch, volume, voice } = options;
58
+ if (voice) {
59
+ utterance.voice = voices[voice];
60
+ }
61
+ if (volume) {
62
+ utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
63
+ }
64
+ if (rate) {
65
+ utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
66
+ }
67
+ if (pitch) {
68
+ utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
69
+ }
70
+ if (lang) {
71
+ utterance.lang = lang;
72
+ }
73
+ utterance.text = text;
74
+ return utterance;
75
+ }
76
+ getSpeechSynthesisVoices() {
77
+ if (!this.speechSynthesis) {
78
+ this.throwUnsupportedError();
79
+ }
80
+ if (!this.supportedVoices || this.supportedVoices.length < 1) {
81
+ this.supportedVoices = this.speechSynthesis.getVoices();
82
+ }
83
+ return this.supportedVoices;
84
+ }
85
+ throwUnsupportedError() {
86
+ throw this.unavailable('SpeechSynthesis API not available in this browser.');
87
+ }
88
+ throwUnimplementedError() {
89
+ throw this.unimplemented('Not implemented on web.');
90
+ }
91
+ }
92
92
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAI5C;QACE,KAAK,EAAE,CAAC;QAJF,oBAAe,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I,GAAG,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACvD;QACD,IAAI,KAAK,EAAE;YACT,SAAS,CAAC,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACxD;QACD,IAAI,IAAI,EAAE;YACR,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;SACvB;QACD,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,wBAAwB;QAC9B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5D,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;SACzD;QACD,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAEO,qBAAqB;QAC3B,MAAM,IAAI,CAAC,WAAW,CACpB,oDAAoD,CACrD,CAAC;IACJ,CAAC;IAEO,uBAAuB;QAC7B,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\r\n\r\nimport type { TextToSpeechPlugin, TTSOptions } from './definitions';\r\n\r\nexport class TextToSpeechWeb extends WebPlugin implements TextToSpeechPlugin {\r\n private speechSynthesis: SpeechSynthesis | null = null;\r\n private supportedVoices: SpeechSynthesisVoice[] | undefined;\r\n\r\n constructor() {\r\n super();\r\n if ('speechSynthesis' in window) {\r\n this.speechSynthesis = window.speechSynthesis;\r\n window.addEventListener('beforeunload', () => {\r\n this.stop();\r\n });\r\n }\r\n }\r\n\r\n public async speak(options: TTSOptions): Promise<void> {\r\n if (!this.speechSynthesis) {\r\n this.throwUnsupportedError();\r\n }\r\n await this.stop();\r\n const speechSynthesis = this.speechSynthesis;\r\n const utterance = this.createSpeechSynthesisUtterance(options);\r\n return new Promise((resolve, reject) => {\r\n utterance.onend = () => {\r\n resolve();\r\n };\r\n utterance.onerror = (event: any) => {\r\n reject(event);\r\n };\r\n speechSynthesis.speak(utterance);\r\n });\r\n }\r\n\r\n public async stop(): Promise<void> {\r\n if (!this.speechSynthesis) {\r\n this.throwUnsupportedError();\r\n }\r\n this.speechSynthesis.cancel();\r\n }\r\n\r\n public async getSupportedLanguages(): Promise<{ languages: string[] }> {\r\n const voices = this.getSpeechSynthesisVoices();\r\n const languages = voices.map(voice => voice.lang);\r\n const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);\r\n return { languages: filteredLanguages };\r\n }\r\n\r\n public async getSupportedVoices(): Promise<{\r\n voices: SpeechSynthesisVoice[];\r\n }> {\r\n const voices = this.getSpeechSynthesisVoices();\r\n return { voices };\r\n }\r\n\r\n public async isLanguageSupported(options: {\r\n lang: string;\r\n }): Promise<{ supported: boolean }> {\r\n const result = await this.getSupportedLanguages();\r\n const isLanguageSupported = result.languages.includes(options.lang);\r\n return { supported: isLanguageSupported };\r\n }\r\n\r\n public async openInstall(): Promise<void> {\r\n this.throwUnimplementedError();\r\n }\r\n\r\n private createSpeechSynthesisUtterance(\r\n options: TTSOptions,\r\n ): SpeechSynthesisUtterance {\r\n const voices = this.getSpeechSynthesisVoices();\r\n const utterance = new SpeechSynthesisUtterance();\r\n const { text, lang, rate, pitch, volume, voice } = options;\r\n if (voice) {\r\n utterance.voice = voices[voice];\r\n }\r\n if (volume) {\r\n utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;\r\n }\r\n if (rate) {\r\n utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;\r\n }\r\n if (pitch) {\r\n utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;\r\n }\r\n if (lang) {\r\n utterance.lang = lang;\r\n }\r\n utterance.text = text;\r\n return utterance;\r\n }\r\n\r\n private getSpeechSynthesisVoices(): SpeechSynthesisVoice[] {\r\n if (!this.speechSynthesis) {\r\n this.throwUnsupportedError();\r\n }\r\n if (!this.supportedVoices || this.supportedVoices.length < 1) {\r\n this.supportedVoices = this.speechSynthesis.getVoices();\r\n }\r\n return this.supportedVoices;\r\n }\r\n\r\n private throwUnsupportedError(): never {\r\n throw this.unavailable(\r\n 'SpeechSynthesis API not available in this browser.',\r\n );\r\n }\r\n\r\n private throwUnimplementedError(): never {\r\n throw this.unimplemented('Not implemented on web.');\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAI5C;QACE,KAAK,EAAE,CAAC;QAJF,oBAAe,GAA2B,IAAI,CAAC;QAKrD,IAAI,iBAAiB,IAAI,MAAM,EAAE;YAC/B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;YAC9C,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,GAAG,EAAE;gBAC3C,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,OAAmB;QACpC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC;QAC/D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;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E;YAC5D,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;SACzD;QACD,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAEO,qBAAqB;QAC3B,MAAM,IAAI,CAAC,WAAW,CACpB,oDAAoD,CACrD,CAAC;IACJ,CAAC;IAEO,uBAAuB;QAC7B,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { TextToSpeechPlugin, TTSOptions } from './definitions';\n\nexport class TextToSpeechWeb extends WebPlugin implements TextToSpeechPlugin {\n private speechSynthesis: SpeechSynthesis | null = null;\n private supportedVoices: SpeechSynthesisVoice[] | undefined;\n\n constructor() {\n super();\n if ('speechSynthesis' in window) {\n this.speechSynthesis = window.speechSynthesis;\n window.addEventListener('beforeunload', () => {\n this.stop();\n });\n }\n }\n\n public async speak(options: TTSOptions): Promise<void> {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n await this.stop();\n const speechSynthesis = this.speechSynthesis;\n const utterance = this.createSpeechSynthesisUtterance(options);\n return new Promise((resolve, reject) => {\n utterance.onend = () => {\n resolve();\n };\n utterance.onerror = (event: any) => {\n reject(event);\n };\n speechSynthesis.speak(utterance);\n });\n }\n\n public async stop(): Promise<void> {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n this.speechSynthesis.cancel();\n }\n\n public async getSupportedLanguages(): Promise<{ languages: string[] }> {\n const voices = this.getSpeechSynthesisVoices();\n const languages = voices.map(voice => voice.lang);\n const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);\n return { languages: filteredLanguages };\n }\n\n public async getSupportedVoices(): Promise<{\n voices: SpeechSynthesisVoice[];\n }> {\n const voices = this.getSpeechSynthesisVoices();\n return { voices };\n }\n\n public async isLanguageSupported(options: {\n lang: string;\n }): Promise<{ supported: boolean }> {\n const result = await this.getSupportedLanguages();\n const isLanguageSupported = result.languages.includes(options.lang);\n return { supported: isLanguageSupported };\n }\n\n public async openInstall(): Promise<void> {\n this.throwUnimplementedError();\n }\n\n private createSpeechSynthesisUtterance(\n options: TTSOptions,\n ): SpeechSynthesisUtterance {\n const voices = this.getSpeechSynthesisVoices();\n const utterance = new SpeechSynthesisUtterance();\n const { text, lang, rate, pitch, volume, voice } = options;\n if (voice) {\n utterance.voice = voices[voice];\n }\n if (volume) {\n utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;\n }\n if (rate) {\n utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;\n }\n if (pitch) {\n utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;\n }\n if (lang) {\n utterance.lang = lang;\n }\n utterance.text = text;\n return utterance;\n }\n\n private getSpeechSynthesisVoices(): SpeechSynthesisVoice[] {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n if (!this.supportedVoices || this.supportedVoices.length < 1) {\n this.supportedVoices = this.speechSynthesis.getVoices();\n }\n return this.supportedVoices;\n }\n\n private throwUnsupportedError(): never {\n throw this.unavailable(\n 'SpeechSynthesis API not available in this browser.',\n );\n }\n\n private throwUnimplementedError(): never {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
@@ -4,99 +4,99 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@capacitor/core');
6
6
 
7
- const TextToSpeech = core.registerPlugin('TextToSpeech', {
8
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()),
7
+ const TextToSpeech = core.registerPlugin('TextToSpeech', {
8
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()),
9
9
  });
10
10
 
11
- class TextToSpeechWeb extends core.WebPlugin {
12
- constructor() {
13
- super();
14
- this.speechSynthesis = null;
15
- if ('speechSynthesis' in window) {
16
- this.speechSynthesis = window.speechSynthesis;
17
- window.addEventListener('beforeunload', () => {
18
- this.stop();
19
- });
20
- }
21
- }
22
- async speak(options) {
23
- if (!this.speechSynthesis) {
24
- this.throwUnsupportedError();
25
- }
26
- await this.stop();
27
- const speechSynthesis = this.speechSynthesis;
28
- const utterance = this.createSpeechSynthesisUtterance(options);
29
- return new Promise((resolve, reject) => {
30
- utterance.onend = () => {
31
- resolve();
32
- };
33
- utterance.onerror = (event) => {
34
- reject(event);
35
- };
36
- speechSynthesis.speak(utterance);
37
- });
38
- }
39
- async stop() {
40
- if (!this.speechSynthesis) {
41
- this.throwUnsupportedError();
42
- }
43
- this.speechSynthesis.cancel();
44
- }
45
- async getSupportedLanguages() {
46
- const voices = this.getSpeechSynthesisVoices();
47
- const languages = voices.map(voice => voice.lang);
48
- const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
49
- return { languages: filteredLanguages };
50
- }
51
- async getSupportedVoices() {
52
- const voices = this.getSpeechSynthesisVoices();
53
- return { voices };
54
- }
55
- async isLanguageSupported(options) {
56
- const result = await this.getSupportedLanguages();
57
- const isLanguageSupported = result.languages.includes(options.lang);
58
- return { supported: isLanguageSupported };
59
- }
60
- async openInstall() {
61
- this.throwUnimplementedError();
62
- }
63
- createSpeechSynthesisUtterance(options) {
64
- const voices = this.getSpeechSynthesisVoices();
65
- const utterance = new SpeechSynthesisUtterance();
66
- const { text, lang, rate, pitch, volume, voice } = options;
67
- if (voice) {
68
- utterance.voice = voices[voice];
69
- }
70
- if (volume) {
71
- utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
72
- }
73
- if (rate) {
74
- utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
75
- }
76
- if (pitch) {
77
- utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
78
- }
79
- if (lang) {
80
- utterance.lang = lang;
81
- }
82
- utterance.text = text;
83
- return utterance;
84
- }
85
- getSpeechSynthesisVoices() {
86
- if (!this.speechSynthesis) {
87
- this.throwUnsupportedError();
88
- }
89
- if (!this.supportedVoices || this.supportedVoices.length < 1) {
90
- this.supportedVoices = this.speechSynthesis.getVoices();
91
- }
92
- return this.supportedVoices;
93
- }
94
- throwUnsupportedError() {
95
- throw this.unavailable('SpeechSynthesis API not available in this browser.');
96
- }
97
- throwUnimplementedError() {
98
- throw this.unimplemented('Not implemented on web.');
99
- }
11
+ class TextToSpeechWeb extends core.WebPlugin {
12
+ constructor() {
13
+ super();
14
+ this.speechSynthesis = null;
15
+ if ('speechSynthesis' in window) {
16
+ this.speechSynthesis = window.speechSynthesis;
17
+ window.addEventListener('beforeunload', () => {
18
+ this.stop();
19
+ });
20
+ }
21
+ }
22
+ async speak(options) {
23
+ if (!this.speechSynthesis) {
24
+ this.throwUnsupportedError();
25
+ }
26
+ await this.stop();
27
+ const speechSynthesis = this.speechSynthesis;
28
+ const utterance = this.createSpeechSynthesisUtterance(options);
29
+ return new Promise((resolve, reject) => {
30
+ utterance.onend = () => {
31
+ resolve();
32
+ };
33
+ utterance.onerror = (event) => {
34
+ reject(event);
35
+ };
36
+ speechSynthesis.speak(utterance);
37
+ });
38
+ }
39
+ async stop() {
40
+ if (!this.speechSynthesis) {
41
+ this.throwUnsupportedError();
42
+ }
43
+ this.speechSynthesis.cancel();
44
+ }
45
+ async getSupportedLanguages() {
46
+ const voices = this.getSpeechSynthesisVoices();
47
+ const languages = voices.map(voice => voice.lang);
48
+ const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
49
+ return { languages: filteredLanguages };
50
+ }
51
+ async getSupportedVoices() {
52
+ const voices = this.getSpeechSynthesisVoices();
53
+ return { voices };
54
+ }
55
+ async isLanguageSupported(options) {
56
+ const result = await this.getSupportedLanguages();
57
+ const isLanguageSupported = result.languages.includes(options.lang);
58
+ return { supported: isLanguageSupported };
59
+ }
60
+ async openInstall() {
61
+ this.throwUnimplementedError();
62
+ }
63
+ createSpeechSynthesisUtterance(options) {
64
+ const voices = this.getSpeechSynthesisVoices();
65
+ const utterance = new SpeechSynthesisUtterance();
66
+ const { text, lang, rate, pitch, volume, voice } = options;
67
+ if (voice) {
68
+ utterance.voice = voices[voice];
69
+ }
70
+ if (volume) {
71
+ utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
72
+ }
73
+ if (rate) {
74
+ utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
75
+ }
76
+ if (pitch) {
77
+ utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
78
+ }
79
+ if (lang) {
80
+ utterance.lang = lang;
81
+ }
82
+ utterance.text = text;
83
+ return utterance;
84
+ }
85
+ getSpeechSynthesisVoices() {
86
+ if (!this.speechSynthesis) {
87
+ this.throwUnsupportedError();
88
+ }
89
+ if (!this.supportedVoices || this.supportedVoices.length < 1) {
90
+ this.supportedVoices = this.speechSynthesis.getVoices();
91
+ }
92
+ return this.supportedVoices;
93
+ }
94
+ throwUnsupportedError() {
95
+ throw this.unavailable('SpeechSynthesis API not available in this browser.');
96
+ }
97
+ throwUnimplementedError() {
98
+ throw this.unimplemented('Not implemented on web.');
99
+ }
100
100
  }
101
101
 
102
102
  var web = /*#__PURE__*/Object.freeze({
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\r\nconst TextToSpeech = registerPlugin('TextToSpeech', {\r\n web: () => import('./web').then(m => new m.TextToSpeechWeb()),\r\n});\r\n// Warm up\r\nif ('speechSynthesis' in window) {\r\n window.speechSynthesis;\r\n}\r\nexport * from './definitions';\r\nexport { TextToSpeech };\r\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\r\nexport class TextToSpeechWeb extends WebPlugin {\r\n constructor() {\r\n super();\r\n this.speechSynthesis = null;\r\n if ('speechSynthesis' in window) {\r\n this.speechSynthesis = window.speechSynthesis;\r\n window.addEventListener('beforeunload', () => {\r\n this.stop();\r\n });\r\n }\r\n }\r\n async speak(options) {\r\n if (!this.speechSynthesis) {\r\n this.throwUnsupportedError();\r\n }\r\n await this.stop();\r\n const speechSynthesis = this.speechSynthesis;\r\n const utterance = this.createSpeechSynthesisUtterance(options);\r\n return new Promise((resolve, reject) => {\r\n utterance.onend = () => {\r\n resolve();\r\n };\r\n utterance.onerror = (event) => {\r\n reject(event);\r\n };\r\n speechSynthesis.speak(utterance);\r\n });\r\n }\r\n async stop() {\r\n if (!this.speechSynthesis) {\r\n this.throwUnsupportedError();\r\n }\r\n this.speechSynthesis.cancel();\r\n }\r\n async getSupportedLanguages() {\r\n const voices = this.getSpeechSynthesisVoices();\r\n const languages = voices.map(voice => voice.lang);\r\n const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);\r\n return { languages: filteredLanguages };\r\n }\r\n async getSupportedVoices() {\r\n const voices = this.getSpeechSynthesisVoices();\r\n return { voices };\r\n }\r\n async isLanguageSupported(options) {\r\n const result = await this.getSupportedLanguages();\r\n const isLanguageSupported = result.languages.includes(options.lang);\r\n return { supported: isLanguageSupported };\r\n }\r\n async openInstall() {\r\n this.throwUnimplementedError();\r\n }\r\n createSpeechSynthesisUtterance(options) {\r\n const voices = this.getSpeechSynthesisVoices();\r\n const utterance = new SpeechSynthesisUtterance();\r\n const { text, lang, rate, pitch, volume, voice } = options;\r\n if (voice) {\r\n utterance.voice = voices[voice];\r\n }\r\n if (volume) {\r\n utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;\r\n }\r\n if (rate) {\r\n utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;\r\n }\r\n if (pitch) {\r\n utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;\r\n }\r\n if (lang) {\r\n utterance.lang = lang;\r\n }\r\n utterance.text = text;\r\n return utterance;\r\n }\r\n getSpeechSynthesisVoices() {\r\n if (!this.speechSynthesis) {\r\n this.throwUnsupportedError();\r\n }\r\n if (!this.supportedVoices || this.supportedVoices.length < 1) {\r\n this.supportedVoices = this.speechSynthesis.getVoices();\r\n }\r\n return this.supportedVoices;\r\n }\r\n throwUnsupportedError() {\r\n throw this.unavailable('SpeechSynthesis API not available in this browser.');\r\n }\r\n throwUnimplementedError() {\r\n throw this.unimplemented('Not implemented on web.');\r\n }\r\n}\r\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACjE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE,CAAC;AAChB,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;AACpC,QAAQ,IAAI,iBAAiB,IAAI,MAAM,EAAE;AACzC,YAAY,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;AAC1D,YAAY,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,MAAM;AAC1D,gBAAgB,IAAI,CAAC,IAAI,EAAE,CAAC;AAC5B,aAAa,CAAC,CAAC;AACf,SAAS;AACT,KAAK;AACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;AACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;AACzC,SAAS;AACT,QAAQ,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;AAC1B,QAAQ,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACrD,QAAQ,MAAM,SAAS,GAAG,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC;AACvE,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAChD,YAAY,SAAS,CAAC,KAAK,GAAG,MAAM;AACpC,gBAAgB,OAAO,EAAE,CAAC;AAC1B,aAAa,CAAC;AACd,YAAY,SAAS,CAAC,OAAO,G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AC;AACzC,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;AACtE,YAAY,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;AACpE,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC,eAAe,CAAC;AACpC,KAAK;AACL,IAAI,qBAAqB,GAAG;AAC5B,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,oDAAoD,CAAC,CAAC;AACrF,KAAK;AACL,IAAI,uBAAuB,GAAG;AAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;AAC5D,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst TextToSpeech = registerPlugin('TextToSpeech', {\n web: () => import('./web').then(m => new m.TextToSpeechWeb()),\n});\n// Warm up\nif ('speechSynthesis' in window) {\n window.speechSynthesis;\n}\nexport * from './definitions';\nexport { TextToSpeech };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class TextToSpeechWeb extends WebPlugin {\n constructor() {\n super();\n this.speechSynthesis = null;\n if ('speechSynthesis' in window) {\n this.speechSynthesis = window.speechSynthesis;\n window.addEventListener('beforeunload', () => {\n this.stop();\n });\n }\n }\n async speak(options) {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n await this.stop();\n const speechSynthesis = this.speechSynthesis;\n const utterance = this.createSpeechSynthesisUtterance(options);\n return new Promise((resolve, reject) => {\n utterance.onend = () => {\n resolve();\n };\n utterance.onerror = (event) => {\n reject(event);\n };\n speechSynthesis.speak(utterance);\n });\n }\n async stop() {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n this.speechSynthesis.cancel();\n }\n async getSupportedLanguages() {\n const voices = this.getSpeechSynthesisVoices();\n const languages = voices.map(voice => voice.lang);\n const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);\n return { languages: filteredLanguages };\n }\n async getSupportedVoices() {\n const voices = this.getSpeechSynthesisVoices();\n return { voices };\n }\n async isLanguageSupported(options) {\n const result = await this.getSupportedLanguages();\n const isLanguageSupported = result.languages.includes(options.lang);\n return { supported: isLanguageSupported };\n }\n async openInstall() {\n this.throwUnimplementedError();\n }\n createSpeechSynthesisUtterance(options) {\n const voices = this.getSpeechSynthesisVoices();\n const utterance = new SpeechSynthesisUtterance();\n const { text, lang, rate, pitch, volume, voice } = options;\n if (voice) {\n utterance.voice = voices[voice];\n }\n if (volume) {\n utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;\n }\n if (rate) {\n utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;\n }\n if (pitch) {\n utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;\n }\n if (lang) {\n utterance.lang = lang;\n }\n utterance.text = text;\n return utterance;\n }\n getSpeechSynthesisVoices() {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n if (!this.supportedVoices || this.supportedVoices.length < 1) {\n this.supportedVoices = this.speechSynthesis.getVoices();\n }\n return this.supportedVoices;\n }\n throwUnsupportedError() {\n throw this.unavailable('SpeechSynthesis API not available in this browser.');\n }\n throwUnimplementedError() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACjE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE,CAAC;AAChB,QAAQ,IAAI,CAAC,eAAe,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AC,CAAC;AAC5D,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -1,99 +1,99 @@
1
1
  var capacitorTextToSpeech = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
- const TextToSpeech = core.registerPlugin('TextToSpeech', {
5
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()),
4
+ const TextToSpeech = core.registerPlugin('TextToSpeech', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()),
6
6
  });
7
7
 
8
- class TextToSpeechWeb extends core.WebPlugin {
9
- constructor() {
10
- super();
11
- this.speechSynthesis = null;
12
- if ('speechSynthesis' in window) {
13
- this.speechSynthesis = window.speechSynthesis;
14
- window.addEventListener('beforeunload', () => {
15
- this.stop();
16
- });
17
- }
18
- }
19
- async speak(options) {
20
- if (!this.speechSynthesis) {
21
- this.throwUnsupportedError();
22
- }
23
- await this.stop();
24
- const speechSynthesis = this.speechSynthesis;
25
- const utterance = this.createSpeechSynthesisUtterance(options);
26
- return new Promise((resolve, reject) => {
27
- utterance.onend = () => {
28
- resolve();
29
- };
30
- utterance.onerror = (event) => {
31
- reject(event);
32
- };
33
- speechSynthesis.speak(utterance);
34
- });
35
- }
36
- async stop() {
37
- if (!this.speechSynthesis) {
38
- this.throwUnsupportedError();
39
- }
40
- this.speechSynthesis.cancel();
41
- }
42
- async getSupportedLanguages() {
43
- const voices = this.getSpeechSynthesisVoices();
44
- const languages = voices.map(voice => voice.lang);
45
- const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
46
- return { languages: filteredLanguages };
47
- }
48
- async getSupportedVoices() {
49
- const voices = this.getSpeechSynthesisVoices();
50
- return { voices };
51
- }
52
- async isLanguageSupported(options) {
53
- const result = await this.getSupportedLanguages();
54
- const isLanguageSupported = result.languages.includes(options.lang);
55
- return { supported: isLanguageSupported };
56
- }
57
- async openInstall() {
58
- this.throwUnimplementedError();
59
- }
60
- createSpeechSynthesisUtterance(options) {
61
- const voices = this.getSpeechSynthesisVoices();
62
- const utterance = new SpeechSynthesisUtterance();
63
- const { text, lang, rate, pitch, volume, voice } = options;
64
- if (voice) {
65
- utterance.voice = voices[voice];
66
- }
67
- if (volume) {
68
- utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
69
- }
70
- if (rate) {
71
- utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
72
- }
73
- if (pitch) {
74
- utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
75
- }
76
- if (lang) {
77
- utterance.lang = lang;
78
- }
79
- utterance.text = text;
80
- return utterance;
81
- }
82
- getSpeechSynthesisVoices() {
83
- if (!this.speechSynthesis) {
84
- this.throwUnsupportedError();
85
- }
86
- if (!this.supportedVoices || this.supportedVoices.length < 1) {
87
- this.supportedVoices = this.speechSynthesis.getVoices();
88
- }
89
- return this.supportedVoices;
90
- }
91
- throwUnsupportedError() {
92
- throw this.unavailable('SpeechSynthesis API not available in this browser.');
93
- }
94
- throwUnimplementedError() {
95
- throw this.unimplemented('Not implemented on web.');
96
- }
8
+ class TextToSpeechWeb extends core.WebPlugin {
9
+ constructor() {
10
+ super();
11
+ this.speechSynthesis = null;
12
+ if ('speechSynthesis' in window) {
13
+ this.speechSynthesis = window.speechSynthesis;
14
+ window.addEventListener('beforeunload', () => {
15
+ this.stop();
16
+ });
17
+ }
18
+ }
19
+ async speak(options) {
20
+ if (!this.speechSynthesis) {
21
+ this.throwUnsupportedError();
22
+ }
23
+ await this.stop();
24
+ const speechSynthesis = this.speechSynthesis;
25
+ const utterance = this.createSpeechSynthesisUtterance(options);
26
+ return new Promise((resolve, reject) => {
27
+ utterance.onend = () => {
28
+ resolve();
29
+ };
30
+ utterance.onerror = (event) => {
31
+ reject(event);
32
+ };
33
+ speechSynthesis.speak(utterance);
34
+ });
35
+ }
36
+ async stop() {
37
+ if (!this.speechSynthesis) {
38
+ this.throwUnsupportedError();
39
+ }
40
+ this.speechSynthesis.cancel();
41
+ }
42
+ async getSupportedLanguages() {
43
+ const voices = this.getSpeechSynthesisVoices();
44
+ const languages = voices.map(voice => voice.lang);
45
+ const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
46
+ return { languages: filteredLanguages };
47
+ }
48
+ async getSupportedVoices() {
49
+ const voices = this.getSpeechSynthesisVoices();
50
+ return { voices };
51
+ }
52
+ async isLanguageSupported(options) {
53
+ const result = await this.getSupportedLanguages();
54
+ const isLanguageSupported = result.languages.includes(options.lang);
55
+ return { supported: isLanguageSupported };
56
+ }
57
+ async openInstall() {
58
+ this.throwUnimplementedError();
59
+ }
60
+ createSpeechSynthesisUtterance(options) {
61
+ const voices = this.getSpeechSynthesisVoices();
62
+ const utterance = new SpeechSynthesisUtterance();
63
+ const { text, lang, rate, pitch, volume, voice } = options;
64
+ if (voice) {
65
+ utterance.voice = voices[voice];
66
+ }
67
+ if (volume) {
68
+ utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
69
+ }
70
+ if (rate) {
71
+ utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
72
+ }
73
+ if (pitch) {
74
+ utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
75
+ }
76
+ if (lang) {
77
+ utterance.lang = lang;
78
+ }
79
+ utterance.text = text;
80
+ return utterance;
81
+ }
82
+ getSpeechSynthesisVoices() {
83
+ if (!this.speechSynthesis) {
84
+ this.throwUnsupportedError();
85
+ }
86
+ if (!this.supportedVoices || this.supportedVoices.length < 1) {
87
+ this.supportedVoices = this.speechSynthesis.getVoices();
88
+ }
89
+ return this.supportedVoices;
90
+ }
91
+ throwUnsupportedError() {
92
+ throw this.unavailable('SpeechSynthesis API not available in this browser.');
93
+ }
94
+ throwUnimplementedError() {
95
+ throw this.unimplemented('Not implemented on web.');
96
+ }
97
97
  }
98
98
 
99
99
  var web = /*#__PURE__*/Object.freeze({