@capacitor-community/text-to-speech 4.0.0 → 4.0.1-dev.1d4e158.1717578191

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/README.md CHANGED
@@ -89,6 +89,7 @@ const isLanguageSupported = async (lang: string) => {
89
89
 
90
90
  <docgen-index>
91
91
 
92
+ * [`initialize(...)`](#initialize)
92
93
  * [`speak(...)`](#speak)
93
94
  * [`stop()`](#stop)
94
95
  * [`getSupportedLanguages()`](#getsupportedlanguages)
@@ -102,6 +103,25 @@ const isLanguageSupported = async (lang: string) => {
102
103
  <docgen-api>
103
104
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
104
105
 
106
+ ### initialize(...)
107
+
108
+ ```typescript
109
+ initialize(options: InitializeOptions) => Promise<void>
110
+ ```
111
+
112
+ Initializes the TTS engine.
113
+
114
+ This method should be called before any other methods.
115
+
116
+ | Param | Type |
117
+ | ------------- | --------------------------------------------------------------- |
118
+ | **`options`** | <code><a href="#initializeoptions">InitializeOptions</a></code> |
119
+
120
+ **Since:** 4.1.0
121
+
122
+ --------------------
123
+
124
+
105
125
  ### speak(...)
106
126
 
107
127
  ```typescript
@@ -187,6 +207,13 @@ Only available for Android.
187
207
  ### Interfaces
188
208
 
189
209
 
210
+ #### InitializeOptions
211
+
212
+ | Prop | Type | Description | Since |
213
+ | ------------ | ------------------- | ------------------------------------------------------ | ----- |
214
+ | **`engine`** | <code>string</code> | The engine to use for TTS. Only available for Android. | 4.1.0 |
215
+
216
+
190
217
  #### TTSOptions
191
218
 
192
219
  | Prop | Type | Description | Default |
@@ -0,0 +1,6 @@
1
+ package com.getcapacitor.community.tts;
2
+
3
+ public interface Callback {
4
+ void error(Exception exception);
5
+ void success();
6
+ }
@@ -1,5 +1,8 @@
1
1
  package com.getcapacitor.community.tts;
2
2
 
3
+ import static com.getcapacitor.community.tts.TextToSpeechPlugin.ERROR_INITIALIZATION_FAILED;
4
+ import static com.getcapacitor.community.tts.TextToSpeechPlugin.ERROR_UTTERANCE;
5
+
3
6
  import android.content.Context;
4
7
  import android.content.Intent;
5
8
  import android.content.pm.PackageManager;
@@ -9,6 +12,9 @@ import android.os.Bundle;
9
12
  import android.speech.tts.UtteranceProgressListener;
10
13
  import android.speech.tts.Voice;
11
14
  import android.util.Log;
15
+
16
+ import androidx.annotation.Nullable;
17
+
12
18
  import com.getcapacitor.JSArray;
13
19
  import com.getcapacitor.JSObject;
14
20
  import java.util.ArrayList;
@@ -27,10 +33,12 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
27
33
  private int initializationStatus;
28
34
  private JSObject[] supportedVoices = null;
29
35
 
36
+ private Callback initializeCallback;
37
+
30
38
  TextToSpeech(Context context) {
31
39
  this.context = context;
32
40
  try {
33
- tts = new android.speech.tts.TextToSpeech(context, this);
41
+ createTextToSpeechInstance(null);
34
42
  } catch (Exception ex) {
35
43
  Log.d(LOG_TAG, ex.getLocalizedMessage());
36
44
  }
@@ -39,6 +47,21 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
39
47
  @Override
40
48
  public void onInit(int status) {
41
49
  this.initializationStatus = status;
50
+ if (initializeCallback != null) {
51
+ if (status == android.speech.tts.TextToSpeech.SUCCESS) {
52
+ initializeCallback.success();
53
+ } else {
54
+ Exception exception = new Exception(ERROR_INITIALIZATION_FAILED);
55
+ initializeCallback.error(exception);
56
+ }
57
+ initializeCallback = null;
58
+ }
59
+ }
60
+
61
+ public void initialize(@Nullable String engine, Callback callback) {
62
+ initializeCallback = callback;
63
+ destroyTextToSpeechInstance();
64
+ createTextToSpeechInstance(engine);
42
65
  }
43
66
 
44
67
  public void speak(
@@ -49,7 +72,7 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
49
72
  float volume,
50
73
  int voice,
51
74
  String callbackId,
52
- SpeakResultCallback resultCallback
75
+ Callback callback
53
76
  ) {
54
77
  tts.stop();
55
78
  tts.setOnUtteranceProgressListener(
@@ -59,12 +82,13 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
59
82
 
60
83
  @Override
61
84
  public void onDone(String utteranceId) {
62
- resultCallback.onDone();
85
+ callback.success();
63
86
  }
64
87
 
65
88
  @Override
66
89
  public void onError(String utteranceId) {
67
- resultCallback.onError();
90
+ Exception exception = new Exception(ERROR_UTTERANCE);
91
+ callback.error(exception);
68
92
  }
69
93
  }
70
94
  );
@@ -123,14 +147,7 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
123
147
  orderedVoices.add(supportedVoice);
124
148
  }
125
149
 
126
- Collections.sort(
127
- orderedVoices,
128
- new Comparator<Voice>() {
129
- public int compare(Voice v1, Voice v2) {
130
- return v1.hashCode() - v2.hashCode();
131
- }
132
- }
133
- );
150
+ Collections.sort(orderedVoices, Comparator.comparing(Voice::hashCode));
134
151
 
135
152
  return orderedVoices;
136
153
  }
@@ -173,11 +190,15 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
173
190
  }
174
191
 
175
192
  public void onDestroy() {
176
- if (tts == null) {
177
- return;
193
+ destroyTextToSpeechInstance();
194
+ }
195
+
196
+ private void createTextToSpeechInstance(@Nullable String engine) {
197
+ if (engine == null) {
198
+ this.tts = new android.speech.tts.TextToSpeech(context, this);
199
+ } else {
200
+ this.tts = new android.speech.tts.TextToSpeech(context, this, engine);
178
201
  }
179
- tts.stop();
180
- tts.shutdown();
181
202
  }
182
203
 
183
204
  private JSObject convertVoiceToJSObject(Voice voice) {
@@ -190,4 +211,13 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
190
211
  obj.put("default", false);
191
212
  return obj;
192
213
  }
214
+
215
+ private void destroyTextToSpeechInstance() {
216
+ if (tts == null) {
217
+ return;
218
+ }
219
+ tts.stop();
220
+ tts.shutdown();
221
+ tts = null;
222
+ }
193
223
  }
@@ -14,6 +14,7 @@ public class TextToSpeechPlugin extends Plugin {
14
14
 
15
15
  public static final String ERROR_UTTERANCE = "Failed to read text.";
16
16
  public static final String ERROR_UNSUPPORTED_LANGUAGE = "This language is not supported.";
17
+ public static final String ERROR_INITIALIZATION_FAILED = "Failed to initialize TextToSpeech.";
17
18
 
18
19
  private TextToSpeech implementation;
19
20
 
@@ -22,6 +23,29 @@ public class TextToSpeechPlugin extends Plugin {
22
23
  implementation = new TextToSpeech(getContext());
23
24
  }
24
25
 
26
+ @PluginMethod
27
+ public void initialize(PluginCall call) {
28
+ try {
29
+ String engine = call.getString("engine");
30
+
31
+ Callback callback = new Callback() {
32
+ @Override
33
+ public void error(Exception exception) {
34
+ call.reject(exception.getLocalizedMessage());
35
+ }
36
+
37
+ @Override
38
+ public void success() {
39
+ call.resolve();
40
+ }
41
+ };
42
+
43
+ implementation.initialize(engine, callback);
44
+ } catch (Exception ex) {
45
+ call.reject(ex.getLocalizedMessage());
46
+ }
47
+ }
48
+
25
49
  @PluginMethod
26
50
  public void speak(PluginCall call) {
27
51
  boolean isAvailable = implementation.isAvailable();
@@ -43,20 +67,20 @@ public class TextToSpeechPlugin extends Plugin {
43
67
  return;
44
68
  }
45
69
 
46
- SpeakResultCallback resultCallback = new SpeakResultCallback() {
70
+ Callback callback = new Callback() {
47
71
  @Override
48
- public void onDone() {
49
- call.resolve();
72
+ public void error(Exception exception) {
73
+ call.reject(exception.getLocalizedMessage());
50
74
  }
51
75
 
52
76
  @Override
53
- public void onError() {
54
- call.reject(ERROR_UTTERANCE);
77
+ public void success() {
78
+ call.resolve();
55
79
  }
56
80
  };
57
81
 
58
82
  try {
59
- implementation.speak(text, lang, rate, pitch, volume, voice, call.getCallbackId(), resultCallback);
83
+ implementation.speak(text, lang, rate, pitch, volume, voice, call.getCallbackId(), callback);
60
84
  } catch (Exception ex) {
61
85
  call.reject(ex.getLocalizedMessage());
62
86
  }
package/dist/docs.json CHANGED
@@ -5,6 +5,29 @@
5
5
  "docs": "",
6
6
  "tags": [],
7
7
  "methods": [
8
+ {
9
+ "name": "initialize",
10
+ "signature": "(options: InitializeOptions) => Promise<void>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "InitializeOptions"
16
+ }
17
+ ],
18
+ "returns": "Promise<void>",
19
+ "tags": [
20
+ {
21
+ "name": "since",
22
+ "text": "4.1.0"
23
+ }
24
+ ],
25
+ "docs": "Initializes the TTS engine.\n\nThis method should be called before any other methods.",
26
+ "complexTypes": [
27
+ "InitializeOptions"
28
+ ],
29
+ "slug": "initialize"
30
+ },
8
31
  {
9
32
  "name": "speak",
10
33
  "signature": "(options: TTSOptions) => Promise<void>",
@@ -85,6 +108,36 @@
85
108
  "properties": []
86
109
  },
87
110
  "interfaces": [
111
+ {
112
+ "name": "InitializeOptions",
113
+ "slug": "initializeoptions",
114
+ "docs": "",
115
+ "tags": [
116
+ {
117
+ "text": "4.1.0",
118
+ "name": "since"
119
+ }
120
+ ],
121
+ "methods": [],
122
+ "properties": [
123
+ {
124
+ "name": "engine",
125
+ "tags": [
126
+ {
127
+ "text": "\"com.google.android.tts\"",
128
+ "name": "example"
129
+ },
130
+ {
131
+ "text": "4.1.0",
132
+ "name": "since"
133
+ }
134
+ ],
135
+ "docs": "The engine to use for TTS.\n\nOnly available for Android.",
136
+ "complexTypes": [],
137
+ "type": "string | undefined"
138
+ }
139
+ ]
140
+ },
88
141
  {
89
142
  "name": "TTSOptions",
90
143
  "slug": "ttsoptions",
@@ -1,4 +1,12 @@
1
1
  export interface TextToSpeechPlugin {
2
+ /**
3
+ * Initializes the TTS engine.
4
+ *
5
+ * This method should be called before any other methods.
6
+ *
7
+ * @since 4.1.0
8
+ */
9
+ initialize(options: InitializeOptions): Promise<void>;
2
10
  /**
3
11
  * Starts the TTS engine and plays the desired text.
4
12
  */
@@ -34,6 +42,20 @@ export interface TextToSpeechPlugin {
34
42
  */
35
43
  openInstall(): Promise<void>;
36
44
  }
45
+ /**
46
+ * @since 4.1.0
47
+ */
48
+ export interface InitializeOptions {
49
+ /**
50
+ * The engine to use for TTS.
51
+ *
52
+ * Only available for Android.
53
+ *
54
+ * @example "com.google.android.tts"
55
+ * @since 4.1.0
56
+ */
57
+ engine?: string;
58
+ }
37
59
  export interface TTSOptions {
38
60
  /**
39
61
  * The text that will be synthesised when the utterance is spoken.
@@ -1 +1 @@
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 * @example \"Hello world\"\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 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;\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 * @example false\n */\n default: boolean;\n /**\n * BCP 47 language tag indicating the language of the voice.\n *\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 * @example true\n */\n localService: boolean;\n /**\n * Human-readable name that represents the voice.\n *\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 *\n * @example \"urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US\"\n */\n voiceURI: string;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TextToSpeechPlugin {\n /**\n * Initializes the TTS engine.\n *\n * This method should be called before any other methods.\n *\n * @since 4.1.0\n */\n initialize(options: InitializeOptions): Promise<void>;\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\n/**\n * @since 4.1.0\n */\nexport interface InitializeOptions {\n /**\n * The engine to use for TTS.\n *\n * Only available for Android.\n *\n * @example \"com.google.android.tts\"\n * @since 4.1.0\n */\n engine?: string;\n}\n\nexport interface TTSOptions {\n /**\n * The text that will be synthesised when the utterance is spoken.\n *\n * @example \"Hello world\"\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 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;\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 * @example false\n */\n default: boolean;\n /**\n * BCP 47 language tag indicating the language of the voice.\n *\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 * @example true\n */\n localService: boolean;\n /**\n * Human-readable name that represents the voice.\n *\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 *\n * @example \"urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US\"\n */\n voiceURI: string;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class TextToSpeechWeb extends WebPlugin implements TextToSpeechPl
4
4
  private speechSynthesis;
5
5
  private supportedVoices;
6
6
  constructor();
7
+ initialize(): Promise<void>;
7
8
  speak(options: TTSOptions): Promise<void>;
8
9
  stop(): Promise<void>;
9
10
  getSupportedLanguages(): Promise<{
package/dist/esm/web.js CHANGED
@@ -10,6 +10,9 @@ export class TextToSpeechWeb extends WebPlugin {
10
10
  });
11
11
  }
12
12
  }
13
+ async initialize() {
14
+ return;
15
+ }
13
16
  async speak(options) {
14
17
  if (!this.speechSynthesis) {
15
18
  this.throwUnsupportedError();
@@ -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,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;YACrC,SAAS,CAAC,KAAK,GAAG,GAAG,EAAE;gBACrB,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC;YACF,SAAS,CAAC,OAAO,GAAG,CAAC,KAAU,EAAE,EAAE;gBACjC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC;YACF,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,IAAI,CAAC,qBAAqB,EAA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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"]}
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,UAAU;QACrB,OAAO;IACT,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,CAA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AAe,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';\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 initialize(): Promise<void> {\n return;\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"]}
@@ -19,6 +19,9 @@ class TextToSpeechWeb extends core.WebPlugin {
19
19
  });
20
20
  }
21
21
  }
22
+ async initialize() {
23
+ return;
24
+ }
22
25
  async speak(options) {
23
26
  if (!this.speechSynthesis) {
24
27
  this.throwUnsupportedError();
@@ -1 +1 @@
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,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,SA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AI,wBAAwB,GAAG;AAC/B,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;AACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;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 initialize() {\n return;\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,CAA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AK;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;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -16,6 +16,9 @@ var capacitorTextToSpeech = (function (exports, core) {
16
16
  });
17
17
  }
18
18
  }
19
+ async initialize() {
20
+ return;
21
+ }
19
22
  async speak(options) {
20
23
  if (!this.speechSynthesis) {
21
24
  this.throwUnsupportedError();
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.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,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE,CAAC;IAChB,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IACpC,QAAQ,IAAI,iBAAiB,IAAI,MAAM,EAAE;IAC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"plugin.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 initialize() {\n return;\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,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE,CAAC;IAChB,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IACpC,QAAQ,IAAI,iBAAiB,IAAI,MAAM,EAAE;IACzC,YAAY,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IAC1D,YAAY,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAC1D,gBAAgB,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,aAAa,CAAC,CAAC;IACf,SAAS;IACT,KAAK;IACL,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,OAAO;IACf,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;IACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACzC,SAAS;IACT,Q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IAAI,KAAK,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;IACnE,SAAS;IACT,QAAQ,IAAI,IAAI,EAAE;IAClB,YAAY,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;IAClC,SAAS;IACT,QAAQ,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;IAC9B,QAAQ,OAAO,SAAS,CAAC;IACzB,KAAK;IACL,IAAI,wBAAwB,GAAG;IAC/B,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;IACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACzC,SAAS;IACT,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;IACtE,YAAY,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;IACpE,SAAS;IACT,QAAQ,OAAO,IAAI,CAAC,eAAe,CAAC;IACpC,KAAK;IACL,IAAI,qBAAqB,GAAG;IAC5B,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,oDAAoD,CAAC,CAAC;IACrF,KAAK;IACL,IAAI,uBAAuB,GAAG;IAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -4,6 +4,7 @@
4
4
  // Define the plugin using the CAP_PLUGIN Macro, and
5
5
  // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
6
  CAP_PLUGIN(TextToSpeechPlugin, "TextToSpeech",
7
+ CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise);
7
8
  CAP_PLUGIN_METHOD(speak, CAPPluginReturnPromise);
8
9
  CAP_PLUGIN_METHOD(stop, CAPPluginReturnPromise);
9
10
  CAP_PLUGIN_METHOD(openInstall, CAPPluginReturnPromise);
@@ -12,6 +12,10 @@ public class TextToSpeechPlugin: CAPPlugin {
12
12
 
13
13
  private let implementation = TextToSpeech()
14
14
 
15
+ @objc public func initialize(_ call: CAPPluginCall) {
16
+ call.resolve()
17
+ }
18
+
15
19
  @objc public func speak(_ call: CAPPluginCall) {
16
20
  let text = call.getString("text") ?? ""
17
21
  let lang = call.getString("lang") ?? "en-US"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/text-to-speech",
3
- "version": "4.0.0",
3
+ "version": "4.0.1-dev.1d4e158.1717578191",
4
4
  "description": "Capacitor plugin for synthesizing speech from text.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,6 +0,0 @@
1
- package com.getcapacitor.community.tts;
2
-
3
- public interface SpeakResultCallback {
4
- void onDone();
5
- void onError();
6
- }