@capgo/capacitor-speech-synthesis 7.0.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.
@@ -0,0 +1,153 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class SpeechSynthesisWeb extends WebPlugin {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.utteranceIdCounter = 0;
6
+ this.currentUtterances = new Map();
7
+ }
8
+ async speak(options) {
9
+ if (!('speechSynthesis' in window)) {
10
+ throw new Error('Speech synthesis not supported in this browser');
11
+ }
12
+ const utteranceId = `web-utterance-${++this.utteranceIdCounter}`;
13
+ const utterance = new SpeechSynthesisUtterance(options.text);
14
+ // Set voice if specified
15
+ if (options.voiceId) {
16
+ const voices = window.speechSynthesis.getVoices();
17
+ const voice = voices.find((v) => v.voiceURI === options.voiceId || v.name === options.voiceId);
18
+ if (voice) {
19
+ utterance.voice = voice;
20
+ }
21
+ }
22
+ else if (options.language) {
23
+ const voices = window.speechSynthesis.getVoices();
24
+ const voice = voices.find((v) => v.lang === options.language);
25
+ if (voice) {
26
+ utterance.voice = voice;
27
+ }
28
+ utterance.lang = options.language;
29
+ }
30
+ // Set speech parameters
31
+ if (options.pitch !== undefined) {
32
+ utterance.pitch = Math.max(0, Math.min(2, options.pitch));
33
+ }
34
+ if (options.rate !== undefined) {
35
+ utterance.rate = Math.max(0.1, Math.min(10, options.rate));
36
+ }
37
+ if (options.volume !== undefined) {
38
+ utterance.volume = Math.max(0, Math.min(1, options.volume));
39
+ }
40
+ // Set up event listeners
41
+ utterance.onstart = () => {
42
+ this.notifyListeners('start', { utteranceId });
43
+ };
44
+ utterance.onend = () => {
45
+ this.currentUtterances.delete(utteranceId);
46
+ this.notifyListeners('end', { utteranceId });
47
+ };
48
+ utterance.onboundary = (event) => {
49
+ this.notifyListeners('boundary', {
50
+ utteranceId,
51
+ charIndex: event.charIndex,
52
+ charLength: event.charLength,
53
+ });
54
+ };
55
+ utterance.onerror = (event) => {
56
+ this.currentUtterances.delete(utteranceId);
57
+ this.notifyListeners('error', {
58
+ utteranceId,
59
+ error: event.error || 'Unknown error',
60
+ });
61
+ };
62
+ // Handle queue strategy
63
+ if (options.queueStrategy === 'Flush') {
64
+ window.speechSynthesis.cancel();
65
+ this.currentUtterances.clear();
66
+ }
67
+ this.currentUtterances.set(utteranceId, utterance);
68
+ window.speechSynthesis.speak(utterance);
69
+ return { utteranceId };
70
+ }
71
+ async synthesizeToFile(_options) {
72
+ throw new Error('synthesizeToFile is not supported on web platform');
73
+ }
74
+ async cancel() {
75
+ if ('speechSynthesis' in window) {
76
+ window.speechSynthesis.cancel();
77
+ this.currentUtterances.clear();
78
+ }
79
+ }
80
+ async pause() {
81
+ if ('speechSynthesis' in window) {
82
+ window.speechSynthesis.pause();
83
+ }
84
+ }
85
+ async resume() {
86
+ if ('speechSynthesis' in window) {
87
+ window.speechSynthesis.resume();
88
+ }
89
+ }
90
+ async isSpeaking() {
91
+ if ('speechSynthesis' in window) {
92
+ return { isSpeaking: window.speechSynthesis.speaking };
93
+ }
94
+ return { isSpeaking: false };
95
+ }
96
+ async isAvailable() {
97
+ return { isAvailable: 'speechSynthesis' in window };
98
+ }
99
+ async getVoices() {
100
+ if (!('speechSynthesis' in window)) {
101
+ return { voices: [] };
102
+ }
103
+ const webVoices = window.speechSynthesis.getVoices();
104
+ const voices = webVoices.map((voice) => ({
105
+ id: voice.voiceURI,
106
+ name: voice.name,
107
+ language: voice.lang,
108
+ isNetworkConnectionRequired: !voice.localService,
109
+ default: voice.default,
110
+ }));
111
+ return { voices };
112
+ }
113
+ async getLanguages() {
114
+ if (!('speechSynthesis' in window)) {
115
+ return { languages: [] };
116
+ }
117
+ const webVoices = window.speechSynthesis.getVoices();
118
+ const languages = Array.from(new Set(webVoices.map((voice) => voice.lang)));
119
+ return { languages };
120
+ }
121
+ async isLanguageAvailable(options) {
122
+ if (!('speechSynthesis' in window)) {
123
+ return { isAvailable: false };
124
+ }
125
+ const webVoices = window.speechSynthesis.getVoices();
126
+ const isAvailable = webVoices.some((voice) => voice.lang === options.language);
127
+ return { isAvailable };
128
+ }
129
+ async isVoiceAvailable(options) {
130
+ if (!('speechSynthesis' in window)) {
131
+ return { isAvailable: false };
132
+ }
133
+ const webVoices = window.speechSynthesis.getVoices();
134
+ const isAvailable = webVoices.some((voice) => voice.voiceURI === options.voiceId || voice.name === options.voiceId);
135
+ return { isAvailable };
136
+ }
137
+ async initialize() {
138
+ // Pre-load voices on web
139
+ if ('speechSynthesis' in window) {
140
+ window.speechSynthesis.getVoices();
141
+ }
142
+ }
143
+ async activateAudioSession(_options) {
144
+ // Not applicable on web
145
+ }
146
+ async deactivateAudioSession() {
147
+ // Not applicable on web
148
+ }
149
+ async getPluginVersion() {
150
+ return { version: 'web' };
151
+ }
152
+ }
153
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa5C,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAAjD;;QACU,uBAAkB,GAAG,CAAC,CAAC;QACvB,sBAAiB,GAAG,IAAI,GAAG,EAAoC,CAAC;IAiL1E,CAAC;IA/KC,KAAK,CAAC,KAAK,CAAC,OAAqB;QAC/B,IAAI,CAAC,CAAC,iBAAiB,IAAI,MAAM,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,WAAW,GAAG,iBAAiB,EAAE,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACjE,MAAM,SAAS,GAAG,IAAI,wBAAwB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAE7D,yBAAyB;QACzB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;Y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AAS,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;QACrD,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpH,OAAO,EAAE,WAAW,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,yBAAyB;QACzB,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAAC;YAChC,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,QAAqC;QAC9D,wBAAwB;IAC1B,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,wBAAwB;IAC1B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const SpeechSynthesis = core.registerPlugin('SpeechSynthesis', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SpeechSynthesisWeb()),
7
+ });
8
+
9
+ class SpeechSynthesisWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.utteranceIdCounter = 0;
13
+ this.currentUtterances = new Map();
14
+ }
15
+ async speak(options) {
16
+ if (!('speechSynthesis' in window)) {
17
+ throw new Error('Speech synthesis not supported in this browser');
18
+ }
19
+ const utteranceId = `web-utterance-${++this.utteranceIdCounter}`;
20
+ const utterance = new SpeechSynthesisUtterance(options.text);
21
+ // Set voice if specified
22
+ if (options.voiceId) {
23
+ const voices = window.speechSynthesis.getVoices();
24
+ const voice = voices.find((v) => v.voiceURI === options.voiceId || v.name === options.voiceId);
25
+ if (voice) {
26
+ utterance.voice = voice;
27
+ }
28
+ }
29
+ else if (options.language) {
30
+ const voices = window.speechSynthesis.getVoices();
31
+ const voice = voices.find((v) => v.lang === options.language);
32
+ if (voice) {
33
+ utterance.voice = voice;
34
+ }
35
+ utterance.lang = options.language;
36
+ }
37
+ // Set speech parameters
38
+ if (options.pitch !== undefined) {
39
+ utterance.pitch = Math.max(0, Math.min(2, options.pitch));
40
+ }
41
+ if (options.rate !== undefined) {
42
+ utterance.rate = Math.max(0.1, Math.min(10, options.rate));
43
+ }
44
+ if (options.volume !== undefined) {
45
+ utterance.volume = Math.max(0, Math.min(1, options.volume));
46
+ }
47
+ // Set up event listeners
48
+ utterance.onstart = () => {
49
+ this.notifyListeners('start', { utteranceId });
50
+ };
51
+ utterance.onend = () => {
52
+ this.currentUtterances.delete(utteranceId);
53
+ this.notifyListeners('end', { utteranceId });
54
+ };
55
+ utterance.onboundary = (event) => {
56
+ this.notifyListeners('boundary', {
57
+ utteranceId,
58
+ charIndex: event.charIndex,
59
+ charLength: event.charLength,
60
+ });
61
+ };
62
+ utterance.onerror = (event) => {
63
+ this.currentUtterances.delete(utteranceId);
64
+ this.notifyListeners('error', {
65
+ utteranceId,
66
+ error: event.error || 'Unknown error',
67
+ });
68
+ };
69
+ // Handle queue strategy
70
+ if (options.queueStrategy === 'Flush') {
71
+ window.speechSynthesis.cancel();
72
+ this.currentUtterances.clear();
73
+ }
74
+ this.currentUtterances.set(utteranceId, utterance);
75
+ window.speechSynthesis.speak(utterance);
76
+ return { utteranceId };
77
+ }
78
+ async synthesizeToFile(_options) {
79
+ throw new Error('synthesizeToFile is not supported on web platform');
80
+ }
81
+ async cancel() {
82
+ if ('speechSynthesis' in window) {
83
+ window.speechSynthesis.cancel();
84
+ this.currentUtterances.clear();
85
+ }
86
+ }
87
+ async pause() {
88
+ if ('speechSynthesis' in window) {
89
+ window.speechSynthesis.pause();
90
+ }
91
+ }
92
+ async resume() {
93
+ if ('speechSynthesis' in window) {
94
+ window.speechSynthesis.resume();
95
+ }
96
+ }
97
+ async isSpeaking() {
98
+ if ('speechSynthesis' in window) {
99
+ return { isSpeaking: window.speechSynthesis.speaking };
100
+ }
101
+ return { isSpeaking: false };
102
+ }
103
+ async isAvailable() {
104
+ return { isAvailable: 'speechSynthesis' in window };
105
+ }
106
+ async getVoices() {
107
+ if (!('speechSynthesis' in window)) {
108
+ return { voices: [] };
109
+ }
110
+ const webVoices = window.speechSynthesis.getVoices();
111
+ const voices = webVoices.map((voice) => ({
112
+ id: voice.voiceURI,
113
+ name: voice.name,
114
+ language: voice.lang,
115
+ isNetworkConnectionRequired: !voice.localService,
116
+ default: voice.default,
117
+ }));
118
+ return { voices };
119
+ }
120
+ async getLanguages() {
121
+ if (!('speechSynthesis' in window)) {
122
+ return { languages: [] };
123
+ }
124
+ const webVoices = window.speechSynthesis.getVoices();
125
+ const languages = Array.from(new Set(webVoices.map((voice) => voice.lang)));
126
+ return { languages };
127
+ }
128
+ async isLanguageAvailable(options) {
129
+ if (!('speechSynthesis' in window)) {
130
+ return { isAvailable: false };
131
+ }
132
+ const webVoices = window.speechSynthesis.getVoices();
133
+ const isAvailable = webVoices.some((voice) => voice.lang === options.language);
134
+ return { isAvailable };
135
+ }
136
+ async isVoiceAvailable(options) {
137
+ if (!('speechSynthesis' in window)) {
138
+ return { isAvailable: false };
139
+ }
140
+ const webVoices = window.speechSynthesis.getVoices();
141
+ const isAvailable = webVoices.some((voice) => voice.voiceURI === options.voiceId || voice.name === options.voiceId);
142
+ return { isAvailable };
143
+ }
144
+ async initialize() {
145
+ // Pre-load voices on web
146
+ if ('speechSynthesis' in window) {
147
+ window.speechSynthesis.getVoices();
148
+ }
149
+ }
150
+ async activateAudioSession(_options) {
151
+ // Not applicable on web
152
+ }
153
+ async deactivateAudioSession() {
154
+ // Not applicable on web
155
+ }
156
+ async getPluginVersion() {
157
+ return { version: 'web' };
158
+ }
159
+ }
160
+
161
+ var web = /*#__PURE__*/Object.freeze({
162
+ __proto__: null,
163
+ SpeechSynthesisWeb: SpeechSynthesisWeb
164
+ });
165
+
166
+ exports.SpeechSynthesis = SpeechSynthesis;
167
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SpeechSynthesis = registerPlugin('SpeechSynthesis', {\n web: () => import('./web').then((m) => new m.SpeechSynthesisWeb()),\n});\nexport * from './definitions';\nexport { SpeechSynthesis };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class SpeechSynthesisWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.utteranceIdCounter = 0;\n this.currentUtterances = new Map();\n }\n async speak(options) {\n if (!('speechSynthesis' in window)) {\n throw new Error('Speech synthesis not supported in this browser');\n }\n const utteranceId = `web-utterance-${++this.utteranceIdCounter}`;\n const utterance = new SpeechSynthesisUtterance(options.text);\n // Set voice if specified\n if (options.voiceId) {\n const voices = window.speechSynthesis.getVoices();\n const voice = voices.find((v) => v.voiceURI === options.voiceId || v.name === options.voiceId);\n if (voice) {\n utterance.voice = voice;\n }\n }\n else if (options.language) {\n const voices = window.speechSynthesis.getVoices();\n const voice = voices.find((v) => v.lang === options.language);\n if (voice) {\n utterance.voice = voice;\n }\n utterance.lang = options.language;\n }\n // Set speech parameters\n if (options.pitch !== undefined) {\n utterance.pitch = Math.max(0, Math.min(2, options.pitch));\n }\n if (options.rate !== undefined) {\n utterance.rate = Math.max(0.1, Math.min(10, options.rate));\n }\n if (options.volume !== undefined) {\n utterance.volume = Math.max(0, Math.min(1, options.volume));\n }\n // Set up event listeners\n utterance.onstart = () => {\n this.notifyListeners('start', { utteranceId });\n };\n utterance.onend = () => {\n this.currentUtterances.delete(utteranceId);\n this.notifyListeners('end', { utteranceId });\n };\n utterance.onboundary = (event) => {\n this.notifyListeners('boundary', {\n utteranceId,\n charIndex: event.charIndex,\n charLength: event.charLength,\n });\n };\n utterance.onerror = (event) => {\n this.currentUtterances.delete(utteranceId);\n this.notifyListeners('error', {\n utteranceId,\n error: event.error || 'Unknown error',\n });\n };\n // Handle queue strategy\n if (options.queueStrategy === 'Flush') {\n window.speechSynthesis.cancel();\n this.currentUtterances.clear();\n }\n this.currentUtterances.set(utteranceId, utterance);\n window.speechSynthesis.speak(utterance);\n return { utteranceId };\n }\n async synthesizeToFile(_options) {\n throw new Error('synthesizeToFile is not supported on web platform');\n }\n async cancel() {\n if ('speechSynthesis' in window) {\n window.speechSynthesis.cancel();\n this.currentUtterances.clear();\n }\n }\n async pause() {\n if ('speechSynthesis' in window) {\n window.speechSynthesis.pause();\n }\n }\n async resume() {\n if ('speechSynthesis' in window) {\n window.speechSynthesis.resume();\n }\n }\n async isSpeaking() {\n if ('speechSynthesis' in window) {\n return { isSpeaking: window.speechSynthesis.speaking };\n }\n return { isSpeaking: false };\n }\n async isAvailable() {\n return { isAvailable: 'speechSynthesis' in window };\n }\n async getVoices() {\n if (!('speechSynthesis' in window)) {\n return { voices: [] };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const voices = webVoices.map((voice) => ({\n id: voice.voiceURI,\n name: voice.name,\n language: voice.lang,\n isNetworkConnectionRequired: !voice.localService,\n default: voice.default,\n }));\n return { voices };\n }\n async getLanguages() {\n if (!('speechSynthesis' in window)) {\n return { languages: [] };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const languages = Array.from(new Set(webVoices.map((voice) => voice.lang)));\n return { languages };\n }\n async isLanguageAvailable(options) {\n if (!('speechSynthesis' in window)) {\n return { isAvailable: false };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const isAvailable = webVoices.some((voice) => voice.lang === options.language);\n return { isAvailable };\n }\n async isVoiceAvailable(options) {\n if (!('speechSynthesis' in window)) {\n return { isAvailable: false };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const isAvailable = webVoices.some((voice) => voice.voiceURI === options.voiceId || voice.name === options.voiceId);\n return { isAvailable };\n }\n async initialize() {\n // Pre-load voices on web\n if ('speechSynthesis' in window) {\n window.speechSynthesis.getVoices();\n }\n }\n async activateAudioSession(_options) {\n // Not applicable on web\n }\n async deactivateAudioSession() {\n // Not applicable on web\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,eAAe,GAAGA,mBAAc,CAAC,iBAAiB,EAAE;AAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACtE,CAAC;;ACFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;AAClD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,kBAAkB,GAAG,CAAC;AACnC,QAAQ,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE;AAC1C,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,EAAE,iBAAiB,IAAI,MAAM,CAAC,EAAE;AAC5C,YAAY,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC;AAC7E,QAAQ;AACR,QAAQ,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACxE,QAAQ,MAAM,SAAS,GAAG,IAAI,wBAAwB,CAAC,OAAO,CAAC,IAAI,CAAC;AACpE;AACA,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE;AAC7B,YAAY,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE;AAC7D,YAAY,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,C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EAAE;AAC5D,QAAQ,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC;AAC3H,QAAQ,OAAO,EAAE,WAAW,EAAE;AAC9B,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB;AACA,QAAQ,IAAI,iBAAiB,IAAI,MAAM,EAAE;AACzC,YAAY,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE;AAC9C,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,oBAAoB,CAAC,QAAQ,EAAE;AACzC;AACA,IAAI;AACJ,IAAI,MAAM,sBAAsB,GAAG;AACnC;AACA,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,170 @@
1
+ var capacitorSpeechSynthesis = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const SpeechSynthesis = core.registerPlugin('SpeechSynthesis', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SpeechSynthesisWeb()),
6
+ });
7
+
8
+ class SpeechSynthesisWeb extends core.WebPlugin {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.utteranceIdCounter = 0;
12
+ this.currentUtterances = new Map();
13
+ }
14
+ async speak(options) {
15
+ if (!('speechSynthesis' in window)) {
16
+ throw new Error('Speech synthesis not supported in this browser');
17
+ }
18
+ const utteranceId = `web-utterance-${++this.utteranceIdCounter}`;
19
+ const utterance = new SpeechSynthesisUtterance(options.text);
20
+ // Set voice if specified
21
+ if (options.voiceId) {
22
+ const voices = window.speechSynthesis.getVoices();
23
+ const voice = voices.find((v) => v.voiceURI === options.voiceId || v.name === options.voiceId);
24
+ if (voice) {
25
+ utterance.voice = voice;
26
+ }
27
+ }
28
+ else if (options.language) {
29
+ const voices = window.speechSynthesis.getVoices();
30
+ const voice = voices.find((v) => v.lang === options.language);
31
+ if (voice) {
32
+ utterance.voice = voice;
33
+ }
34
+ utterance.lang = options.language;
35
+ }
36
+ // Set speech parameters
37
+ if (options.pitch !== undefined) {
38
+ utterance.pitch = Math.max(0, Math.min(2, options.pitch));
39
+ }
40
+ if (options.rate !== undefined) {
41
+ utterance.rate = Math.max(0.1, Math.min(10, options.rate));
42
+ }
43
+ if (options.volume !== undefined) {
44
+ utterance.volume = Math.max(0, Math.min(1, options.volume));
45
+ }
46
+ // Set up event listeners
47
+ utterance.onstart = () => {
48
+ this.notifyListeners('start', { utteranceId });
49
+ };
50
+ utterance.onend = () => {
51
+ this.currentUtterances.delete(utteranceId);
52
+ this.notifyListeners('end', { utteranceId });
53
+ };
54
+ utterance.onboundary = (event) => {
55
+ this.notifyListeners('boundary', {
56
+ utteranceId,
57
+ charIndex: event.charIndex,
58
+ charLength: event.charLength,
59
+ });
60
+ };
61
+ utterance.onerror = (event) => {
62
+ this.currentUtterances.delete(utteranceId);
63
+ this.notifyListeners('error', {
64
+ utteranceId,
65
+ error: event.error || 'Unknown error',
66
+ });
67
+ };
68
+ // Handle queue strategy
69
+ if (options.queueStrategy === 'Flush') {
70
+ window.speechSynthesis.cancel();
71
+ this.currentUtterances.clear();
72
+ }
73
+ this.currentUtterances.set(utteranceId, utterance);
74
+ window.speechSynthesis.speak(utterance);
75
+ return { utteranceId };
76
+ }
77
+ async synthesizeToFile(_options) {
78
+ throw new Error('synthesizeToFile is not supported on web platform');
79
+ }
80
+ async cancel() {
81
+ if ('speechSynthesis' in window) {
82
+ window.speechSynthesis.cancel();
83
+ this.currentUtterances.clear();
84
+ }
85
+ }
86
+ async pause() {
87
+ if ('speechSynthesis' in window) {
88
+ window.speechSynthesis.pause();
89
+ }
90
+ }
91
+ async resume() {
92
+ if ('speechSynthesis' in window) {
93
+ window.speechSynthesis.resume();
94
+ }
95
+ }
96
+ async isSpeaking() {
97
+ if ('speechSynthesis' in window) {
98
+ return { isSpeaking: window.speechSynthesis.speaking };
99
+ }
100
+ return { isSpeaking: false };
101
+ }
102
+ async isAvailable() {
103
+ return { isAvailable: 'speechSynthesis' in window };
104
+ }
105
+ async getVoices() {
106
+ if (!('speechSynthesis' in window)) {
107
+ return { voices: [] };
108
+ }
109
+ const webVoices = window.speechSynthesis.getVoices();
110
+ const voices = webVoices.map((voice) => ({
111
+ id: voice.voiceURI,
112
+ name: voice.name,
113
+ language: voice.lang,
114
+ isNetworkConnectionRequired: !voice.localService,
115
+ default: voice.default,
116
+ }));
117
+ return { voices };
118
+ }
119
+ async getLanguages() {
120
+ if (!('speechSynthesis' in window)) {
121
+ return { languages: [] };
122
+ }
123
+ const webVoices = window.speechSynthesis.getVoices();
124
+ const languages = Array.from(new Set(webVoices.map((voice) => voice.lang)));
125
+ return { languages };
126
+ }
127
+ async isLanguageAvailable(options) {
128
+ if (!('speechSynthesis' in window)) {
129
+ return { isAvailable: false };
130
+ }
131
+ const webVoices = window.speechSynthesis.getVoices();
132
+ const isAvailable = webVoices.some((voice) => voice.lang === options.language);
133
+ return { isAvailable };
134
+ }
135
+ async isVoiceAvailable(options) {
136
+ if (!('speechSynthesis' in window)) {
137
+ return { isAvailable: false };
138
+ }
139
+ const webVoices = window.speechSynthesis.getVoices();
140
+ const isAvailable = webVoices.some((voice) => voice.voiceURI === options.voiceId || voice.name === options.voiceId);
141
+ return { isAvailable };
142
+ }
143
+ async initialize() {
144
+ // Pre-load voices on web
145
+ if ('speechSynthesis' in window) {
146
+ window.speechSynthesis.getVoices();
147
+ }
148
+ }
149
+ async activateAudioSession(_options) {
150
+ // Not applicable on web
151
+ }
152
+ async deactivateAudioSession() {
153
+ // Not applicable on web
154
+ }
155
+ async getPluginVersion() {
156
+ return { version: 'web' };
157
+ }
158
+ }
159
+
160
+ var web = /*#__PURE__*/Object.freeze({
161
+ __proto__: null,
162
+ SpeechSynthesisWeb: SpeechSynthesisWeb
163
+ });
164
+
165
+ exports.SpeechSynthesis = SpeechSynthesis;
166
+
167
+ return exports;
168
+
169
+ })({}, capacitorExports);
170
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SpeechSynthesis = registerPlugin('SpeechSynthesis', {\n web: () => import('./web').then((m) => new m.SpeechSynthesisWeb()),\n});\nexport * from './definitions';\nexport { SpeechSynthesis };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class SpeechSynthesisWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.utteranceIdCounter = 0;\n this.currentUtterances = new Map();\n }\n async speak(options) {\n if (!('speechSynthesis' in window)) {\n throw new Error('Speech synthesis not supported in this browser');\n }\n const utteranceId = `web-utterance-${++this.utteranceIdCounter}`;\n const utterance = new SpeechSynthesisUtterance(options.text);\n // Set voice if specified\n if (options.voiceId) {\n const voices = window.speechSynthesis.getVoices();\n const voice = voices.find((v) => v.voiceURI === options.voiceId || v.name === options.voiceId);\n if (voice) {\n utterance.voice = voice;\n }\n }\n else if (options.language) {\n const voices = window.speechSynthesis.getVoices();\n const voice = voices.find((v) => v.lang === options.language);\n if (voice) {\n utterance.voice = voice;\n }\n utterance.lang = options.language;\n }\n // Set speech parameters\n if (options.pitch !== undefined) {\n utterance.pitch = Math.max(0, Math.min(2, options.pitch));\n }\n if (options.rate !== undefined) {\n utterance.rate = Math.max(0.1, Math.min(10, options.rate));\n }\n if (options.volume !== undefined) {\n utterance.volume = Math.max(0, Math.min(1, options.volume));\n }\n // Set up event listeners\n utterance.onstart = () => {\n this.notifyListeners('start', { utteranceId });\n };\n utterance.onend = () => {\n this.currentUtterances.delete(utteranceId);\n this.notifyListeners('end', { utteranceId });\n };\n utterance.onboundary = (event) => {\n this.notifyListeners('boundary', {\n utteranceId,\n charIndex: event.charIndex,\n charLength: event.charLength,\n });\n };\n utterance.onerror = (event) => {\n this.currentUtterances.delete(utteranceId);\n this.notifyListeners('error', {\n utteranceId,\n error: event.error || 'Unknown error',\n });\n };\n // Handle queue strategy\n if (options.queueStrategy === 'Flush') {\n window.speechSynthesis.cancel();\n this.currentUtterances.clear();\n }\n this.currentUtterances.set(utteranceId, utterance);\n window.speechSynthesis.speak(utterance);\n return { utteranceId };\n }\n async synthesizeToFile(_options) {\n throw new Error('synthesizeToFile is not supported on web platform');\n }\n async cancel() {\n if ('speechSynthesis' in window) {\n window.speechSynthesis.cancel();\n this.currentUtterances.clear();\n }\n }\n async pause() {\n if ('speechSynthesis' in window) {\n window.speechSynthesis.pause();\n }\n }\n async resume() {\n if ('speechSynthesis' in window) {\n window.speechSynthesis.resume();\n }\n }\n async isSpeaking() {\n if ('speechSynthesis' in window) {\n return { isSpeaking: window.speechSynthesis.speaking };\n }\n return { isSpeaking: false };\n }\n async isAvailable() {\n return { isAvailable: 'speechSynthesis' in window };\n }\n async getVoices() {\n if (!('speechSynthesis' in window)) {\n return { voices: [] };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const voices = webVoices.map((voice) => ({\n id: voice.voiceURI,\n name: voice.name,\n language: voice.lang,\n isNetworkConnectionRequired: !voice.localService,\n default: voice.default,\n }));\n return { voices };\n }\n async getLanguages() {\n if (!('speechSynthesis' in window)) {\n return { languages: [] };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const languages = Array.from(new Set(webVoices.map((voice) => voice.lang)));\n return { languages };\n }\n async isLanguageAvailable(options) {\n if (!('speechSynthesis' in window)) {\n return { isAvailable: false };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const isAvailable = webVoices.some((voice) => voice.lang === options.language);\n return { isAvailable };\n }\n async isVoiceAvailable(options) {\n if (!('speechSynthesis' in window)) {\n return { isAvailable: false };\n }\n const webVoices = window.speechSynthesis.getVoices();\n const isAvailable = webVoices.some((voice) => voice.voiceURI === options.voiceId || voice.name === options.voiceId);\n return { isAvailable };\n }\n async initialize() {\n // Pre-load voices on web\n if ('speechSynthesis' in window) {\n window.speechSynthesis.getVoices();\n }\n }\n async activateAudioSession(_options) {\n // Not applicable on web\n }\n async deactivateAudioSession() {\n // Not applicable on web\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,eAAe,GAAGA,mBAAc,CAAC,iBAAiB,EAAE;IAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACtE,CAAC;;ICFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;IAClD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,kBAAkB,GAAG,CAAC;IACnC,QAAQ,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE;IAC1C,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,EAAE,iBAAiB,IAAI,MAAM,CAAC,EAAE;IAC5C,YAAY,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC;IAC7E,QAAQ;IACR,QAAQ,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACxE,QAAQ,MAAM,SAAS,GAAG,IAAI,wBAAwB,CAAC,OAAO,CAAC,IAAI,CAAC;IACpE;IACA,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE;IAC7B,YAAY,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE;IAC7D,YAAY,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO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