@capacitor-community/text-to-speech 0.2.3 → 1.1.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.
Files changed (36) hide show
  1. package/CapacitorCommunityTextToSpeech.podspec +1 -1
  2. package/LICENSE +1 -1
  3. package/README.md +169 -113
  4. package/android/build.gradle +14 -8
  5. package/android/src/main/AndroidManifest.xml +3 -5
  6. package/android/src/main/java/com/getcapacitor/community/tts/SpeakResultCallback.java +6 -0
  7. package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeech.java +98 -180
  8. package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeechPlugin.java +130 -0
  9. package/android/src/main/res/.gitkeep +0 -0
  10. package/dist/docs.json +194 -0
  11. package/dist/esm/definitions.d.ts +70 -17
  12. package/dist/esm/definitions.js +1 -0
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/dist/esm/index.d.ts +3 -1
  15. package/dist/esm/index.js +9 -1
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/web.d.ts +7 -9
  18. package/dist/esm/web.js +48 -76
  19. package/dist/esm/web.js.map +1 -1
  20. package/dist/plugin.cjs.js +57 -75
  21. package/dist/plugin.cjs.js.map +1 -1
  22. package/dist/plugin.js +59 -75
  23. package/dist/plugin.js.map +1 -1
  24. package/ios/Plugin/Info.plist +1 -1
  25. package/ios/Plugin/TextToSpeech.swift +81 -0
  26. package/ios/Plugin/{Plugin.h → TextToSpeechPlugin.h} +0 -0
  27. package/ios/Plugin/{Plugin.m → TextToSpeechPlugin.m} +2 -3
  28. package/ios/Plugin/TextToSpeechPlugin.swift +64 -0
  29. package/package.json +36 -21
  30. package/CHANGELOG.md +0 -46
  31. package/android/src/main/java/com/getcapacitor/community/tts/Constant.java +0 -8
  32. package/android/src/main/res/layout/bridge_layout_main.xml +0 -15
  33. package/android/src/main/res/values/colors.xml +0 -3
  34. package/android/src/main/res/values/strings.xml +0 -3
  35. package/android/src/main/res/values/styles.xml +0 -3
  36. package/ios/Plugin/Plugin.swift +0 -119
@@ -1,32 +1,85 @@
1
- declare module '@capacitor/core' {
2
- interface PluginRegistry {
3
- TextToSpeech: TextToSpeechPlugin;
4
- }
5
- }
6
1
  export interface TextToSpeechPlugin {
2
+ /**
3
+ * Starts the TTS engine and plays the desired text.
4
+ */
7
5
  speak(options: TTSOptions): Promise<void>;
6
+ /**
7
+ * Stops the TTS engine.
8
+ */
8
9
  stop(): Promise<void>;
10
+ /**
11
+ * Returns a list of supported BCP 47 language tags.
12
+ */
9
13
  getSupportedLanguages(): Promise<{
10
14
  languages: string[];
11
15
  }>;
16
+ /**
17
+ * Returns a list of supported voices.
18
+ */
12
19
  getSupportedVoices(): Promise<{
13
20
  voices: SpeechSynthesisVoice[];
14
21
  }>;
22
+ /**
23
+ * Checks if a specific BCP 47 language tag is supported.
24
+ */
25
+ isLanguageSupported(options: {
26
+ lang: string;
27
+ }): Promise<{
28
+ supported: boolean;
29
+ }>;
30
+ /**
31
+ * Verifies proper installation and availability of resource files on the system.
32
+ *
33
+ * Only available for Android.
34
+ */
15
35
  openInstall(): Promise<void>;
16
- setPitchRate(options: {
17
- pitchRate: number;
18
- }): Promise<void>;
19
- setSpeechRate(options: {
20
- speechRate: number;
21
- }): Promise<void>;
22
36
  }
