@capacitor-community/text-to-speech 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -81,6 +81,7 @@ const isLanguageSupported = async (lang: string) => {
81
81
  * [`getSupportedVoices()`](#getsupportedvoices)
82
82
  * [`isLanguageSupported(...)`](#islanguagesupported)
83
83
  * [`openInstall()`](#openinstall)
84
+ * [`addListener('onRangeStart', ...)`](#addlisteneronrangestart)
84
85
  * [Interfaces](#interfaces)
85
86
 
86
87
  </docgen-index>
@@ -170,6 +171,22 @@ Only available for Android.
170
171
  --------------------
171
172
 
172
173
 
174
+ ### addListener('onRangeStart', ...)
175
+
176
+ ```typescript
177
+ addListener(eventName: 'onRangeStart', listenerFunc: (info: { start: number; end: number; spokenWord: string; }) => void) => Promise<PluginListenerHandle>
178
+ ```
179
+
180
+ | Param | Type |
181
+ | ------------------ | ----------------------------------------------------------------------------------- |
182
+ | **`eventName`** | <code>'onRangeStart'</code> |
183
+ | **`listenerFunc`** | <code>(info: { start: number; end: number; spokenWord: string; }) =&gt; void</code> |
184
+
185
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
186
+
187
+ --------------------
188
+
189
+
173
190
  ### Interfaces
174
191
 
175
192
 
@@ -198,6 +215,13 @@ The <a href="#speechsynthesisvoice">SpeechSynthesisVoice</a> interface represent
198
215
  | **`name`** | <code>string</code> | Human-readable name that represents the voice. |
199
216
  | **`voiceURI`** | <code>string</code> | Type of URI and location of the speech synthesis service for this voice. |
200
217
 
218
+
219
+ #### PluginListenerHandle
220
+
221
+ | Prop | Type |
222
+ | ------------ | ----------------------------------------- |
223
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
224
+
201
225
  </docgen-api>
202
226
 
203
227
  ## Changelog
@@ -3,4 +3,5 @@ package com.getcapacitor.community.tts;
3
3
  public interface SpeakResultCallback {
4
4
  void onDone();
5
5
  void onError();
6
+ void onRangeStart(int start, int end, String spokenWord);
6
7
  }
@@ -65,6 +65,12 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
65
65
  public void onError(String utteranceId) {
66
66
  resultCallback.onError();
67
67
  }
68
+
69
+ @Override
70
+ public void onRangeStart(String utteranceId, int start, int end, int frame) {
71
+ String spokenWord = text.substring(start, end);
72
+ resultCallback.onRangeStart(start, end, spokenWord);
73
+ }
68
74
  }
69
75
  );
70
76
 
@@ -1,5 +1,6 @@
1
1
  package com.getcapacitor.community.tts;
2
2
 
3
+ import android.util.Base64;
3
4
  import com.getcapacitor.JSArray;
4
5
  import com.getcapacitor.JSObject;
5
6
  import com.getcapacitor.Plugin;
@@ -53,6 +54,15 @@ public class TextToSpeechPlugin extends Plugin {
53
54
  public void onError() {
54
55
  call.reject(ERROR_UTTERANCE);
55
56
  }
57
+
58
+ @Override
59
+ public void onRangeStart(int start, int end, String spokenWord) {
60
+ JSObject ret = new JSObject();
61
+ ret.put("start", start);
62
+ ret.put("end", end);
63
+ ret.put("spokenWord", spokenWord);
64
+ notifyListeners("onRangeStart", ret);
65
+ }
56
66
  };
57
67
 
58
68
  try {
package/dist/docs.json CHANGED
@@ -80,6 +80,29 @@
80
80
  "docs": "Verifies proper installation and availability of resource files on the system.\n\nOnly available for Android.",
81
81
  "complexTypes": [],
82
82
  "slug": "openinstall"
83
+ },
84
+ {
85
+ "name": "addListener",
86
+ "signature": "(eventName: 'onRangeStart', listenerFunc: (info: { start: number; end: number; spokenWord: string; }) => void) => Promise<PluginListenerHandle>",
87
+ "parameters": [
88
+ {
89
+ "name": "eventName",
90
+ "docs": "",
91
+ "type": "'onRangeStart'"
92
+ },
93
+ {
94
+ "name": "listenerFunc",
95
+ "docs": "",
96
+ "type": "(info: { start: number; end: number; spokenWord: string; }) => void"
97
+ }
98
+ ],
99
+ "returns": "Promise<PluginListenerHandle>",
100
+ "tags": [],
101
+ "docs": "",
102
+ "complexTypes": [
103
+ "PluginListenerHandle"
104
+ ],
105
+ "slug": "addlisteneronrangestart"
83
106
  }
84
107
  ],
85
108
  "properties": []
@@ -241,6 +264,22 @@
241
264
  "type": "string"
242
265
  }
243
266
  ]
267
+ },
268
+ {
269
+ "name": "PluginListenerHandle",
270
+ "slug": "pluginlistenerhandle",
271
+ "docs": "",
272
+ "tags": [],
273
+ "methods": [],
274
+ "properties": [
275
+ {
276
+ "name": "remove",
277
+ "tags": [],
278
+ "docs": "",
279
+ "complexTypes": [],
280
+ "type": "() => Promise<void>"
281
+ }
282
+ ]
244
283
  }
245
284
  ],
246
285
  "enums": [],
@@ -1,3 +1,4 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
1
2
  export interface TextToSpeechPlugin {
2
3
  /**
3
4
  * Starts the TTS engine and plays the desired text.
@@ -33,6 +34,11 @@ export interface TextToSpeechPlugin {
33
34
  * Only available for Android.
34
35
  */
35
36
  openInstall(): Promise<void>;
37
+ addListener(eventName: 'onRangeStart', listenerFunc: (info: {
38
+ start: number;
39
+ end: number;
40
+ spokenWord: string;
41
+ }) => void): Promise<PluginListenerHandle>;
36
42
  }
37
43
  export interface TTSOptions {
38
44
  /**
@@ -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":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport 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 addListener(\n eventName: 'onRangeStart',\n listenerFunc: (info: {\n start: number;\n end: number;\n spokenWord: string;\n }) => void,\n ): Promise<PluginListenerHandle>;\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/text-to-speech",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "Capacitor plugin for synthesizing speech from text.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,10 +31,10 @@
31
31
  "@capacitor/core": "6.0.0",
32
32
  "@capacitor/docgen": "0.2.0",
33
33
  "@capacitor/ios": "6.0.0",
34
- "@ionic/eslint-config": "0.3.0",
34
+ "@ionic/eslint-config": "^0.4.0",
35
35
  "@ionic/prettier-config": "1.0.1",
36
36
  "@ionic/swiftlint-config": "1.1.2",
37
- "eslint": "7.32.0",
37
+ "eslint": "^8.57.0",
38
38
  "prettier": "2.3.2",
39
39
  "prettier-plugin-java": "1.0.2",
40
40
  "rimraf": "3.0.2",