23
37
  export interface TTSOptions {
38
+ /**
39
+ * The text that will be synthesised when the utterance is spoken.
40
+ */
24
41
  text: string;
25
- locale?: string;
26
- speechRate?: number;
27
- pitchRate?: number;
42
+ /**
43
+ * The language of the utterance.
44
+ * Possible languages can be queried using `getSupportedLanguages`.
45
+ *
46
+ * Default: `en-US`.
47
+ */
48
+ lang?: string;
49
+ /**
50
+ * The speed at which the utterance will be spoken at.
51
+ *
52
+ * Default: `1.0`.
53
+ */
54
+ rate?: number;
55
+ /**
56
+ * The pitch at which the utterance will be spoken at.
57
+ *
58
+ * Default: `1.0`.
59
+ */
60
+ pitch?: number;
61
+ /**
62
+ * The volume that the utterance will be spoken at.
63
+ *
64
+ * Default: `1.0`.
65
+ */
28
66
  volume?: number;
67
+ /**
68
+ * The index of the selected voice that will be used to speak the utterance.
69
+ * Possible voices can be queried using `getSupportedVoices`.
70
+ *
71
+ * Only available for Web.
72
+ */
29
73
  voice?: number;
74
+ /**
75
+ * Select the iOS Audio session category.
76
+ * Possible values: `ambient` and `playback`.
77
+ * Use `playback` to play audio even when the app is in the background.
78
+ *
79
+ * Only available for iOS.
80
+ *
81
+ * Default: `ambient`.
82
+ */
30
83
  category?: string;
31
84
  }
32
85
  /**
@@ -39,7 +92,7 @@ export interface SpeechSynthesisVoice {
39
92
  default: boolean;
40
93
  /**
41
94
  * BCP 47 language tag indicating the language of the voice.
42
- * Example: `en-US`
95
+ * Example: `en-US`.
43
96
  */
44
97
  lang: string;
45
98
  /**
@@ -48,12 +101,12 @@ export interface SpeechSynthesisVoice {
48
101
  localService: boolean;
49
102
  /**
50
103
  * Human-readable name that represents the voice.
51
- * Example: `Microsoft Zira Desktop - English (United States)`
104
+ * Example: `Microsoft Zira Desktop - English (United States)`.
52
105
  */
53
106
  name: string;
54
107
  /**
55
108
  * Type of URI and location of the speech synthesis service for this voice.
56
- * Example: `urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US`
109
+ * Example: `urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US`.
57
110
  */
58
111
  voiceURI: string;
59
112
  }
@@ -1 +1,2 @@
1
+ export {};
1
2
  //# sourceMappingURL=definitions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TextToSpeechPlugin {\n /**\n * Starts the TTS engine and plays the desired text.\n */\n speak(options: TTSOptions): Promise<void>;\n /**\n * Stops the TTS engine.\n */\n stop(): Promise<void>;\n /**\n * Returns a list of supported BCP 47 language tags.\n */\n getSupportedLanguages(): Promise<{ languages: string[] }>;\n /**\n * Returns a list of supported voices.\n */\n getSupportedVoices(): Promise<{ voices: SpeechSynthesisVoice[] }>;\n /**\n * Checks if a specific BCP 47 language tag is supported.\n */\n isLanguageSupported(options: {\n lang: string;\n }): Promise<{ supported: boolean }>;\n /**\n * Verifies proper installation and availability of resource files on the system.\n *\n * Only available for Android.\n */\n openInstall(): Promise<void>;\n}\n\nexport interface TTSOptions {\n /**\n * The text that will be synthesised when the utterance is spoken.\n */\n text: string;\n /**\n * The language of the utterance.\n * Possible languages can be queried using `getSupportedLanguages`.\n *\n * Default: `en-US`.\n */\n lang?: string;\n /**\n * The speed at which the utterance will be spoken at.\n *\n * Default: `1.0`.\n */\n rate?: number;\n /**\n * The pitch at which the utterance will be spoken at.\n *\n * Default: `1.0`.\n */\n pitch?: number;\n /**\n * The volume that the utterance will be spoken at.\n *\n * Default: `1.0`.\n */\n volume?: number;\n /**\n * The index of the selected voice that will be used to speak the utterance.\n * Possible voices can be queried using `getSupportedVoices`.\n *\n * Only available for Web.\n */\n voice?: number;\n /**\n * Select the iOS Audio session category.\n * Possible values: `ambient` and `playback`.\n * Use `playback` to play audio even when the app is in the background.\n *\n * Only available for iOS.\n *\n * Default: `ambient`.\n */\n category?: string; // iOS only\n}\n\n/**\n * The SpeechSynthesisVoice interface represents a voice that the system supports.\n */\nexport interface SpeechSynthesisVoice {\n /**\n * Specifies whether the voice is the default voice for the current app (`true`) or not (`false`).\n */\n default: boolean;\n /**\n * BCP 47 language tag indicating the language of the voice.\n * Example: `en-US`.\n */\n lang: string;\n /**\n * Specifies whether the voice is supplied by a local (`true`) or remote (`false`) speech synthesizer service.\n */\n localService: boolean;\n /**\n * Human-readable name that represents the voice.\n * Example: `Microsoft Zira Desktop - English (United States)`.\n */\n name: string;\n /**\n * Type of URI and location of the speech synthesis service for this voice.\n * Example: `urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US`.\n */\n voiceURI: string;\n}\n"]}
@@ -1,2 +1,4 @@
1
+ import type { TextToSpeechPlugin } from './definitions';
2
+ declare const TextToSpeech: TextToSpeechPlugin;
1
3
  export * from './definitions';
2
- export * from './web';
4
+ export { TextToSpeech };
package/dist/esm/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const TextToSpeech = registerPlugin('TextToSpeech', {
3
+ web: () => import('./web').then(m => new m.TextToSpeechWeb()),
4
+ });
5
+ // Warm up
6
+ if ('speechSynthesis' in window) {
7
+ window.speechSynthesis;
8
+ }
1
9
  export * from './definitions';
2
- export * from './web';
10
+ export { TextToSpeech };
3
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,UAAU;AACV,IAAI,iBAAiB,IAAI,MAAM,EAAE;IAC/B,MAAM,CAAC,eAAe,CAAC;CACxB;AAED,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { TextToSpeechPlugin } from './definitions';\n\nconst TextToSpeech = registerPlugin<TextToSpeechPlugin>('TextToSpeech', {\n web: () => import('./web').then(m => new m.TextToSpeechWeb()),\n});\n\n// Warm up\nif ('speechSynthesis' in window) {\n window.speechSynthesis;\n}\n\nexport * from './definitions';\nexport { TextToSpeech };\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
- import { TextToSpeechPlugin, SpeechSynthesisVoice, TTSOptions } from './definitions';
2
+ import type { TextToSpeechPlugin, TTSOptions } from './definitions';
3
3
  export declare class TextToSpeechWeb extends WebPlugin implements TextToSpeechPlugin {
4
4
  private speechSynthesis;
5
+ private supportedVoices;
5
6
  constructor();
6
7
  speak(options: TTSOptions): Promise<void>;
7
8
  stop(): Promise<void>;
@@ -11,17 +12,14 @@ export declare class TextToSpeechWeb extends WebPlugin implements TextToSpeechPl
11
12
  getSupportedVoices(): Promise<{
12
13
  voices: SpeechSynthesisVoice[];
13
14
  }>;
15
+ isLanguageSupported(options: {
16
+ lang: string;
17
+ }): Promise<{
18
+ supported: boolean;
19
+ }>;
14
20
  openInstall(): Promise<void>;
15
- setPitchRate(_options: {
16
- pitchRate: number;
17
- }): Promise<void>;
18
- setSpeechRate(_options: {
19
- speechRate: number;
20
- }): Promise<void>;
21
21
  private createSpeechSynthesisUtterance;
22
22
  private getSpeechSynthesisVoices;
23
23
  private throwUnsupportedError;
24
24
  private throwUnimplementedError;
25
25
  }
26
- declare const TextToSpeech: TextToSpeechWeb;
27
- export { TextToSpeech };
package/dist/esm/web.js CHANGED
@@ -1,98 +1,71 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { WebPlugin } from '@capacitor/core';
11
2
  export class TextToSpeechWeb extends WebPlugin {
12
3
  constructor() {
13
- super({
14
- name: 'TextToSpeech',
15
- platforms: ['web'],
16
- });
4
+ super();
17
5
  this.speechSynthesis = null;
18
6
  if ('speechSynthesis' in window) {
19
7
  this.speechSynthesis = window.speechSynthesis;
20
8
  }
21
9
  }
22
- speak(options) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if (!this.speechSynthesis) {
25
- this.throwUnsupportedError();
26
- }
27
- yield this.stop();
28
- const speechSynthesis = this.speechSynthesis;
29
- const utterance = this.createSpeechSynthesisUtterance(options);
30
- return new Promise((resolve, reject) => {
31
- utterance.onend = () => {
32
- resolve();
33
- };
34
- utterance.onerror = (event) => {
35
- reject(event);
36
- };
37
- speechSynthesis.speak(utterance);
38
- });
39
- });
40
- }
41
- stop() {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- if (!this.speechSynthesis) {
44
- this.throwUnsupportedError();
45
- }
46
- this.speechSynthesis.cancel();
10
+ async speak(options) {
11
+ if (!this.speechSynthesis) {
12
+ this.throwUnsupportedError();
13
+ }
14
+ await this.stop();
15
+ const speechSynthesis = this.speechSynthesis;
16
+ const utterance = this.createSpeechSynthesisUtterance(options);
17
+ return new Promise((resolve, reject) => {
18
+ utterance.onend = () => {
19
+ resolve();
20
+ };
21
+ utterance.onerror = (event) => {
22
+ reject(event);
23
+ };
24
+ speechSynthesis.speak(utterance);
47
25
  });
48
26
  }
49
- getSupportedLanguages() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const voices = this.getSpeechSynthesisVoices();
52
- const languages = voices.map(voice => voice.lang);
53
- const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
54
- return { languages: filteredLanguages };
55
- });
27
+ async stop() {
28
+ if (!this.speechSynthesis) {
29
+ this.throwUnsupportedError();
30
+ }
31
+ this.speechSynthesis.cancel();
56
32
  }
57
- getSupportedVoices() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- const voices = this.getSpeechSynthesisVoices();
60
- return { voices };
61
- });
33
+ async getSupportedLanguages() {
34
+ const voices = this.getSpeechSynthesisVoices();
35
+ const languages = voices.map(voice => voice.lang);
36
+ const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
37
+ return { languages: filteredLanguages };
62
38
  }
63
- openInstall() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- this.throwUnimplementedError();
66
- });
39
+ async getSupportedVoices() {
40
+ const voices = this.getSpeechSynthesisVoices();
41
+ return { voices };
67
42
  }
68
- setPitchRate(_options) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- this.throwUnimplementedError();
71
- });
43
+ async isLanguageSupported(options) {
44
+ const result = await this.getSupportedLanguages();
45
+ const isLanguageSupported = result.languages.includes(options.lang);
46
+ return { supported: isLanguageSupported };
72
47
  }
73
- setSpeechRate(_options) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- this.throwUnimplementedError();
76
- });
48
+ async openInstall() {
49
+ this.throwUnimplementedError();
77
50
  }
78
51
  createSpeechSynthesisUtterance(options) {
79
52
  const voices = this.getSpeechSynthesisVoices();
80
53
  const utterance = new SpeechSynthesisUtterance();
81
- const { text, locale, speechRate, volume, voice, pitchRate } = options;
54
+ const { text, lang, rate, pitch, volume, voice } = options;
82
55
  if (voice) {
83
56
  utterance.voice = voices[voice];
84
57
  }
85
58
  if (volume) {
86
59
  utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
87
60
  }
88
- if (speechRate) {
89
- utterance.rate = speechRate >= 0.1 && speechRate <= 10 ? speechRate : 1;
61
+ if (rate) {
62
+ utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
90
63
  }
91
- if (pitchRate) {
92
- utterance.pitch = pitchRate >= 0 && pitchRate <= 2 ? pitchRate : 2;
64
+ if (pitch) {
65
+ utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
93
66
  }
94
- if (locale) {
95
- utterance.lang = locale;
67
+ if (lang) {
68
+ utterance.lang = lang;
96
69
  }
97
70
  utterance.text = text;
98
71
  return utterance;
@@ -101,17 +74,16 @@ export class TextToSpeechWeb extends WebPlugin {
101
74
  if (!this.speechSynthesis) {
102
75
  this.throwUnsupportedError();
103
76
  }
104
- return this.speechSynthesis.getVoices();
77
+ if (!this.supportedVoices || this.supportedVoices.length < 1) {
78
+ this.supportedVoices = this.speechSynthesis.getVoices();
79
+ }
80
+ return this.supportedVoices;
105
81
  }
106
82
  throwUnsupportedError() {
107
- throw new Error('Not supported on this device.');
83
+ throw this.unavailable('SpeechSynthesis API not available in this browser.');
108
84
  }
109
85
  throwUnimplementedError() {
110
- throw new Error('Not implemented on web.');
86
+ throw this.unimplemented('Not implemented on web.');
111
87
  }
112
88
  }
113
- const TextToSpeech = new TextToSpeechWeb();
114
- export { TextToSpeech };
115
- import { registerWebPlugin } from '@capacitor/core';
116
- registerWebPlugin(TextToSpeech);
117
89
  //# 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;AAO5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAG5C;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,SAAS,EAAE,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC;QANG,oBAAe,GAA2B,IAAI,CAAC;QAOrD,IAAI,iBAAiB,IAAI,MAAM,EAAE;YAC/B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;SAC/C;IACH,CAAC;IAEY,KAAK,CAAC,OAAmB;;YACpC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;gBACzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;aAC9B;YACD,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;YAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC;YAC/D,OAAO,IAAI,O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;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 }\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,100 +4,77 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@capacitor/core');
6
6
 
7
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
7
+ const TextToSpeech = core.registerPlugin('TextToSpeech', {
8
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()),
9
+ });
10
+
16
11
  class TextToSpeechWeb extends core.WebPlugin {
17
12
  constructor() {
18
- super({
19
- name: 'TextToSpeech',
20
- platforms: ['web'],
21
- });
13
+ super();
22
14
  this.speechSynthesis = null;
23
15
  if ('speechSynthesis' in window) {
24
16
  this.speechSynthesis = window.speechSynthesis;
25
17
  }
26
18
  }
27
- speak(options) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- if (!this.speechSynthesis) {
30
- this.throwUnsupportedError();
31
- }
32
- yield this.stop();
33
- const speechSynthesis = this.speechSynthesis;
34
- const utterance = this.createSpeechSynthesisUtterance(options);
35
- return new Promise((resolve, reject) => {
36
- utterance.onend = () => {
37
- resolve();
38
- };
39
- utterance.onerror = (event) => {
40
- reject(event);
41
- };
42
- speechSynthesis.speak(utterance);
43
- });
44
- });
45
- }
46
- stop() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- if (!this.speechSynthesis) {
49
- this.throwUnsupportedError();
50
- }
51
- this.speechSynthesis.cancel();
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);
52
34
  });
53
35
  }
54
- getSupportedLanguages() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const voices = this.getSpeechSynthesisVoices();
57
- const languages = voices.map(voice => voice.lang);
58
- const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);
59
- return { languages: filteredLanguages };
60
- });
36
+ async stop() {
37
+ if (!this.speechSynthesis) {
38
+ this.throwUnsupportedError();
39
+ }
40
+ this.speechSynthesis.cancel();
61
41
  }
62
- getSupportedVoices() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const voices = this.getSpeechSynthesisVoices();
65
- return { voices };
66
- });
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 };
67
47
  }
68
- openInstall() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- this.throwUnimplementedError();
71
- });
48
+ async getSupportedVoices() {
49
+ const voices = this.getSpeechSynthesisVoices();
50
+ return { voices };
72
51
  }
73
- setPitchRate(_options) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- this.throwUnimplementedError();
76
- });
52
+ async isLanguageSupported(options) {
53
+ const result = await this.getSupportedLanguages();
54
+ const isLanguageSupported = result.languages.includes(options.lang);
55
+ return { supported: isLanguageSupported };
77
56
  }
78
- setSpeechRate(_options) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- this.throwUnimplementedError();
81
- });
57
+ async openInstall() {
58
+ this.throwUnimplementedError();
82
59
  }
83
60
  createSpeechSynthesisUtterance(options) {
84
61
  const voices = this.getSpeechSynthesisVoices();
85
62
  const utterance = new SpeechSynthesisUtterance();
86
- const { text, locale, speechRate, volume, voice, pitchRate } = options;
63
+ const { text, lang, rate, pitch, volume, voice } = options;
87
64
  if (voice) {
88
65
  utterance.voice = voices[voice];
89
66
  }
90
67
  if (volume) {
91
68
  utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
92
69
  }
93
- if (speechRate) {
94
- utterance.rate = speechRate >= 0.1 && speechRate <= 10 ? speechRate : 1;
70
+ if (rate) {
71
+ utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
95
72
  }
96
- if (pitchRate) {
97
- utterance.pitch = pitchRate >= 0 && pitchRate <= 2 ? pitchRate : 2;
73
+ if (pitch) {
74
+ utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
98
75
  }
99
- if (locale) {
100
- utterance.lang = locale;
76
+ if (lang) {
77
+ utterance.lang = lang;
101
78
  }
102
79
  utterance.text = text;
103
80
  return utterance;
@@ -106,18 +83,23 @@ class TextToSpeechWeb extends core.WebPlugin {
106
83
  if (!this.speechSynthesis) {
107
84
  this.throwUnsupportedError();
108
85
  }
109
- return this.speechSynthesis.getVoices();
86
+ if (!this.supportedVoices || this.supportedVoices.length < 1) {
87
+ this.supportedVoices = this.speechSynthesis.getVoices();
88
+ }
89
+ return this.supportedVoices;
110
90
  }
111
91
  throwUnsupportedError() {
112
- throw new Error('Not supported on this device.');
92
+ throw this.unavailable('SpeechSynthesis API not available in this browser.');
113
93
  }
114
94
  throwUnimplementedError() {
115
- throw new Error('Not implemented on web.');
95
+ throw this.unimplemented('Not implemented on web.');
116
96
  }
117
97
  }
118
- const TextToSpeech = new TextToSpeechWeb();
119
- core.registerWebPlugin(TextToSpeech);
98
+
99
+ var web = /*#__PURE__*/Object.freeze({
100
+ __proto__: null,
101
+ TextToSpeechWeb: TextToSpeechWeb
102
+ });
120
103
 
121
104
  exports.TextToSpeech = TextToSpeech;
122
- exports.TextToSpeechWeb = TextToSpeechWeb;
123
105
  //# sourceMappingURL=plugin.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/web.js"],"sourcesContent":["var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { WebPlugin } from '@capacitor/core';\nexport class TextToSpeechWeb extends WebPlugin {\n constructor() {\n super({\n name: 'TextToSpeech',\n platforms: ['web'],\n });\n this.speechSynthesis = null;\n if ('speechSynthesis' in window) {\n this.speechSynthesis = window.speechSynthesis;\n }\n }\n speak(options) {\n return __awaiter(this, void 0, void 0, function* () {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n yield 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 }\n stop() {\n return __awaiter(this, void 0, void 0, function* () {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n this.speechSynthesis.cancel();\n });\n }\n getSupportedLanguages() {\n return __awaiter(this, void 0, void 0, function* () {\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 getSupportedVoices() {\n return __awaiter(this, void 0, void 0, function* () {\n const voices = this.getSpeechSynthesisVoices();\n return { voices };\n });\n }\n openInstall() {\n return __awaiter(this, void 0, void 0, function* () {\n this.throwUnimplementedError();\n });\n }\n setPitchRate(_options) {\n return __awaiter(this, void 0, void 0, function* () {\n this.throwUnimplementedError();\n });\n }\n setSpeechRate(_options) {\n return __awaiter(this, void 0, void 0, function* () {\n this.throwUnimplementedError();\n });\n }\n createSpeechSynthesisUtterance(options) {\n const voices = this.getSpeechSynthesisVoices();\n const utterance = new SpeechSynthesisUtterance();\n const { text, locale, speechRate, volume, voice, pitchRate } = 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 (speechRate) {\n utterance.rate = speechRate >= 0.1 && speechRate <= 10 ? speechRate : 1;\n }\n if (pitchRate) {\n utterance.pitch = pitchRate >= 0 && pitchRate <= 2 ? pitchRate : 2;\n }\n if (locale) {\n utterance.lang = locale;\n }\n utterance.text = text;\n return utterance;\n }\n getSpeechSynthesisVoices() {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n return this.speechSynthesis.getVoices();\n }\n throwUnsupportedError() {\n throw new Error('Not supported on this device.');\n }\n throwUnimplementedError() {\n throw new Error('Not implemented on web.');\n }\n}\nconst TextToSpeech = new TextToSpeechWeb();\nexport { TextToSpeech };\nimport { registerWebPlugin } from '@capacitor/core';\nregisterWebPlugin(TextToSpeech);\n//# sourceMappingURL=web.js.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AAS;AACT,QAAQ,IAAI,MAAM,EAAE;AACpB,YAAY,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC;AACpC,SAAS;AACT,QAAQ,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;AAC9B,QAAQ,OAAO,SAAS,CAAC;AACzB,KAAK;AACL,IAAI,wBAAwB,GAAG;AAC/B,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;AACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;AACzC,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;AAChD,KAAK;AACL,IAAI,qBAAqB,GAAG;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;AACzD,KAAK;AACL,IAAI,uBAAuB,GAAG;AAC9B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL,CAAC;AACI,MAAC,YAAY,GAAG,IAAI,eAAe,GAAG;AAG3CC,sBAAiB,CAAC,YAAY,CAAC;;;;;"}
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 }\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,CA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